From 098d8efecc6c9bb8a263a8dc1864273327fbb214 Mon Sep 17 00:00:00 2001 From: Oleksandr Krutko Date: Wed, 15 Oct 2025 23:37:03 +0300 Subject: [PATCH] add option to remove Pod name prefix in resulting container name Signed-off-by: Oleksandr Krutko --- cmd/podman/kube/play.go | 3 +++ docs/source/markdown/podman-kube-play.1.md.in | 4 ++++ pkg/domain/entities/play.go | 2 ++ pkg/domain/infra/abi/play.go | 1 + pkg/specgen/generate/kube/kube.go | 8 +++++++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go index cfa6f39495..c850641eaf 100644 --- a/cmd/podman/kube/play.go +++ b/cmd/podman/kube/play.go @@ -205,6 +205,9 @@ func playFlags(cmd *cobra.Command) { exitFlagName := "service-exit-code-propagation" flags.StringVar(&playOptions.ExitCodePropagation, exitFlagName, "", "Exit-code propagation of the service container") _ = flags.MarkHidden(exitFlagName) + + noPodPrefix := "no-pod-prefix" + flags.BoolVar(&playOptions.NoPodPrefix, noPodPrefix, false, "Don't use pod name as prefix in resulting container name.") } } diff --git a/docs/source/markdown/podman-kube-play.1.md.in b/docs/source/markdown/podman-kube-play.1.md.in index 0d4cbec4a6..1aef64c2a6 100644 --- a/docs/source/markdown/podman-kube-play.1.md.in +++ b/docs/source/markdown/podman-kube-play.1.md.in @@ -260,6 +260,10 @@ When no network option is specified and *host* network mode is not configured in This option conflicts with host added in the Kubernetes YAML. +#### **--no-pod-prefix** + +Don't use pod name as prefix in resulting container name. + #### **--publish**=*[[ip:][hostPort]:]containerPort[/protocol]* Define or override a port definition in the YAML file. diff --git a/pkg/domain/entities/play.go b/pkg/domain/entities/play.go index ae51bebd67..cc5a4fa5f5 100644 --- a/pkg/domain/entities/play.go +++ b/pkg/domain/entities/play.go @@ -81,6 +81,8 @@ type PlayKubeOptions struct { Wait bool // SystemContext - used when building the image SystemContext *types.SystemContext + // Don't use pod name as prefix in resulting container name. + NoPodPrefix bool } // PlayKubePod represents a single pod and associated containers created by play kube diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 15d1a61aa4..bf41e73a44 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1089,6 +1089,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY VolumesFrom: volumesFrom, ImageVolumes: automountImages, UtsNSIsHost: p.UtsNs.IsHost(), + NoPodPrefix: options.NoPodPrefix, } if podYAML.Spec.TerminationGracePeriodSeconds != nil { diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index 9fa93634c1..51a05130b3 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -185,6 +185,8 @@ type CtrSpecGenOptions struct { PodSecurityContext *v1.PodSecurityContext // TerminationGracePeriodSeconds is the grace period given to a container to stop before being forcefully killed TerminationGracePeriodSeconds *int64 + // Don't use pod name as prefix in resulting container name. + NoPodPrefix bool } func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGenerator, error) { @@ -217,7 +219,11 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener return nil, errors.New("got empty pod name on container creation when playing kube") } - s.Name = fmt.Sprintf("%s-%s", opts.PodName, opts.Container.Name) + if opts.NoPodPrefix { + s.Name = opts.Container.Name + } else { + s.Name = fmt.Sprintf("%s-%s", opts.PodName, opts.Container.Name) + } s.Terminal = &opts.Container.TTY