container_opts.go: add WithAdditionalContainerLabels
WithAdditionalContainerLabels() preserves the existing entries in c.Labels. OTOH, WithContainerLabels() clears them. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
parent
7b0149ac4a
commit
041eb3ac31
@ -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 {
|
func WithContainerLabels(labels map[string]string) NewContainerOpts {
|
||||||
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
return func(_ context.Context, _ *Client, c *containers.Container) error {
|
||||||
c.Labels = labels
|
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)
|
// WithImageStopSignal sets a well-known containerd label (StopSignalLabel)
|
||||||
// on the container for storing the stop signal specified in the OCI image
|
// on the container for storing the stop signal specified in the OCI image
|
||||||
// config
|
// config
|
||||||
|
Loading…
Reference in New Issue
Block a user