File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,14 +85,31 @@ func WithImageName(n string) NewContainerOpts {
8585 }
8686}
8787
88- // WithContainerLabels adds the provided labels to the container
88+ // WithContainerLabels sets the provided labels to the container.
89+ // The existing labels are cleared.
90+ // Use WithAdditionalContainerLabels to preserve the existing labels.
8991func WithContainerLabels (labels map [string ]string ) NewContainerOpts {
9092 return func (_ context.Context , _ * Client , c * containers.Container ) error {
9193 c .Labels = labels
9294 return nil
9395 }
9496}
9597
98+ // WithAdditionalContainerLabels adds the provided labels to the container
99+ // The existing labels are preserved as long as they do not conflict with the added labels.
100+ func WithAdditionalContainerLabels (labels map [string ]string ) NewContainerOpts {
101+ return func (_ context.Context , _ * Client , c * containers.Container ) error {
102+ if c .Labels == nil {
103+ c .Labels = labels
104+ return nil
105+ }
106+ for k , v := range labels {
107+ c .Labels [k ] = v
108+ }
109+ return nil
110+ }
111+ }
112+
96113// WithImageStopSignal sets a well-known containerd label (StopSignalLabel)
97114// on the container for storing the stop signal specified in the OCI image
98115// config
You can’t perform that action at this time.
0 commit comments