summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-03-09 17:30:01 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-03-09 17:30:01 -0500
commitfeaa1a134a4fd0a7d25bab485708a201321bfb56 (patch)
tree080fa2a13998bc0b9f3c0689df6317f736aa8d02 /cmd
parentacfcecf2ae41528d1d7ecd43d37d8fd554f587bc (diff)
downloadpodman-feaa1a134a4fd0a7d25bab485708a201321bfb56.tar.gz
podman-feaa1a134a4fd0a7d25bab485708a201321bfb56.tar.bz2
podman-feaa1a134a4fd0a7d25bab485708a201321bfb56.zip
Add podman play kube --annotation
Allow users to add annotions in the podman play kube command. This PR Also fixes the fact that annotations in the pod spec were not being passed down to containers. Fixes: https://github.com/containers/podman/issues/12968 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/play/kube.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go
index 563a6251c..3067f0d54 100644
--- a/cmd/podman/play/kube.go
+++ b/cmd/podman/play/kube.go
@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"os"
+ "strings"
"github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/completion"
@@ -31,7 +32,8 @@ type playKubeOptionsWrapper struct {
}
var (
- macs []string
+ annotations []string
+ macs []string
// https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/
defaultSeccompRoot = "/var/lib/kubelet/seccomp"
kubeOptions = playKubeOptionsWrapper{}
@@ -61,6 +63,13 @@ func init() {
flags := kubeCmd.Flags()
flags.SetNormalizeFunc(utils.AliasFlags)
+ annotationFlagName := "annotation"
+ flags.StringSliceVar(
+ &annotations,
+ annotationFlagName, []string{},
+ "Add annotations to pods (key=value)",
+ )
+ _ = kubeCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone)
credsFlagName := "creds"
flags.StringVar(&kubeOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
_ = kubeCmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone)
@@ -161,6 +170,16 @@ func kube(cmd *cobra.Command, args []string) error {
kubeOptions.Password = creds.Password
}
+ for _, annotation := range annotations {
+ splitN := strings.SplitN(annotation, "=", 2)
+ if len(splitN) > 2 {
+ return errors.Errorf("annotation %q must include an '=' sign", annotation)
+ }
+ if kubeOptions.Annotations == nil {
+ kubeOptions.Annotations = make(map[string]string)
+ }
+ kubeOptions.Annotations[splitN[0]] = splitN[1]
+ }
yamlfile := args[0]
if yamlfile == "-" {
yamlfile = "/dev/stdin"