fix remote command parameters

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
This commit is contained in:
Oleksandr Krutko
2025-10-17 23:21:39 +03:00
parent f6dd05d9c4
commit bb4fa066b3
8 changed files with 40 additions and 8 deletions

View File

@@ -176,6 +176,9 @@ func playFlags(cmd *cobra.Command) {
flags.BoolVar(&playOptions.UseLongAnnotations, noTruncFlagName, false, "Use annotations that are not truncated to the Kubernetes maximum length of 63 characters") flags.BoolVar(&playOptions.UseLongAnnotations, noTruncFlagName, false, "Use annotations that are not truncated to the Kubernetes maximum length of 63 characters")
_ = flags.MarkHidden(noTruncFlagName) _ = flags.MarkHidden(noTruncFlagName)
noPodPrefix := "no-pod-prefix"
flags.BoolVar(&playOptions.NoPodPrefix, noPodPrefix, false, "Do not prefix container name with pod name")
if !registry.IsRemote() { if !registry.IsRemote() {
certDirFlagName := "cert-dir" certDirFlagName := "cert-dir"
flags.StringVar(&playOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys") flags.StringVar(&playOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
@@ -205,9 +208,6 @@ func playFlags(cmd *cobra.Command) {
exitFlagName := "service-exit-code-propagation" exitFlagName := "service-exit-code-propagation"
flags.StringVar(&playOptions.ExitCodePropagation, exitFlagName, "", "Exit-code propagation of the service container") flags.StringVar(&playOptions.ExitCodePropagation, exitFlagName, "", "Exit-code propagation of the service container")
_ = flags.MarkHidden(exitFlagName) _ = flags.MarkHidden(exitFlagName)
noPodPrefix := "no-pod-prefix"
flags.BoolVar(&playOptions.NoPodPrefix, noPodPrefix, false, "Don't use pod name as prefix in resulting container name.")
} }
} }

View File

@@ -262,7 +262,7 @@ This option conflicts with host added in the Kubernetes YAML.
#### **--no-pod-prefix** #### **--no-pod-prefix**
Don't use pod name as prefix in resulting container name. Do not prefix container name with pod name.
#### **--publish**=*[[ip:][hostPort]:]containerPort[/protocol]* #### **--publish**=*[[ip:][hostPort]:]containerPort[/protocol]*

View File

@@ -123,6 +123,7 @@ func KubePlay(w http.ResponseWriter, r *http.Request) {
Userns string `schema:"userns"` Userns string `schema:"userns"`
Wait bool `schema:"wait"` Wait bool `schema:"wait"`
Build bool `schema:"build"` Build bool `schema:"build"`
NoPodPrefix bool `schema:"noPodPrefix"`
}{ }{
TLSVerify: true, TLSVerify: true,
Start: true, Start: true,
@@ -198,6 +199,7 @@ func KubePlay(w http.ResponseWriter, r *http.Request) {
Userns: query.Userns, Userns: query.Userns,
Wait: query.Wait, Wait: query.Wait,
ContextDir: contextDirectory, ContextDir: contextDirectory,
NoPodPrefix: query.NoPodPrefix,
} }
if _, found := r.URL.Query()["build"]; found { if _, found := r.URL.Query()["build"]; found {
options.Build = types.NewOptionalBool(query.Build) options.Build = types.NewOptionalBool(query.Build)

View File

@@ -63,6 +63,7 @@ type PlayOptions struct {
// Wait - indicates whether to return after having created the pods // Wait - indicates whether to return after having created the pods
Wait *bool Wait *bool
ServiceContainer *bool ServiceContainer *bool
NoPodPrefix *bool
} }
// ApplyOptions are optional options for applying kube YAML files to a k8s cluster // ApplyOptions are optional options for applying kube YAML files to a k8s cluster

View File

@@ -407,3 +407,18 @@ func (o *PlayOptions) GetServiceContainer() bool {
} }
return *o.ServiceContainer return *o.ServiceContainer
} }
// WithNoPodPrefix set field NoPodPrefix to given value
func (o *PlayOptions) WithNoPodPrefix(value bool) *PlayOptions {
o.NoPodPrefix = &value
return o
}
// GetNoPodPrefix returns value of field NoPodPrefix
func (o *PlayOptions) GetNoPodPrefix() bool {
if o.NoPodPrefix == nil {
var z bool
return z
}
return *o.NoPodPrefix
}

View File

@@ -81,7 +81,7 @@ type PlayKubeOptions struct {
Wait bool Wait bool
// SystemContext - used when building the image // SystemContext - used when building the image
SystemContext *types.SystemContext SystemContext *types.SystemContext
// Don't use pod name as prefix in resulting container name. // Do not prefix container name with pod name
NoPodPrefix bool NoPodPrefix bool
} }

View File

@@ -75,6 +75,7 @@ func (ic *ContainerEngine) PlayKube(_ context.Context, body io.Reader, opts enti
options.WithPublishPorts(opts.PublishPorts) options.WithPublishPorts(opts.PublishPorts)
options.WithPublishAllPorts(opts.PublishAllPorts) options.WithPublishAllPorts(opts.PublishAllPorts)
options.WithNoTrunc(opts.UseLongAnnotations) options.WithNoTrunc(opts.UseLongAnnotations)
options.WithNoPodPrefix(opts.NoPodPrefix)
return play.KubeWithBody(ic.ClientCtx, body, options) return play.KubeWithBody(ic.ClientCtx, body, options)
} }

View File

@@ -222,6 +222,19 @@ spec:
- sleep - sleep
- "3600"` - "3600"`
var simpleWithoutPodPrefixYaml = `
apiVersion: v1
kind: Pod
metadata:
name: libpod-test
spec:
containers:
- name: simpleWithoutPodPrefix
image: ` + CITEST_IMAGE + `
command:
- sleep
- "3600"`
var unknownKindYaml = ` var unknownKindYaml = `
apiVersion: v1 apiVersion: v1
kind: UnknownKind kind: UnknownKind
@@ -6422,11 +6435,11 @@ spec:
}) })
It("test container name without Pod name prefix", func() { It("test container name without Pod name prefix", func() {
err := writeYaml(podnameEqualsContainerNameYaml, kubeYaml) err := writeYaml(simpleWithoutPodPrefixYaml, kubeYaml)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
podmanTest.PodmanExitCleanly("kube", "play", "--no-pod-prefix", kubeYaml) podmanTest.PodmanExitCleanly("kube", "play", "--no-pod-prefix", kubeYaml)
inspect := podmanTest.PodmanExitCleanly("inspect", "podnameEqualsContainerNameYaml") inspect := podmanTest.PodmanExitCleanly("inspect", "simpleWithoutPodPrefix")
Expect(inspect.InspectContainerToJSON()[0].Name).Should(Equal("podnameEqualsContainerNameYaml")) Expect(inspect.InspectContainerToJSON()[0].Name).Should(Equal("simpleWithoutPodPrefix"))
}) })
}) })