Merge pull request #4840 from AkihiroSuda/with-container-labels-2
container_opts.go: add WithAdditionalContainerLabels
This commit is contained in:
commit
23315f8647
@ -85,7 +85,9 @@ func WithImageName(n string) NewContainerOpts {
|
||||
}
|
||||
}
|
||||
|
||||
// WithContainerLabels adds the provided labels to the container
|
||||
// WithContainerLabels sets the provided labels to the container.
|
||||
// The existing labels are cleared.
|
||||
// Use WithAdditionalContainerLabels to preserve the existing labels.
|
||||
func WithContainerLabels(labels map[string]string) NewContainerOpts {
|
||||
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
||||
c.Labels = labels
|
||||
@ -93,6 +95,21 @@ func WithContainerLabels(labels map[string]string) NewContainerOpts {
|
||||
}
|
||||
}
|
||||
|
||||
// WithAdditionalContainerLabels adds the provided labels to the container
|
||||
// The existing labels are preserved as long as they do not conflict with the added labels.
|
||||
func WithAdditionalContainerLabels(labels map[string]string) NewContainerOpts {
|
||||
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
||||
if c.Labels == nil {
|
||||
c.Labels = labels
|
||||
return nil
|
||||
}
|
||||
for k, v := range labels {
|
||||
c.Labels[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithImageStopSignal sets a well-known containerd label (StopSignalLabel)
|
||||
// on the container for storing the stop signal specified in the OCI image
|
||||
// config
|
||||
|
Loading…
Reference in New Issue
Block a user