add option to remove Pod name prefix in resulting container name

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
This commit is contained in:
Oleksandr Krutko
2025-10-15 23:37:03 +03:00
parent 86eecc976a
commit 098d8efecc
5 changed files with 17 additions and 1 deletions

View File

@@ -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.")
}
}

View File

@@ -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.

View File

@@ -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

View File

@@ -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 {

View File

@@ -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