Skip to content
Merged
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
16 changes: 8 additions & 8 deletions pkg/cmd/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
if err != nil {
return nil, generateRemoveStateDirFunc(ctx, id, internalLabels), err
}
// Image config labels must be applied before any other label-setting opt:
// containerd.WithImageConfigLabels resets the container labels, so running it
// later would clear labels set by other opts (e.g. the restart policy).
if ensuredImage != nil {
cOpts = append(cOpts, containerd.WithImageConfigLabels(ensuredImage.Image))
}
opts = append(opts, rootfsOpts...)
cOpts = append(cOpts, rootfsCOpts...)
if options.UserNS != "" {
Expand Down Expand Up @@ -357,7 +363,7 @@ func Create(ctx context.Context, client *containerd.Client, args []string, netMa
internalLabels.healthcheck = healthcheckConfig
}

lCOpts, err := withContainerLabels(options.Label, options.LabelFile, ensuredImage)
lCOpts, err := withContainerLabels(options.Label, options.LabelFile)
if err != nil {
return nil, generateRemoveOrphanedDirsFunc(ctx, id, dataStore, internalLabels), err
}
Expand Down Expand Up @@ -650,15 +656,9 @@ func withNerdctlOCIHook(cmd string, args []string) (oci.SpecOpts, error) {
}, nil
}

func withContainerLabels(label, labelFile []string, ensuredImage *imgutil.EnsuredImage) ([]containerd.NewContainerOpts, error) {
func withContainerLabels(label, labelFile []string) ([]containerd.NewContainerOpts, error) {
var opts []containerd.NewContainerOpts

// add labels defined by image
if ensuredImage != nil {
imageLabelOpts := containerd.WithAdditionalContainerLabels(ensuredImage.ImageConfig.Labels)
opts = append(opts, imageLabelOpts)
}

labelMap, err := readKVStringsMapfFromLabel(label, labelFile)
if err != nil {
return nil, err
Expand Down
Loading