Add task name as part of container name

This commit is contained in:
lisongmin 2021-01-24 10:06:58 +08:00
parent a7874cce6f
commit 6650170982
No known key found for this signature in database
GPG Key ID: 989E105F73407D49
2 changed files with 3 additions and 6 deletions

View File

@ -35,7 +35,6 @@ import (
"github.com/hashicorp/nomad/plugins/drivers" "github.com/hashicorp/nomad/plugins/drivers"
"github.com/hashicorp/nomad/plugins/shared/hclspec" "github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/plugins/shared/structs" "github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/moby/moby/pkg/namesgenerator"
) )
const ( const (
@ -368,15 +367,14 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
handle := drivers.NewTaskHandle(taskHandleVersion) handle := drivers.NewTaskHandle(taskHandleVersion)
handle.Config = cfg handle.Config = cfg
// Generate a random container name using docker namesgenerator package. // https://www.nomadproject.io/docs/drivers/docker#container-name
// https://github.com/moby/moby/blob/master/pkg/namesgenerator/names-generator.go containerName := cfg.Name + "-" + cfg.AllocID
containerName := cfg.AllocID[:8] + "_" + namesgenerator.GetRandomName(1)
containerConfig.ContainerName = containerName containerConfig.ContainerName = containerName
var err error var err error
containerConfig.Image, err = d.pullImage(driverConfig.Image) containerConfig.Image, err = d.pullImage(driverConfig.Image)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Error in pulling image: %v", err) return nil, nil, fmt.Errorf("Error in pulling image %s: %v", driverConfig.Image, err)
} }
d.logger.Info(fmt.Sprintf("Successfully pulled %s image\n", containerConfig.Image.Name())) d.logger.Info(fmt.Sprintf("Successfully pulled %s image\n", containerConfig.Image.Name()))

1
go.mod
View File

@ -39,7 +39,6 @@ require (
github.com/hashicorp/nomad v0.10.1 github.com/hashicorp/nomad v0.10.1
github.com/hashicorp/nomad/api v0.0.0-20191203164002-b31573ae7206 // indirect github.com/hashicorp/nomad/api v0.0.0-20191203164002-b31573ae7206 // indirect
github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b // indirect
github.com/moby/moby v1.13.1
github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect github.com/mrunalp/fileutils v0.0.0-20171103030105-7d4729fb3618 // indirect
github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 // indirect github.com/opencontainers/runc v1.0.0-rc8.0.20190611121236-6cc515888830 // indirect
github.com/opencontainers/runtime-spec v1.0.2 github.com/opencontainers/runtime-spec v1.0.2