Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: update label compatibility with alidocker #1228

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us keep this, and update this to Labels in sometime when ok.

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