mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Merge pull request #20976 from Luap99/string-array
cli: use StringArray over StringSlice Part 2
This commit is contained in:
@ -110,7 +110,7 @@ func pullFlags(cmd *cobra.Command) {
|
|||||||
_ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
decryptionKeysFlagName := "decryption-key"
|
decryptionKeysFlagName := "decryption-key"
|
||||||
flags.StringSliceVar(&pullOptions.DecryptionKeys, decryptionKeysFlagName, nil, "Key needed to decrypt the image (e.g. /path/to/key.pem)")
|
flags.StringArrayVar(&pullOptions.DecryptionKeys, decryptionKeysFlagName, nil, "Key needed to decrypt the image (e.g. /path/to/key.pem)")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(decryptionKeysFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(decryptionKeysFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
if registry.IsRemote() {
|
if registry.IsRemote() {
|
||||||
|
@ -138,7 +138,7 @@ func pushFlags(cmd *cobra.Command) {
|
|||||||
_ = cmd.RegisterFlagCompletionFunc(compLevel, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(compLevel, completion.AutocompleteNone)
|
||||||
|
|
||||||
encryptionKeysFlagName := "encryption-key"
|
encryptionKeysFlagName := "encryption-key"
|
||||||
flags.StringSliceVar(&pushOptions.EncryptionKeys, encryptionKeysFlagName, nil, "Key with the encryption protocol to use to encrypt the image (e.g. jwe:/path/to/key.pem)")
|
flags.StringArrayVar(&pushOptions.EncryptionKeys, encryptionKeysFlagName, nil, "Key with the encryption protocol to use to encrypt the image (e.g. jwe:/path/to/key.pem)")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(encryptionKeysFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(encryptionKeysFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
encryptLayersFlagName := "encrypt-layer"
|
encryptLayersFlagName := "encrypt-layer"
|
||||||
|
@ -41,7 +41,7 @@ func init() {
|
|||||||
_ = setFlags.MarkHidden("policypath")
|
_ = setFlags.MarkHidden("policypath")
|
||||||
|
|
||||||
pubkeysfileFlagName := "pubkeysfile"
|
pubkeysfileFlagName := "pubkeysfile"
|
||||||
setFlags.StringSliceVarP(&setOptions.PubKeysFile, pubkeysfileFlagName, "f", []string{}, `Path of installed public key(s) to trust for TARGET.
|
setFlags.StringArrayVarP(&setOptions.PubKeysFile, pubkeysfileFlagName, "f", []string{}, `Path of installed public key(s) to trust for TARGET.
|
||||||
Absolute path to keys is added to policy.json. May
|
Absolute path to keys is added to policy.json. May
|
||||||
used multiple times to define multiple public keys.
|
used multiple times to define multiple public keys.
|
||||||
File(s) must exist before using this command`)
|
File(s) must exist before using this command`)
|
||||||
|
@ -98,7 +98,7 @@ func playFlags(cmd *cobra.Command) {
|
|||||||
flags.SetNormalizeFunc(utils.AliasFlags)
|
flags.SetNormalizeFunc(utils.AliasFlags)
|
||||||
|
|
||||||
annotationFlagName := "annotation"
|
annotationFlagName := "annotation"
|
||||||
flags.StringSliceVar(
|
flags.StringArrayVar(
|
||||||
&playOptions.annotations,
|
&playOptions.annotations,
|
||||||
annotationFlagName, []string{},
|
annotationFlagName, []string{},
|
||||||
"Add annotations to pods (key=value)",
|
"Add annotations to pods (key=value)",
|
||||||
@ -124,7 +124,7 @@ func playFlags(cmd *cobra.Command) {
|
|||||||
_ = cmd.RegisterFlagCompletionFunc(logDriverFlagName, common.AutocompleteLogDriver)
|
_ = cmd.RegisterFlagCompletionFunc(logDriverFlagName, common.AutocompleteLogDriver)
|
||||||
|
|
||||||
logOptFlagName := "log-opt"
|
logOptFlagName := "log-opt"
|
||||||
flags.StringSliceVar(
|
flags.StringArrayVar(
|
||||||
&playOptions.LogOptions,
|
&playOptions.LogOptions,
|
||||||
logOptFlagName, []string{},
|
logOptFlagName, []string{},
|
||||||
"Logging driver options",
|
"Logging driver options",
|
||||||
@ -165,7 +165,7 @@ func playFlags(cmd *cobra.Command) {
|
|||||||
flags.BoolVarP(&playOptions.Wait, waitFlagName, "w", false, "Clean up all objects created when a SIGTERM is received or pods exit")
|
flags.BoolVarP(&playOptions.Wait, waitFlagName, "w", false, "Clean up all objects created when a SIGTERM is received or pods exit")
|
||||||
|
|
||||||
configmapFlagName := "configmap"
|
configmapFlagName := "configmap"
|
||||||
flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
|
flags.StringArrayVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
noTruncFlagName := "no-trunc"
|
noTruncFlagName := "no-trunc"
|
||||||
@ -239,7 +239,7 @@ func play(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
for _, annotation := range playOptions.annotations {
|
for _, annotation := range playOptions.annotations {
|
||||||
splitN := strings.SplitN(annotation, "=", 2)
|
splitN := strings.SplitN(annotation, "=", 2)
|
||||||
if len(splitN) > 2 {
|
if len(splitN) != 2 {
|
||||||
return fmt.Errorf("annotation %q must include an '=' sign", annotation)
|
return fmt.Errorf("annotation %q must include an '=' sign", annotation)
|
||||||
}
|
}
|
||||||
if playOptions.Annotations == nil {
|
if playOptions.Annotations == nil {
|
||||||
|
@ -48,7 +48,7 @@ func init() {
|
|||||||
flags.BoolVar(&manifestAddOpts.All, "all", false, "add all of the list's images if the image is a list")
|
flags.BoolVar(&manifestAddOpts.All, "all", false, "add all of the list's images if the image is a list")
|
||||||
|
|
||||||
annotationFlagName := "annotation"
|
annotationFlagName := "annotation"
|
||||||
flags.StringSliceVar(&manifestAddOpts.Annotation, annotationFlagName, nil, "set an `annotation` for the specified image")
|
flags.StringArrayVar(&manifestAddOpts.Annotation, annotationFlagName, nil, "set an `annotation` for the specified image")
|
||||||
_ = addCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone)
|
_ = addCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
archFlagName := "arch"
|
archFlagName := "arch"
|
||||||
|
@ -31,7 +31,7 @@ func init() {
|
|||||||
flags := annotateCmd.Flags()
|
flags := annotateCmd.Flags()
|
||||||
|
|
||||||
annotationFlagName := "annotation"
|
annotationFlagName := "annotation"
|
||||||
flags.StringSliceVar(&manifestAnnotateOpts.Annotation, annotationFlagName, nil, "set an `annotation` for the specified image")
|
flags.StringArrayVar(&manifestAnnotateOpts.Annotation, annotationFlagName, nil, "set an `annotation` for the specified image")
|
||||||
_ = annotateCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone)
|
_ = annotateCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
archFlagName := "arch"
|
archFlagName := "arch"
|
||||||
|
@ -314,7 +314,7 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(125))
|
Expect(session).Should(Exit(125))
|
||||||
Expect(session.ErrorToString()).To(ContainSubstring("no value given for annotation"))
|
Expect(session.ErrorToString()).To(ContainSubstring("no value given for annotation"))
|
||||||
session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge=fuga", "foo", imageList})
|
session = podmanTest.Podman([]string{"manifest", "add", "--annotation", "hoge=fuga", "--annotation", "key=val,withcomma", "foo", imageList})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
||||||
@ -324,7 +324,7 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
var inspect define.ManifestListData
|
var inspect define.ManifestListData
|
||||||
err := json.Unmarshal(session.Out.Contents(), &inspect)
|
err := json.Unmarshal(session.Out.Contents(), &inspect)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(inspect.Manifests[0].Annotations).To(Equal(map[string]string{"hoge": "fuga"}))
|
Expect(inspect.Manifests[0].Annotations).To(Equal(map[string]string{"hoge": "fuga", "key": "val,withcomma"}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("add --os", func() {
|
It("add --os", func() {
|
||||||
@ -347,7 +347,7 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
session = podmanTest.Podman([]string{"manifest", "add", "foo", imageListInstance})
|
session = podmanTest.Podman([]string{"manifest", "add", "foo", imageListInstance})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
session = podmanTest.Podman([]string{"manifest", "annotate", "--annotation", "hello=world", "--arch", "bar", "foo", imageListARM64InstanceDigest})
|
session = podmanTest.Podman([]string{"manifest", "annotate", "--annotation", "hello=world,withcomma", "--arch", "bar", "foo", imageListARM64InstanceDigest})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
session = podmanTest.Podman([]string{"manifest", "inspect", "foo"})
|
||||||
@ -355,7 +355,7 @@ add_compression = ["zstd"]`), 0o644)
|
|||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(`"architecture": "bar"`))
|
Expect(session.OutputToString()).To(ContainSubstring(`"architecture": "bar"`))
|
||||||
// Check added annotation
|
// Check added annotation
|
||||||
Expect(session.OutputToString()).To(ContainSubstring(`"hello": "world"`))
|
Expect(session.OutputToString()).To(ContainSubstring(`"hello": "world,withcomma"`))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("remove digest", func() {
|
It("remove digest", func() {
|
||||||
|
@ -4886,7 +4886,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q
|
|||||||
err := generateKubeYaml("pod", pod, kubeYaml)
|
err := generateKubeYaml("pod", pod, kubeYaml)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
kube := podmanTest.Podman([]string{"kube", "play", kubeYaml, "--log-driver", "journald", "--log-opt", "tag={{.ImageName}}"})
|
kube := podmanTest.Podman([]string{"kube", "play", kubeYaml, "--log-driver", "journald", "--log-opt", "tag={{.ImageName}},withcomma"})
|
||||||
kube.WaitWithDefaultTimeout()
|
kube.WaitWithDefaultTimeout()
|
||||||
Expect(kube).Should(ExitCleanly())
|
Expect(kube).Should(ExitCleanly())
|
||||||
|
|
||||||
@ -4897,7 +4897,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q
|
|||||||
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)})
|
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)})
|
||||||
inspect.WaitWithDefaultTimeout()
|
inspect.WaitWithDefaultTimeout()
|
||||||
Expect(start).Should(ExitCleanly())
|
Expect(start).Should(ExitCleanly())
|
||||||
Expect((inspect.InspectContainerToJSON()[0]).HostConfig.LogConfig.Tag).To(Equal("{{.ImageName}}"))
|
Expect((inspect.InspectContainerToJSON()[0]).HostConfig.LogConfig.Tag).To(Equal("{{.ImageName}},withcomma"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("using a user namespace", func() {
|
It("using a user namespace", func() {
|
||||||
|
@ -612,7 +612,7 @@ var _ = Describe("Podman pull", func() {
|
|||||||
|
|
||||||
decryptionTestHelper := func(imgPath string) *PodmanSessionIntegration {
|
decryptionTestHelper := func(imgPath string) *PodmanSessionIntegration {
|
||||||
bitSize := 1024
|
bitSize := 1024
|
||||||
keyFileName := filepath.Join(podmanTest.TempDir, "key")
|
keyFileName := filepath.Join(podmanTest.TempDir, "key,withcomma")
|
||||||
publicKeyFileName, privateKeyFileName, err := WriteRSAKeyPair(keyFileName, bitSize)
|
publicKeyFileName, privateKeyFileName, err := WriteRSAKeyPair(keyFileName, bitSize)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
@ -2152,7 +2152,7 @@ WORKDIR /madethis`, BB)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bitSize := 1024
|
bitSize := 1024
|
||||||
keyFileName := filepath.Join(podmanTest.TempDir, "key")
|
keyFileName := filepath.Join(podmanTest.TempDir, "key,withcomma")
|
||||||
publicKeyFileName, privateKeyFileName, err := WriteRSAKeyPair(keyFileName, bitSize)
|
publicKeyFileName, privateKeyFileName, err := WriteRSAKeyPair(keyFileName, bitSize)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
@ -435,11 +435,18 @@ _EOF
|
|||||||
@test "podman kube --annotation" {
|
@test "podman kube --annotation" {
|
||||||
TESTDIR=$PODMAN_TMPDIR/testdir
|
TESTDIR=$PODMAN_TMPDIR/testdir
|
||||||
RANDOMSTRING=$(random_string 15)
|
RANDOMSTRING=$(random_string 15)
|
||||||
|
ANNOTATION_WITH_COMMA="comma,$(random_string 5)"
|
||||||
mkdir -p $TESTDIR
|
mkdir -p $TESTDIR
|
||||||
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
|
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
|
||||||
run_podman kube play --annotation "name=$RANDOMSTRING" $PODMAN_TMPDIR/test.yaml
|
run_podman kube play --annotation "name=$RANDOMSTRING" \
|
||||||
|
--annotation "anno=$ANNOTATION_WITH_COMMA" $PODMAN_TMPDIR/test.yaml
|
||||||
run_podman inspect --format "{{ .Config.Annotations }}" test_pod-test
|
run_podman inspect --format "{{ .Config.Annotations }}" test_pod-test
|
||||||
is "$output" ".*name:$RANDOMSTRING" "Annotation should be added to pod"
|
is "$output" ".*name:$RANDOMSTRING" "Annotation should be added to pod"
|
||||||
|
is "$output" ".*anno:$ANNOTATION_WITH_COMMA" "Annotation with comma should be added to pod"
|
||||||
|
|
||||||
|
# invalid annotation
|
||||||
|
run_podman 125 kube play --annotation "val" $PODMAN_TMPDIR/test.yaml
|
||||||
|
assert "$output" == "Error: annotation \"val\" must include an '=' sign" "invalid annotation error"
|
||||||
|
|
||||||
run_podman stop -a -t 0
|
run_podman stop -a -t 0
|
||||||
run_podman pod rm -t 0 -f test_pod
|
run_podman pod rm -t 0 -f test_pod
|
||||||
@ -692,7 +699,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "podman kube play with configmaps" {
|
@test "podman kube play with configmaps" {
|
||||||
configmap_file=${PODMAN_TMPDIR}/play_kube_configmap_configmaps$(random_string 6).yaml
|
configmap_file=${PODMAN_TMPDIR}/play_kube_configmap_configmaps$(random_string 6),withcomma.yaml
|
||||||
echo "
|
echo "
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
Reference in New Issue
Block a user