Skip to content

Commit

Permalink
Merge pull request #1228 from HusterWan/zr/update-env-fix
Browse files Browse the repository at this point in the history
bugfix: update label compatibility with alidocker
  • Loading branch information
allencloud authored Apr 26, 2018
2 parents ecbe47d + 4627409 commit 00f4f6e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
6 changes: 3 additions & 3 deletions apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2110,10 +2110,10 @@ definitions:
type: "array"
items:
type: "string"
Labels:
Label:
description: "List of labels set to container."
type: "object"
additionalProperties:
type: "array"
items:
type: "string"

ContainerUpgradeConfig:
Expand Down
23 changes: 18 additions & 5 deletions apis/types/update_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func (uc *UpdateCommand) updateRun(args []string) error {
container := args[0]
ctx := context.Background()

labels, err := opts.ParseLabels(uc.labels)
if err != nil {
return err
}
// UpdateConfig.Label's type change to []string
// labels, err := opts.ParseLabels(uc.labels)
// if err != nil {
// return err
// }

if err := opts.ValidateMemorySwappiness(uc.memorySwappiness); err != nil {
return err
Expand Down Expand Up @@ -95,7 +96,7 @@ func (uc *UpdateCommand) updateRun(args []string) error {

updateConfig := &types.UpdateConfig{
Env: uc.env,
Labels: labels,
Label: uc.labels,
RestartPolicy: restartPolicy,
Resources: resource,
}
Expand Down
18 changes: 15 additions & 3 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,25 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty
return fmt.Errorf("failed to update container %s: can not update kernel memory to a running container, please stop it first", c.ID())
}

if len(config.Labels) != 0 {
// compatibility with alidocker, UpdateConfig.Label is []string
// but ContainerConfig.Labels is map[string]string
if len(config.Label) != 0 {
if c.meta.Config.Labels == nil {
c.meta.Config.Labels = map[string]string{}
}

for k, v := range config.Labels {
c.meta.Config.Labels[k] = v
// support remove some labels
newLabels, err := opts.ParseLabels(config.Label)
if err != nil {
return fmt.Errorf("failed to parse labels: %v", err)
}

for k, v := range newLabels {
if v == "" {
delete(c.meta.Config.Labels, k)
} else {
c.meta.Config.Labels[k] = v
}
}
}

Expand Down

0 comments on commit 00f4f6e

Please sign in to comment.