From 6565bde6e8d03fe805ec03d92b13eaaf34cd8fe0 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 13 Jan 2025 12:05:25 -0500 Subject: [PATCH 1/2] Add --no-hostname option Fixes: https://github.com/containers/podman/issues/25002 Also add the ability to inspect containers for UseImageHosts and UseImageHostname. Finally fixed some bugs in handling of --no-hosts for Pods, which I descovered. Signed-off-by: Daniel J Walsh --- cmd/podman/common/netflags.go | 9 ++++++ cmd/podman/kube/play.go | 4 ++- docs/source/markdown/options/no-hostname.md | 6 ++-- .../markdown/podman-container-inspect.1.md.in | 4 +++ docs/source/markdown/podman-create.1.md.in | 2 ++ docs/source/markdown/podman-kube-play.1.md.in | 2 ++ .../source/markdown/podman-pod-create.1.md.in | 2 ++ docs/source/markdown/podman-run.1.md.in | 2 ++ libpod/container_config.go | 7 ++++- libpod/container_inspect.go | 2 ++ libpod/container_internal_common.go | 2 +- libpod/container_internal_freebsd.go | 2 +- libpod/container_internal_linux.go | 6 +++- libpod/define/container_inspect.go | 2 ++ libpod/define/pod_inspect.go | 3 ++ libpod/options.go | 13 ++++++++ libpod/pod_api.go | 1 + pkg/api/handlers/libpod/kube.go | 2 ++ pkg/bindings/kube/types.go | 2 ++ pkg/bindings/kube/types_play_options.go | 15 +++++++++ pkg/domain/entities/play.go | 3 ++ pkg/domain/entities/pods.go | 1 + pkg/domain/entities/types.go | 2 ++ pkg/domain/infra/abi/play.go | 2 +- pkg/domain/infra/tunnel/kube.go | 2 +- pkg/specgen/generate/container.go | 2 ++ pkg/specgen/generate/kube/kube.go | 2 +- pkg/specgen/generate/namespaces.go | 3 ++ pkg/specgen/generate/pod_create.go | 3 ++ pkg/specgen/podspecgen.go | 4 +++ pkg/specgen/specgen.go | 4 +++ pkg/specgenutil/specgen.go | 1 + test/e2e/play_kube_test.go | 31 +++++++++++++------ test/e2e/pod_create_test.go | 16 ++++++++++ test/system/030-run.bats | 17 ++++++++++ 35 files changed, 160 insertions(+), 21 deletions(-) diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go index 4d0cb5266b..64f0297476 100644 --- a/cmd/podman/common/netflags.go +++ b/cmd/podman/common/netflags.go @@ -95,6 +95,10 @@ func DefineNetFlags(cmd *cobra.Command) { ) _ = cmd.RegisterFlagCompletionFunc(publishFlagName, completion.AutocompleteNone) + netFlags.Bool( + "no-hostname", false, "Do not create /etc/hostname within the container, instead use the version from the image", + ) + netFlags.Bool( "no-hosts", podmanConfig.ContainersConfDefaultsRO.Containers.NoHosts, "Do not create /etc/hosts within the container, instead use the version from the image", @@ -192,6 +196,11 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti } } + opts.NoHostname, err = flags.GetBool("no-hostname") + if err != nil { + return nil, err + } + opts.NoHosts, err = flags.GetBool("no-hosts") if err != nil { return nil, err diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go index 2c6175af6f..37669348be 100644 --- a/cmd/podman/kube/play.go +++ b/cmd/podman/kube/play.go @@ -98,6 +98,7 @@ func init() { func playFlags(cmd *cobra.Command) { flags := cmd.Flags() flags.SetNormalizeFunc(utils.AliasFlags) + podmanConfig := registry.PodmanConfig() annotationFlagName := "annotation" flags.StringArrayVar( @@ -139,7 +140,8 @@ func playFlags(cmd *cobra.Command) { ) _ = cmd.RegisterFlagCompletionFunc(usernsFlagName, common.AutocompleteUserNamespace) - flags.BoolVar(&playOptions.NoHosts, "no-hosts", false, "Do not create /etc/hosts within the pod's containers, instead use the version from the image") + flags.BoolVar(&playOptions.NoHostname, "no-hostname", false, "Do not create /etc/hostname within the container, instead use the version from the image") + flags.BoolVar(&playOptions.NoHosts, "no-hosts", podmanConfig.ContainersConfDefaultsRO.Containers.NoHosts, "Do not create /etc/hosts within the pod's containers, instead use the version from the image") flags.BoolVarP(&playOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images") flags.BoolVar(&playOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries") flags.BoolVar(&playOptions.StartCLI, "start", true, "Start the pod after creating it") diff --git a/docs/source/markdown/options/no-hostname.md b/docs/source/markdown/options/no-hostname.md index 1cb4d8dfb6..e913aec1b5 100644 --- a/docs/source/markdown/options/no-hostname.md +++ b/docs/source/markdown/options/no-hostname.md @@ -1,9 +1,9 @@ ####> This option file is used in: -####> podman build, farm build +####> podman build, create, farm build, kube play, pod create, run ####> If file is edited, make sure the changes ####> are applicable to all of those. #### **--no-hostname** -Do not create the _/etc/hostname_ file in the container for RUN instructions. +Do not create the _/etc/hostname_ file in the containers. -By default, Buildah manages the _/etc/hostname_ file, adding the container's own hostname. When the **--no-hostname** option is set, the image's _/etc/hostname_ will be preserved unmodified if it exists. +By default, Podman manages the _/etc/hostname_ file, adding the container's own hostname. When the **--no-hostname** option is set, the image's _/etc/hostname_ will be preserved unmodified if it exists. diff --git a/docs/source/markdown/podman-container-inspect.1.md.in b/docs/source/markdown/podman-container-inspect.1.md.in index 27ba28018d..cda408a15d 100644 --- a/docs/source/markdown/podman-container-inspect.1.md.in +++ b/docs/source/markdown/podman-container-inspect.1.md.in @@ -62,6 +62,10 @@ Valid placeholders for the Go template are listed below: | .SizeRw | Size of upper (R/W) container layer, in bytes [1] | | .State ... | Container state info (struct) | | .StaticDir | Path to container metadata dir (string) | +| .UseImageHostname | Use /etc/hostname from the image if it exists? (string: true/false) +| +| .UseImageHosts | Use /etc/hosts from the image? (string: true/false) +| [1] This format specifier requires the **--size** option diff --git a/docs/source/markdown/podman-create.1.md.in b/docs/source/markdown/podman-create.1.md.in index 2225a3a582..7308fee288 100644 --- a/docs/source/markdown/podman-create.1.md.in +++ b/docs/source/markdown/podman-create.1.md.in @@ -268,6 +268,8 @@ If used together with **--pod**, the container does not join the pod's network n @@option no-healthcheck +@@option no-hostname + @@option no-hosts This option conflicts with **--add-host**. diff --git a/docs/source/markdown/podman-kube-play.1.md.in b/docs/source/markdown/podman-kube-play.1.md.in index a42ef21a52..3073c29cc9 100644 --- a/docs/source/markdown/podman-kube-play.1.md.in +++ b/docs/source/markdown/podman-kube-play.1.md.in @@ -228,6 +228,8 @@ Note: When joining multiple networks use the **--network name:mac=\** synt When no network option is specified and *host* network mode is not configured in the YAML file, a new network stack is created and pods are attached to it making possible pod to pod communication. +@@option no-hostname + @@option no-hosts This option conflicts with host added in the Kubernetes YAML. diff --git a/docs/source/markdown/podman-pod-create.1.md.in b/docs/source/markdown/podman-pod-create.1.md.in index 10a05fea97..6f696d8351 100644 --- a/docs/source/markdown/podman-pod-create.1.md.in +++ b/docs/source/markdown/podman-pod-create.1.md.in @@ -128,6 +128,8 @@ Invalid if using **--dns**, **--dns-option**, or **--dns-search** with **--netwo @@option network-alias +@@option no-hostname + @@option no-hosts This option conflicts with **--add-host**. diff --git a/docs/source/markdown/podman-run.1.md.in b/docs/source/markdown/podman-run.1.md.in index a5c967ab4e..041838b11d 100644 --- a/docs/source/markdown/podman-run.1.md.in +++ b/docs/source/markdown/podman-run.1.md.in @@ -287,6 +287,8 @@ If used together with **--pod**, the container joins the pod's network namespace @@option no-healthcheck +@@option no-hostname + @@option no-hosts This option conflicts with **--add-host**. diff --git a/libpod/container_config.go b/libpod/container_config.go index 0f6f8959b0..34a4c2e53e 100644 --- a/libpod/container_config.go +++ b/libpod/container_config.go @@ -286,10 +286,13 @@ type ContainerNetworkConfig struct { // DNS options to be set in container resolv.conf // With override options in host resolv if set DNSOption []string `json:"dnsOption,omitempty"` + // UseImageHostname indicates that /etc/hostname should not be + // bind-mounted inside the container. + UseImageHostname bool `json:"useImageHostname"` // UseImageHosts indicates that /etc/hosts should not be // bind-mounted inside the container. // Conflicts with HostAdd. - UseImageHosts bool + UseImageHosts bool `json:"useImageHosts"` // BaseHostsFile is the base file to create the `/etc/hosts` file inside the container. // This must either be an absolute path to a file on the host system, or one of the // special flags `image` or `none`. @@ -472,6 +475,8 @@ type InfraInherit struct { Volumes []*specgen.NamedVolume `json:"volumes,omitempty"` ShmSize *int64 `json:"shm_size"` ShmSizeSystemd *int64 `json:"shm_size_systemd"` + UseImageHosts bool `json:"use_image_hosts"` + UseImageHostname bool `json:"use_image_hostname"` } // IsDefaultShmSize determines if the user actually set the shm in the parent ctr or if it has been set to the default size diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 55d5dea477..a173d59a6c 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -171,6 +171,8 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver IsService: c.IsService(), KubeExitCodePropagation: config.KubeExitCodePropagation.String(), LockNumber: c.lock.ID(), + UseImageHosts: c.config.UseImageHosts, + UseImageHostname: c.config.UseImageHostname, } if config.RootfsImageID != "" { // May not be set if the container was created with --rootfs diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index 2ef27d010d..77eb280f31 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -2098,7 +2098,7 @@ rootless=%d } } - return c.makePlatformBindMounts() + return c.makeHostnameBindMount() } // createResolvConf create the resolv.conf file and bind mount it diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go index 4635da064b..55ce66dc2a 100644 --- a/libpod/container_internal_freebsd.go +++ b/libpod/container_internal_freebsd.go @@ -313,7 +313,7 @@ func setVolumeAtime(mountPoint string, st os.FileInfo) error { return nil } -func (c *Container) makePlatformBindMounts() error { +func (c *Container) makeHostnameBindMount() error { return nil } diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 5178b97f21..c1be78d31d 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -688,7 +688,11 @@ func setVolumeAtime(mountPoint string, st os.FileInfo) error { return nil } -func (c *Container) makePlatformBindMounts() error { +func (c *Container) makeHostnameBindMount() error { + if c.config.UseImageHostname { + return nil + } + // Make /etc/hostname // This should never change, so no need to recreate if it exists if _, ok := c.state.BindMounts["/etc/hostname"]; !ok { diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 3c842cb101..6859b48e1f 100644 --- a/libpod/define/container_inspect.go +++ b/libpod/define/container_inspect.go @@ -798,6 +798,8 @@ type InspectContainerData struct { LockNumber uint32 `json:"lockNumber"` Config *InspectContainerConfig `json:"Config"` HostConfig *InspectContainerHostConfig `json:"HostConfig"` + UseImageHosts bool `json:"UseImageHosts"` + UseImageHostname bool `json:"UseImageHostname"` } // InspectExecSession contains information about a given exec session. diff --git a/libpod/define/pod_inspect.go b/libpod/define/pod_inspect.go index 23b0326fb4..a66cf66675 100644 --- a/libpod/define/pod_inspect.go +++ b/libpod/define/pod_inspect.go @@ -118,6 +118,9 @@ type InspectPodInfraConfig struct { // DNSOption is a set of DNS options that will be used by the infra // container's resolv.conf and shared with the remainder of the pod. DNSOption []string + // NoManageHostname indicates that the pod will not manage /etc/hostname + // and instead each container will handle their own. + NoManageHostname bool // NoManageHosts indicates that the pod will not manage /etc/hosts and // instead each container will handle their own. NoManageHosts bool diff --git a/libpod/options.go b/libpod/options.go index 9a5c7cd1b8..4578a8ed26 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -1389,6 +1389,19 @@ func WithUseImageResolvConf() CtrCreateOption { } } +// WithUseImageHostname tells the container not to bind-mount /etc/hostname in. +func WithUseImageHostname() CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return define.ErrCtrFinalized + } + + ctr.config.UseImageHostname = true + + return nil + } +} + // WithUseImageHosts tells the container not to bind-mount /etc/hosts in. // This conflicts with WithHosts(). func WithUseImageHosts() CtrCreateOption { diff --git a/libpod/pod_api.go b/libpod/pod_api.go index 53c1024317..10ac424b8d 100644 --- a/libpod/pod_api.go +++ b/libpod/pod_api.go @@ -677,6 +677,7 @@ func (p *Pod) Inspect() (*define.InspectPodData, error) { infraConfig.HostNetwork = p.NetworkMode() == "host" infraConfig.StaticIP = infra.config.ContainerNetworkConfig.StaticIP infraConfig.NoManageResolvConf = infra.config.UseImageResolvConf + infraConfig.NoManageHostname = infra.config.UseImageHostname infraConfig.NoManageHosts = infra.config.UseImageHosts infraConfig.CPUPeriod = p.CPUPeriod() infraConfig.CPUQuota = p.CPUQuota() diff --git a/pkg/api/handlers/libpod/kube.go b/pkg/api/handlers/libpod/kube.go index a5a3bf4d73..344fba4416 100644 --- a/pkg/api/handlers/libpod/kube.go +++ b/pkg/api/handlers/libpod/kube.go @@ -109,6 +109,7 @@ func KubePlay(w http.ResponseWriter, r *http.Request) { LogDriver string `schema:"logDriver"` LogOptions []string `schema:"logOptions"` Network []string `schema:"network"` + NoHostname bool `schema:"noHostname"` NoHosts bool `schema:"noHosts"` NoTrunc bool `schema:"noTrunc"` Replace bool `schema:"replace"` @@ -182,6 +183,7 @@ func KubePlay(w http.ResponseWriter, r *http.Request) { LogDriver: logDriver, LogOptions: query.LogOptions, Networks: query.Network, + NoHostname: query.NoHostname, NoHosts: query.NoHosts, Password: password, PublishPorts: query.PublishPorts, diff --git a/pkg/bindings/kube/types.go b/pkg/bindings/kube/types.go index 3a798df3f3..c2e86a2dda 100644 --- a/pkg/bindings/kube/types.go +++ b/pkg/bindings/kube/types.go @@ -20,6 +20,8 @@ type PlayOptions struct { Password *string // Network - name of the networks to connect to. Network *[]string + // NoHostname - do not generate /etc/hostname file in pod's containers + NoHostname *bool // NoHosts - do not generate /etc/hosts file in pod's containers NoHosts *bool // Quiet - suppress output when pulling images. diff --git a/pkg/bindings/kube/types_play_options.go b/pkg/bindings/kube/types_play_options.go index f9e160e141..e7c82eaf31 100644 --- a/pkg/bindings/kube/types_play_options.go +++ b/pkg/bindings/kube/types_play_options.go @@ -108,6 +108,21 @@ func (o *PlayOptions) GetNetwork() []string { return *o.Network } +// WithNoHostname set field NoHostname to given value +func (o *PlayOptions) WithNoHostname(value bool) *PlayOptions { + o.NoHostname = &value + return o +} + +// GetNoHostname returns value of field NoHostname +func (o *PlayOptions) GetNoHostname() bool { + if o.NoHostname == nil { + var z bool + return z + } + return *o.NoHostname +} + // WithNoHosts set field NoHosts to given value func (o *PlayOptions) WithNoHosts(value bool) *PlayOptions { o.NoHosts = &value diff --git a/pkg/domain/entities/play.go b/pkg/domain/entities/play.go index eaec3690be..0fa4f4a145 100644 --- a/pkg/domain/entities/play.go +++ b/pkg/domain/entities/play.go @@ -27,6 +27,9 @@ type PlayKubeOptions struct { ExitCodePropagation string // Replace indicates whether to delete and recreate a yaml file Replace bool + // Do not create /etc/hostname within the pod's containers, + // instead use the version from the image + NoHostname bool // Do not create /etc/hosts within the pod's containers, // instead use the version from the image NoHosts bool diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go index 2648b6716d..1ae81e87dd 100644 --- a/pkg/domain/entities/pods.go +++ b/pkg/domain/entities/pods.go @@ -367,6 +367,7 @@ func ToPodSpecGen(s specgen.PodSpecGenerator, p *PodCreateOptions) (*specgen.Pod s.DNSSearch = p.Net.DNSSearch s.DNSOption = p.Net.DNSOptions s.NoManageHosts = p.Net.NoHosts + s.NoManageHostname = p.Net.NoHostname s.HostAdd = p.Net.AddHosts s.HostsFile = p.Net.HostsFile } diff --git a/pkg/domain/entities/types.go b/pkg/domain/entities/types.go index 13e779ebad..89c921ebfe 100644 --- a/pkg/domain/entities/types.go +++ b/pkg/domain/entities/types.go @@ -40,6 +40,7 @@ type NetFlags struct { MacAddr string `json:"mac-address,omitempty"` Publish []string `json:"publish,omitempty"` IP string `json:"ip,omitempty"` + NoHostname bool `json:"no-hostname,omitempty"` NoHosts bool `json:"no-hosts,omitempty"` Network string `json:"network,omitempty"` NetworkAlias []string `json:"network-alias,omitempty"` @@ -57,6 +58,7 @@ type NetOptions struct { DNSServers []net.IP `json:"dns_server,omitempty"` HostsFile string `json:"hosts_file,omitempty"` Network specgen.Namespace `json:"netns,omitempty"` + NoHostname bool `json:"no_manage_hostname,omitempty"` NoHosts bool `json:"no_manage_hosts,omitempty"` PublishPorts []types.PortMapping `json:"portmappings,omitempty"` // NetworkOptions are additional options for each network diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 8319fd9ed1..2d9b780716 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -625,7 +625,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY podOpt := entities.PodCreateOptions{ Infra: true, - Net: &entities.NetOptions{NoHosts: options.NoHosts}, + Net: &entities.NetOptions{NoHosts: options.NoHosts, NoHostname: options.NoHostname}, ExitPolicy: string(config.PodExitPolicyStop), } podOpt, err = kube.ToPodOpt(ctx, podName, podOpt, options.PublishAllPorts, podYAML) diff --git a/pkg/domain/infra/tunnel/kube.go b/pkg/domain/infra/tunnel/kube.go index 6a863cff7e..319e7eb04a 100644 --- a/pkg/domain/infra/tunnel/kube.go +++ b/pkg/domain/infra/tunnel/kube.go @@ -65,7 +65,7 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, opts en if opts.Annotations != nil { options.WithAnnotations(opts.Annotations) } - options.WithNoHosts(opts.NoHosts).WithUserns(opts.Userns) + options.WithNoHostname(opts.NoHostname).WithNoHosts(opts.NoHosts).WithUserns(opts.Userns) if s := opts.SkipTLSVerify; s != types.OptionalBoolUndefined { options.WithSkipTLSVerify(s == types.OptionalBoolTrue) } diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index ef9aed24a8..c69512027a 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -495,6 +495,8 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, containerID specg.Networks = conf.Networks specg.ShmSize = &conf.ShmSize specg.ShmSizeSystemd = &conf.ShmSizeSystemd + specg.UseImageHostname = &conf.UseImageHostname + specg.UseImageHosts = &conf.UseImageHosts mapSecurityConfig(conf, specg) diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index 694a48347b..f02339319e 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -43,7 +43,7 @@ import ( ) func ToPodOpt(ctx context.Context, podName string, p entities.PodCreateOptions, publishAllPorts bool, podYAML *v1.PodTemplateSpec) (entities.PodCreateOptions, error) { - p.Net = &entities.NetOptions{NoHosts: p.Net.NoHosts} + p.Net = &entities.NetOptions{NoHosts: p.Net.NoHosts, NoHostname: p.Net.NoHostname} p.Name = podName p.Labels = podYAML.ObjectMeta.Labels diff --git a/pkg/specgen/generate/namespaces.go b/pkg/specgen/generate/namespaces.go index 5b0e90415e..6b1467f659 100644 --- a/pkg/specgen/generate/namespaces.go +++ b/pkg/specgen/generate/namespaces.go @@ -366,6 +366,9 @@ func namespaceOptions(s *specgen.SpecGenerator, rt *libpod.Runtime, pod *libpod. } else if len(s.HostAdd) > 0 { toReturn = append(toReturn, libpod.WithHosts(s.HostAdd)) } + if s.UseImageHostname != nil && *s.UseImageHostname { + toReturn = append(toReturn, libpod.WithUseImageHostname()) + } if len(s.DNSSearch) > 0 { toReturn = append(toReturn, libpod.WithDNSSearch(s.DNSSearch)) } diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go index 186aba746b..d835e15d7a 100644 --- a/pkg/specgen/generate/pod_create.go +++ b/pkg/specgen/generate/pod_create.go @@ -272,6 +272,9 @@ func MapSpec(p *specgen.PodSpecGenerator) (*specgen.SpecGenerator, error) { if p.NoManageHosts { spec.UseImageHosts = &p.NoManageHosts } + if p.NoManageHostname { + spec.UseImageHostname = &p.NoManageHostname + } if len(p.InfraConmonPidFile) > 0 { spec.ConmonPidFile = p.InfraConmonPidFile diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go index 7f22ed7ad5..9aef3ea5a6 100644 --- a/pkg/specgen/podspecgen.go +++ b/pkg/specgen/podspecgen.go @@ -159,6 +159,10 @@ type PodNetworkConfig struct { // Conflicts with NoInfra=true. // Optional. DNSOption []string `json:"dns_option,omitempty"` + // NoManageHostname indicates that /etc/hostname should not be managed + // by the pod. Instead, each container will create a separate + // /etc/hostname as they would if not in a pod. + NoManageHostname bool `json:"no_manage_hostname,omitempty"` // NoManageHosts indicates that /etc/hosts should not be managed by the // pod. Instead, each container will create a separate /etc/hosts as // they would if not in a pod. diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index 7bb5bc4a86..c5ba5fe17f 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -534,6 +534,10 @@ type ContainerNetworkConfig struct { // Conflicts with UseImageResolvConf. // Optional. DNSOptions []string `json:"dns_option,omitempty"` + // UseImageHostname indicates that /etc/hostname should not be managed by + // Podman, and instead sourced from the image. + // Optional. + UseImageHostname *bool `json:"use_image_hostname,omitempty"` // UseImageHosts indicates that /etc/hosts should not be managed by // Podman, and instead sourced from the image. // Conflicts with HostAdd. diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go index 74ad6829b9..6ab70b1cc3 100644 --- a/pkg/specgenutil/specgen.go +++ b/pkg/specgenutil/specgen.go @@ -593,6 +593,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions s.DNSSearch = c.Net.DNSSearch s.DNSOptions = c.Net.DNSOptions s.NetworkOptions = c.Net.NetworkOptions + s.UseImageHostname = &c.Net.NoHostname s.UseImageHosts = &c.Net.NoHosts } if len(s.HostUsers) == 0 || len(c.HostUsers) != 0 { diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 31e715b416..cad12e4481 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -2384,26 +2384,37 @@ var _ = Describe("Podman kube play", func() { Expect(label).To(ContainSubstring("unconfined_u:system_r:spc_t:s0")) }) - It("--no-host", func() { + It("--no-hostname", func() { err := writeYaml(checkInfraImagePodYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--no-hosts", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--no-hostname", kubeYaml) + alpineHostname := podmanTest.PodmanExitCleanly("run", "--rm", "--no-hostname", ALPINE, "cat", "/etc/hostname") - podInspect := podmanTest.Podman([]string{"pod", "inspect", "check-infra-image"}) - podInspect.WaitWithDefaultTimeout() - Expect(podInspect).Should(ExitCleanly()) + podInspect := podmanTest.PodmanExitCleanly("pod", "inspect", "check-infra-image") + + data := podInspect.InspectPodToJSON() + for _, ctr := range data.Containers { + if strings.HasSuffix(ctr.Name, "-infra") { + continue + } + exec := podmanTest.PodmanExitCleanly("exec", ctr.ID, "cat", "/etc/hostname") + Expect(exec.OutputToString()).To(Equal(alpineHostname.OutputToString())) + } + }) + + It("--no-host", func() { + err := writeYaml(checkInfraImagePodYaml, kubeYaml) + Expect(err).ToNot(HaveOccurred()) + kube := podmanTest.PodmanExitCleanly("kube", "play", "--no-hosts", kubeYaml) + podInspect := podmanTest.PodmanExitCleanly("pod", "inspect", "check-infra-image") data := podInspect.InspectPodToJSON() for _, ctr := range data.Containers { if strings.HasSuffix(ctr.Name, "-infra") { continue } - exec := podmanTest.Podman([]string{"exec", ctr.ID, "cat", "/etc/hosts"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec := podmanTest.PodmanExitCleanly("exec", ctr.ID, "cat", "/etc/hosts") Expect(exec.OutputToString()).To(Not(ContainSubstring("check-infra-image"))) } }) diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go index 349994d203..4b0f814f93 100644 --- a/test/e2e/pod_create_test.go +++ b/test/e2e/pod_create_test.go @@ -123,6 +123,22 @@ var _ = Describe("Podman pod create", func() { Expect(podResolvConf.OutputToString()).To(Equal(alpineResolvConf.OutputToString())) }) + It("podman create pod with --no-hostname", func() { + name := "test" + podCreate := podmanTest.Podman([]string{"pod", "create", "--no-hostname", "--name", name}) + podCreate.WaitWithDefaultTimeout() + Expect(podCreate).Should(ExitCleanly()) + + alpineHostname := podmanTest.Podman([]string{"run", "--rm", "--no-hostname", ALPINE, "cat", "/etc/hostname"}) + alpineHostname.WaitWithDefaultTimeout() + Expect(alpineHostname).Should(ExitCleanly()) + + podHostname := podmanTest.Podman([]string{"run", "--pod", name, "--rm", ALPINE, "cat", "/etc/hostname"}) + podHostname.WaitWithDefaultTimeout() + Expect(podHostname).Should(ExitCleanly()) + Expect(podHostname.OutputToString()).To(Equal(alpineHostname.OutputToString())) + }) + It("podman create pod with --no-hosts and no infra should fail", func() { name := "test" podCreate := podmanTest.Podman([]string{"pod", "create", "--no-hosts", "--name", name, "--infra=false"}) diff --git a/test/system/030-run.bats b/test/system/030-run.bats index e40bd914df..99def8d069 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -1711,4 +1711,21 @@ search | $IMAGE | run_podman rm -f -t0 $cname } +# bats test_tags=ci:parallel +@test "podman run - no-hostname" { + randomname=c_$(safename) + echo "\ +from $IMAGE +RUN umount /etc/hostname; rm /etc/hostname +" > $PODMAN_TMPDIR/Containerfile + run_podman build -t $randomname --cap-add SYS_ADMIN ${PODMAN_TMPDIR} + + run_podman run --rm $randomname ls /etc/hostname + + run_podman 1 run --no-hostname --rm $randomname ls /etc/hostname + is "$output" "ls: /etc/hostname: No such file or directory" "container did not add /etc/hostname" + + run_podman rmi $randomname +} + # vim: filetype=sh From 6ad44fe179fe2d40e16a2bf94b944659e1267032 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 14 Jan 2025 16:48:01 -0500 Subject: [PATCH 2/2] Replace instances of PodmanExitCleanly in play_kube_test.go Signed-off-by: Daniel J Walsh --- test/e2e/play_kube_test.go | 1148 +++++++++--------------------------- 1 file changed, 266 insertions(+), 882 deletions(-) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index cad12e4481..a739618249 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -2407,7 +2407,7 @@ var _ = Describe("Podman kube play", func() { err := writeYaml(checkInfraImagePodYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.PodmanExitCleanly("kube", "play", "--no-hosts", kubeYaml) + podmanTest.PodmanExitCleanly("kube", "play", "--no-hosts", kubeYaml) podInspect := podmanTest.PodmanExitCleanly("pod", "inspect", "check-infra-image") data := podInspect.InspectPodToJSON() for _, ctr := range data.Containers { @@ -3989,18 +3989,11 @@ VOLUME %s`, CITEST_IMAGE, hostPathDir+"/") err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - cmData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) - cmData.WaitWithDefaultTimeout() - Expect(cmData).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + cmData := podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/test/FOO") Expect(cmData.OutputToString()).To(Equal("foobar")) - inspect := podmanTest.Podman([]string{"volume", "inspect", volumeName, "--format", "{{.Mountpoint}}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("volume", "inspect", volumeName, "--format", "{{.Mountpoint}}") Expect(inspect.OutputToStringArray()).To(HaveLen(1)) path := inspect.OutputToString() @@ -4041,18 +4034,11 @@ spec: err := writeYaml(cmYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - cmData := podmanTest.Podman([]string{"exec", "youthfulshaw-pod-youthfulshaw", "cat", "/test/foo"}) - cmData.WaitWithDefaultTimeout() - Expect(cmData).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + cmData := podmanTest.PodmanExitCleanly("exec", "youthfulshaw-pod-youthfulshaw", "cat", "/test/foo") Expect(cmData.OutputToString()).To(Equal("bar")) - inspect := podmanTest.Podman([]string{"volume", "inspect", "example-configmap", "--format", "{{.Mountpoint}}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("volume", "inspect", "example-configmap", "--format", "{{.Mountpoint}}") Expect(inspect.OutputToStringArray()).To(HaveLen(1)) path := inspect.OutputToString() @@ -4072,30 +4058,15 @@ spec: err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - emptyDirCheck1 := podmanTest.Podman([]string{"exec", podName + "-" + ctrName1, "ls", "/test-emptydir"}) - emptyDirCheck1.WaitWithDefaultTimeout() - Expect(emptyDirCheck1).Should(ExitCleanly()) - - emptyDirCheck2 := podmanTest.Podman([]string{"exec", podName + "-" + ctrName2, "ls", "/test-emptydir-2"}) - emptyDirCheck2.WaitWithDefaultTimeout() - Expect(emptyDirCheck2).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("exec", podName+"-"+ctrName1, "ls", "/test-emptydir") + podmanTest.PodmanExitCleanly("exec", podName+"-"+ctrName2, "ls", "/test-emptydir-2") - volList1 := podmanTest.Podman([]string{"volume", "ls", "-q"}) - volList1.WaitWithDefaultTimeout() - Expect(volList1).Should(ExitCleanly()) + volList1 := podmanTest.PodmanExitCleanly("volume", "ls", "-q") Expect(volList1.OutputToString()).To(Equal(defaultVolName)) - remove := podmanTest.Podman([]string{"pod", "rm", "-f", podName}) - remove.WaitWithDefaultTimeout() - Expect(remove).Should(ExitCleanly()) - - volList2 := podmanTest.Podman([]string{"volume", "ls", "-q"}) - volList2.WaitWithDefaultTimeout() - Expect(volList2).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("pod", "rm", "-f", podName) + volList2 := podmanTest.PodmanExitCleanly("volume", "ls", "-q") Expect(volList2.OutputToString()).To(Equal("")) }) @@ -4121,9 +4092,7 @@ spec: correctLabels := expectedLabelKey + ":" + expectedLabelValue pod := getPodNameInDeployment(deployment) - inspect := podmanTest.Podman([]string{"pod", "inspect", pod.Name, "--format", "'{{ .Labels }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("pod", "inspect", pod.Name, "--format", "'{{ .Labels }}'") Expect(inspect.OutputToString()).To(ContainSubstring(correctLabels)) }) @@ -4163,13 +4132,11 @@ spec: } pod := getPodNameInDeployment(deployment) - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&pod), "--format", ` + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(&pod), "--format", ` CpuPeriod: {{ .HostConfig.CpuPeriod }} CpuQuota: {{ .HostConfig.CpuQuota }} Memory: {{ .HostConfig.Memory }} -MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) +MemoryReservation: {{ .HostConfig.MemoryReservation }}`) Expect(inspect.OutputToString()).To(ContainSubstring(fmt.Sprintf("%s: %d", "CpuQuota", expectedCPUQuota))) Expect(inspect.OutputToString()).To(ContainSubstring("MemoryReservation: " + expectedMemoryRequest)) Expect(inspect.OutputToString()).To(ContainSubstring("Memory: " + expectedMemoryLimit)) @@ -4192,15 +4159,9 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err := generateKubeYaml("deployment", deployment, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) pod := getPodNameInDeployment(deployment) - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&pod), "--format", `{{ .HostConfig.CpuPeriod }}:{{ .HostConfig.CpuQuota }}`}) - - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(&pod), "--format", `{{ .HostConfig.CpuPeriod }}:{{ .HostConfig.CpuQuota }}`) parts := strings.Split(strings.Trim(inspect.OutputToString(), "\n"), ":") Expect(parts).To(HaveLen(2)) @@ -4233,18 +4194,12 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--log-opt=max-size=10k", "--log-driver", "journald", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--log-opt=max-size=10k", "--log-driver", "journald", kubeYaml) cid := getCtrNameInPod(pod) - inspect := podmanTest.Podman([]string{"inspect", cid, "--format", "'{{ .HostConfig.LogConfig.Type }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", cid, "--format", "'{{ .HostConfig.LogConfig.Type }}'") Expect(inspect.OutputToString()).To(ContainSubstring("journald")) - inspect = podmanTest.Podman([]string{"container", "inspect", "--format", "{{.HostConfig.LogConfig.Size}}", cid}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitCleanly()) + inspect = podmanTest.PodmanExitCleanly("container", "inspect", "--format", "{{.HostConfig.LogConfig.Size}}", cid) Expect(inspect.OutputToString()).To(Equal("10kB")) }) @@ -4253,13 +4208,8 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--start=false", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "{{ .State.Running }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--start=false", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "{{ .State.Running }}") Expect(inspect.OutputToString()).To(Equal("false")) }) @@ -4268,13 +4218,8 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", pod.Name, "--format", "{{ .InfraConfig.HostNetwork }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", pod.Name, "--format", "{{ .InfraConfig.HostNetwork }}") Expect(inspect.OutputToString()).To(Equal("true")) ns := SystemExec("readlink", []string{"/proc/self/ns/net"}) @@ -4283,9 +4228,7 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) netns := ns.OutputToString() Expect(netns).ToNot(BeEmpty()) - logs := podmanTest.Podman([]string{"logs", getCtrNameInPod(pod)}) - logs.WaitWithDefaultTimeout() - Expect(logs).Should(ExitCleanly()) + logs := podmanTest.PodmanExitCleanly("logs", getCtrNameInPod(pod)) Expect(logs.OutputToString()).To(Equal(netns)) }) @@ -4294,13 +4237,8 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", pod.Name, "--format", "{{ .InfraConfig.Networks }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", pod.Name, "--format", "{{ .InfraConfig.Networks }}") Expect(inspect.OutputToString()).To(Equal("[podman-default-kube-network]")) }) @@ -4317,17 +4255,12 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", volName, "--format", ` + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", volName, "--format", ` Name: {{ .Name }} Device: {{ .Options.device }} Type: {{ .Options.type }} -o: {{ .Options.o }}`}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) +o: {{ .Options.o }}`) Expect(inspect.OutputToString()).To(ContainSubstring("Name: " + volName)) Expect(inspect.OutputToString()).To(ContainSubstring("Device: " + volDevice)) Expect(inspect.OutputToString()).To(ContainSubstring("Type: " + volType)) @@ -4356,13 +4289,11 @@ o: {{ .Options.o }}`}) } Expect(kube).Should(ExitCleanly()) - inspect := podmanTest.Podman([]string{"inspect", volName, "--format", ` + inspect := podmanTest.PodmanExitCleanly("inspect", volName, "--format", ` { "Name": "{{ .Name }}", "Mountpoint": "{{ .Mountpoint }}" -}`}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) +}`) mp := make(map[string]string) err = json.Unmarshal([]byte(inspect.OutputToString()), &mp) Expect(err).ToNot(HaveOccurred()) @@ -4383,18 +4314,13 @@ o: {{ .Options.o }}`}) err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", volName, "--format", ` + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", volName, "--format", ` { "Name": "{{ .Name }}", "Driver": "{{ .Driver }}", "Image": "{{ .Options.image }}" -}`}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) +}`) mp := make(map[string]string) err = json.Unmarshal([]byte(inspect.OutputToString()), &mp) Expect(err).ToNot(HaveOccurred()) @@ -4450,23 +4376,14 @@ spec: err = generateMultiDocKubeYaml(yamlDocs, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspectVolume := podmanTest.Podman([]string{"inspect", volName, "--format", "'{{ .Name }}'"}) - inspectVolume.WaitWithDefaultTimeout() - Expect(inspectVolume).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspectVolume := podmanTest.PodmanExitCleanly("inspect", volName, "--format", "'{{ .Name }}'") Expect(inspectVolume.OutputToString()).To(ContainSubstring(volName)) - inspectPod := podmanTest.Podman([]string{"inspect", podName + "-pod", "--format", "'{{ .State }}'"}) - inspectPod.WaitWithDefaultTimeout() - Expect(inspectPod).Should(ExitCleanly()) + inspectPod := podmanTest.PodmanExitCleanly("inspect", podName+"-pod", "--format", "'{{ .State }}'") Expect(inspectPod.OutputToString()).To(ContainSubstring(`Running`)) - inspectMounts := podmanTest.Podman([]string{"inspect", podName + "-pod-" + ctrName, "--format", "{{ (index .Mounts 0).Type }}:{{ (index .Mounts 0).Name }}"}) - inspectMounts.WaitWithDefaultTimeout() - Expect(inspectMounts).Should(ExitCleanly()) + inspectMounts := podmanTest.PodmanExitCleanly("inspect", podName+"-pod-"+ctrName, "--format", "{{ (index .Mounts 0).Type }}:{{ (index .Mounts 0).Name }}") correct := fmt.Sprintf("volume:%s", volName) Expect(inspectMounts.OutputToString()).To(Equal(correct)) @@ -4522,14 +4439,9 @@ spec: err = generateMultiDocKubeYaml(yamlDocs, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) for _, n := range podNames { - inspect := podmanTest.Podman([]string{"inspect", n, "--format", "'{{ .State }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", n, "--format", "'{{ .State }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`Running`)) } }) @@ -4591,15 +4503,9 @@ invalid kube kind err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) for _, ctr := range []string{podName + "-" + ctr01Name, podName + "-" + ctr02Name} { - inspect := podmanTest.Podman([]string{"inspect", ctr, "--format", "'{{.Config.Labels}}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) - + inspect := podmanTest.PodmanExitCleanly("inspect", ctr, "--format", "'{{.Config.Labels}}'") Expect(inspect.OutputToString()).To(ContainSubstring(autoUpdateRegistry + ":" + autoUpdateRegistryValue)) Expect(inspect.OutputToString()).To(ContainSubstring(autoUpdateAuthfile + ":" + autoUpdateAuthfileValue)) } @@ -4627,20 +4533,14 @@ invalid kube kind err = generateKubeYaml("deployment", deployment, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) podName := getPodNameInDeployment(deployment).Name - inspect := podmanTest.Podman([]string{"inspect", podName + "-" + ctr01Name, "--format", "'{{.Config.Labels}}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", podName+"-"+ctr01Name, "--format", "'{{.Config.Labels}}'") Expect(inspect.OutputToString()).To(ContainSubstring(autoUpdateRegistry + ":" + autoUpdateRegistryValue)) - inspect = podmanTest.Podman([]string{"inspect", podName + "-" + ctr02Name, "--format", "'{{.Config.Labels}}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect = podmanTest.PodmanExitCleanly("inspect", podName+"-"+ctr02Name, "--format", "'{{.Config.Labels}}'") Expect(inspect.OutputToString()).NotTo(ContainSubstring(autoUpdateRegistry + ":" + autoUpdateRegistryValue)) }) @@ -4649,27 +4549,15 @@ invalid kube kind err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - ls := podmanTest.Podman([]string{"pod", "ps", "--format", "'{{.ID}}'"}) - ls.WaitWithDefaultTimeout() - Expect(ls).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + ls := podmanTest.PodmanExitCleanly("pod", "ps", "--format", "'{{.ID}}'") Expect(ls.OutputToStringArray()).To(HaveLen(1)) - teardown := podmanTest.Podman([]string{"kube", "play", "--down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--down", kubeYaml) // Removing a 2nd time to make sure no "no such error" is returned (see #19711) - teardown = podmanTest.Podman([]string{"kube", "play", "--down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--down", kubeYaml) - checkls := podmanTest.Podman([]string{"pod", "ps", "--format", "'{{.ID}}'"}) - checkls.WaitWithDefaultTimeout() - Expect(checkls).Should(ExitCleanly()) + checkls := podmanTest.PodmanExitCleanly("pod", "ps", "--format", "'{{.ID}}'") Expect(checkls.OutputToStringArray()).To(BeEmpty()) }) @@ -4677,28 +4565,16 @@ invalid kube kind err := writeYaml(secretYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - ls := podmanTest.Podman([]string{"secret", "ls", "--format", "{{.ID}}"}) - ls.WaitWithDefaultTimeout() - Expect(ls).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + ls := podmanTest.PodmanExitCleanly("secret", "ls", "--format", "{{.ID}}") Expect(ls.OutputToStringArray()).To(HaveLen(1)) - teardown := podmanTest.Podman([]string{"kube", "down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) + teardown := podmanTest.PodmanExitCleanly("kube", "down", kubeYaml) Expect(teardown.OutputToString()).Should(ContainSubstring(ls.OutputToString())) // Removing a 2nd time to make sure no "no such error" is returned (see #19711) - teardown = podmanTest.Podman([]string{"kube", "down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) - - checkls := podmanTest.Podman([]string{"secret", "ls", "--format", "'{{.ID}}'"}) - checkls.WaitWithDefaultTimeout() - Expect(checkls).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "down", kubeYaml) + checkls := podmanTest.PodmanExitCleanly("secret", "ls", "--format", "'{{.ID}}'") Expect(checkls.OutputToStringArray()).To(BeEmpty()) }) @@ -4706,9 +4582,7 @@ invalid kube kind err := writeYaml(simplePodYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - teardown := podmanTest.Podman([]string{"kube", "play", "--down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--down", kubeYaml) }) It("teardown volume --force", func() { @@ -4725,35 +4599,18 @@ invalid kube kind err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - exists := podmanTest.Podman([]string{"volume", "exists", volName}) - exists.WaitWithDefaultTimeout() - Expect(exists).To(ExitCleanly()) - - teardown := podmanTest.Podman([]string{"kube", "play", "--down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).To(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("volume", "exists", volName) + podmanTest.PodmanExitCleanly("kube", "play", "--down", kubeYaml) // volume should not be deleted on teardown without --force - exists = podmanTest.Podman([]string{"volume", "exists", volName}) - exists.WaitWithDefaultTimeout() - Expect(exists).To(ExitCleanly()) - + podmanTest.PodmanExitCleanly("volume", "exists", volName) // volume gets deleted with --force - teardown = podmanTest.Podman([]string{"kube", "play", "--down", "--force", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).To(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--down", "--force", kubeYaml) // Removing a 2nd should succeed as well even if no volume matches - teardown = podmanTest.Podman([]string{"kube", "play", "--down", "--force", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).To(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--down", "--force", kubeYaml) // volume should not be deleted on teardown - exists = podmanTest.Podman([]string{"volume", "exists", volName}) + exists := podmanTest.Podman([]string{"volume", "exists", volName}) exists.WaitWithDefaultTimeout() Expect(exists).To(ExitWithError(1, "")) }) @@ -4772,26 +4629,12 @@ invalid kube kind err = generateKubeYaml("persistentVolumeClaim", pvc, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - exists := podmanTest.Podman([]string{"volume", "exists", volName}) - exists.WaitWithDefaultTimeout() - Expect(exists).To(ExitCleanly()) - - teardown := podmanTest.Podman([]string{"kube", "play", "--down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).To(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("volume", "exists", volName) + podmanTest.PodmanExitCleanly("kube", "play", "--down", kubeYaml) // volume should not be deleted on teardown - exists = podmanTest.Podman([]string{"volume", "exists", volName}) - exists.WaitWithDefaultTimeout() - Expect(exists).To(ExitCleanly()) - - restart := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - restart.WaitWithDefaultTimeout() - Expect(restart).To(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "exists", volName) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) }) It("use network mode from config", func() { @@ -4806,18 +4649,11 @@ invalid kube kind err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - podInspect := podmanTest.Podman([]string{"pod", "inspect", pod.Name, "--format", "{{.InfraContainerID}}"}) - podInspect.WaitWithDefaultTimeout() - Expect(podInspect).To(ExitCleanly()) - infraID := podInspect.OutputToString() + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("pod", "inspect", pod.Name, "--format", "{{.InfraContainerID}}") + infraID := inspect.OutputToString() - inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.HostConfig.NetworkMode}}", infraID}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).To(ExitCleanly()) + inspect = podmanTest.PodmanExitCleanly("inspect", "--format", "{{.HostConfig.NetworkMode}}", infraID) Expect(inspect.OutputToString()).To(Equal("bridge")) }) @@ -4826,18 +4662,11 @@ invalid kube kind err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - ls := podmanTest.Podman([]string{"pod", "ps", "--format", "'{{.ID}}'"}) - ls.WaitWithDefaultTimeout() - Expect(ls).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + ls := podmanTest.PodmanExitCleanly("pod", "ps", "--format", "'{{.ID}}'") Expect(ls.OutputToStringArray()).To(HaveLen(1)) - containerLen := podmanTest.Podman([]string{"pod", "inspect", pod.Name, "--format", "{{len .Containers}}"}) - containerLen.WaitWithDefaultTimeout() - Expect(containerLen).Should(ExitCleanly()) + containerLen := podmanTest.PodmanExitCleanly("pod", "inspect", pod.Name, "--format", "{{len .Containers}}") Expect(containerLen.OutputToString()).To(Equal("2")) ctr01Name := "ctr01" ctr02Name := "ctr02" @@ -4852,13 +4681,8 @@ invalid kube kind err = generateKubeYaml("pod", newPod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - replace := podmanTest.Podman([]string{"kube", "play", "--replace", kubeYaml}) - replace.WaitWithDefaultTimeout() - Expect(replace).Should(ExitCleanly()) - - newContainerLen := podmanTest.Podman([]string{"pod", "inspect", newPod.Name, "--format", "{{len .Containers}}"}) - newContainerLen.WaitWithDefaultTimeout() - Expect(newContainerLen).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--replace", kubeYaml) + newContainerLen := podmanTest.PodmanExitCleanly("pod", "inspect", newPod.Name, "--format", "{{len .Containers}}") Expect(newContainerLen.OutputToString()).NotTo(Equal(containerLen.OutputToString())) }) @@ -4867,13 +4691,8 @@ invalid kube kind err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - replace := podmanTest.Podman([]string{"kube", "play", "--replace", kubeYaml}) - replace.WaitWithDefaultTimeout() - Expect(replace).Should(ExitCleanly()) - - ls := podmanTest.Podman([]string{"pod", "ps", "--format", "'{{.ID}}'"}) - ls.WaitWithDefaultTimeout() - Expect(ls).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--replace", kubeYaml) + ls := podmanTest.PodmanExitCleanly("pod", "ps", "--format", "'{{.ID}}'") Expect(ls.OutputToStringArray()).To(HaveLen(1)) }) @@ -4894,18 +4713,13 @@ invalid kube kind err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - cmd := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - cmd.WaitWithDefaultTimeout() - Expect(cmd).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // we expect the user:group as configured for the container - inspect := podmanTest.Podman([]string{"container", "inspect", "--format", "'{{.Config.User}}'", makeCtrNameInPod(pod, ctr1Name)}) - inspect.WaitWithDefaultTimeout() + inspect := podmanTest.PodmanExitCleanly("container", "inspect", "--format", "'{{.Config.User}}'", makeCtrNameInPod(pod, ctr1Name)) Expect(inspect.OutputToString()).To(Equal("'101:102'")) // we expect the user:group as configured for the pod - inspect = podmanTest.Podman([]string{"container", "inspect", "--format", "'{{.Config.User}}'", makeCtrNameInPod(pod, ctr2Name)}) - inspect.WaitWithDefaultTimeout() + inspect = podmanTest.PodmanExitCleanly("container", "inspect", "--format", "'{{.Config.User}}'", makeCtrNameInPod(pod, ctr2Name)) Expect(inspect.OutputToString()).To(Equal("'103:104'")) }) @@ -4935,14 +4749,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q pod := getPod(withCtr(ctnr)) Expect(generateKubeYaml("pod", pod, kubeYaml)).Should(Succeed()) - play := podmanTest.Podman([]string{"kube", "play", "--start", kubeYaml}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"container", "inspect", "--format=json", getCtrNameInPod(pod)}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--start", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("container", "inspect", "--format=json", getCtrNameInPod(pod)) contents := string(inspect.Out.Contents()) Expect(contents).To(ContainSubstring(javaToolOptions)) Expect(contents).To(ContainSubstring(openj9JavaOptions)) @@ -4965,13 +4773,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`)) }) @@ -5010,13 +4813,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ range .Config.Env }}[{{ . }}]{{end}}'") Expect(inspect.OutputToString()).To(Not(ContainSubstring(`[FOO=]`))) }) @@ -5034,13 +4832,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`FOO1=foo1`)) Expect(inspect.OutputToString()).To(ContainSubstring(`FOO2=foo2`)) }) @@ -5060,13 +4853,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", fmt.Sprintf("%s-%s-%s", deployment.Name, "pod", defaultCtrName), "--format", "'{{ .Config }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("inspect", fmt.Sprintf("%s-%s-%s", deployment.Name, "pod", defaultCtrName), "--format", "'{{ .Config }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`)) }) @@ -5102,9 +4890,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q _, err = play.Kube(podmanConnection, kubeYaml, nil) Expect(err).ToNot(HaveOccurred()) - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=foo`)) }) }) @@ -5133,13 +4919,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml, "--configmap", fsCmYamlPathname}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml, "--configmap", fsCmYamlPathname) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(And( ContainSubstring(`FOO=foo`), ContainSubstring(`FOO_FS=fooFS`), @@ -5174,13 +4955,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml, "--configmap", fsCmYamlPathname}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml, "--configmap", fsCmYamlPathname) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod), "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(And( ContainSubstring(`FOO_1=foo1`), ContainSubstring(`FOO_2=foo2`), @@ -5226,17 +5002,9 @@ ENV OPENJ9_JAVA_OPTIONS=%q err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml, "--log-driver", "journald", "--log-opt", "tag={{.ImageName}},withcomma"}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - start := podmanTest.Podman([]string{"start", getCtrNameInPod(pod)}) - start.WaitWithDefaultTimeout() - Expect(start).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)}) - inspect.WaitWithDefaultTimeout() - Expect(start).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml, "--log-driver", "journald", "--log-opt", "tag={{.ImageName}},withcomma") + podmanTest.PodmanExitCleanly("start", getCtrNameInPod(pod)) + inspect := podmanTest.PodmanExitCleanly("inspect", getCtrNameInPod(pod)) Expect((inspect.InspectContainerToJSON()[0]).HostConfig.LogConfig.Tag).To(Equal("{{.ImageName}},withcomma")) }) @@ -5270,33 +5038,21 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - usernsInCtr := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map"}) - usernsInCtr.WaitWithDefaultTimeout() - Expect(usernsInCtr).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + usernsInCtr := podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map") // the conversion to string is needed for better error messages Expect(string(usernsInCtr.Out.Contents())).To(Equal(string(initialUsernsConfig))) // -q necessary for ExitCleanly() because --replace pulls image - kube = podmanTest.Podman([]string{"kube", "play", "-q", "--replace", "--userns=auto", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map"}) - usernsInCtr.WaitWithDefaultTimeout() - Expect(usernsInCtr).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "-q", "--replace", "--userns=auto", kubeYaml) + usernsInCtr = podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map") Expect(string(usernsInCtr.Out.Contents())).To(Not(Equal(string(initialUsernsConfig)))) - kube = podmanTest.PodmanNoCache([]string{"kube", "play", "-q", "--replace", "--userns=keep-id", kubeYaml}) + kube := podmanTest.PodmanNoCache([]string{"kube", "play", "-q", "--replace", "--userns=keep-id", kubeYaml}) kube.WaitWithDefaultTimeout() Expect(kube).Should(ExitCleanly()) - usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "id", "-u"}) - usernsInCtr.WaitWithDefaultTimeout() - Expect(usernsInCtr).Should(ExitCleanly()) + usernsInCtr = podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "id", "-u") uid := strconv.Itoa(os.Geteuid()) Expect(string(usernsInCtr.Out.Contents())).To(ContainSubstring(uid)) @@ -5304,9 +5060,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q kube.WaitWithDefaultTimeout() Expect(kube).Should(ExitCleanly()) - usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "sh", "-c", "echo $(id -u):$(id -g)"}) - usernsInCtr.WaitWithDefaultTimeout() - Expect(usernsInCtr).Should(ExitCleanly()) + usernsInCtr = podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "sh", "-c", "echo $(id -u):$(id -g)") Expect(string(usernsInCtr.Out.Contents())).To(ContainSubstring("10:12")) // Now try with hostUsers in the pod spec @@ -5319,9 +5073,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q kube.WaitWithDefaultTimeout() Expect(kube).Should(ExitCleanly()) - usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map"}) - usernsInCtr.WaitWithDefaultTimeout() - Expect(usernsInCtr).Should(ExitCleanly()) + usernsInCtr = podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/proc/self/uid_map") if hostUsers { Expect(string(usernsInCtr.Out.Contents())).To(Equal(string(initialUsernsConfig))) } else { @@ -5352,20 +5104,13 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // Container should be in running state - inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.State.Status}}", "testPod-" + defaultCtrName}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", "--format", "{{.State.Status}}", "testPod-"+defaultCtrName) Expect(inspect.OutputToString()).To(ContainSubstring("running")) // Container should have a block device /dev/loop1 - inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.HostConfig.Devices}}", "testPod-" + defaultCtrName}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect = podmanTest.PodmanExitCleanly("inspect", "--format", "{{.HostConfig.Devices}}", "testPod-"+defaultCtrName) Expect(inspect.OutputToString()).To(ContainSubstring(devicePath)) }) @@ -5391,20 +5136,13 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // Container should be in running state - inspect := podmanTest.Podman([]string{"inspect", "--format", "{{.State.Status}}", "testPod-" + defaultCtrName}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", "--format", "{{.State.Status}}", "testPod-"+defaultCtrName) Expect(inspect.OutputToString()).To(ContainSubstring("running")) // Container should have a block device /dev/loop1 - inspect = podmanTest.Podman([]string{"inspect", "--format", "{{.HostConfig.Devices}}", "testPod-" + defaultCtrName}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect = podmanTest.PodmanExitCleanly("inspect", "--format", "{{.HostConfig.Devices}}", "testPod-"+defaultCtrName) Expect(inspect.OutputToString()).To(ContainSubstring(devicePath)) }) @@ -5486,42 +5224,28 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // do not remove newsecret to test that we auto remove on collision yamls = []string{secretYaml, complexSecretYaml} err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube = podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) err = writeYaml(secretPodYamlTwo, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube = podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + exec := podmanTest.PodmanExitCleanly("exec", "mypod2-myctr", "cat", "/etc/foo/username") - exec := podmanTest.Podman([]string{"exec", "mypod2-myctr", "cat", "/etc/foo/username"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) username, _ := base64.StdEncoding.DecodeString("dXNlcg==") Expect(exec.OutputToString()).Should(ContainSubstring(string(username))) - exec = podmanTest.Podman([]string{"exec", "mypod2-myctr", "cat", "/etc/bar/username"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec = podmanTest.PodmanExitCleanly("exec", "mypod2-myctr", "cat", "/etc/bar/username") username, _ = base64.StdEncoding.DecodeString("Y2RvZXJu") Expect(exec.OutputToString()).Should(ContainSubstring(string(username))) - exec = podmanTest.Podman([]string{"exec", "mypod2-myctr", "cat", "/etc/baz/plain_note"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec = podmanTest.PodmanExitCleanly("exec", "mypod2-myctr", "cat", "/etc/baz/plain_note") Expect(exec.OutputToString()).Should(ContainSubstring("This is a test")) }) @@ -5551,13 +5275,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - secretData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) - secretData.WaitWithDefaultTimeout() - Expect(secretData).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + secretData := podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/test/FOO") Expect(secretData.OutputToString()).To(Equal("testuser")) }) @@ -5579,13 +5298,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - secretData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/BAR"}) - secretData.WaitWithDefaultTimeout() - Expect(secretData).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + secretData := podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/test/BAR") Expect(secretData.OutputToString()).To(Equal("foobar")) secretData = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) @@ -5609,18 +5323,11 @@ ENV OPENJ9_JAVA_OPTIONS=%q err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - secretData := podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "cat", "/test/FOO"}) - secretData.WaitWithDefaultTimeout() - Expect(secretData).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + secretData := podmanTest.PodmanExitCleanly("exec", getCtrNameInPod(pod), "cat", "/test/FOO") Expect(secretData.OutputToString()).To(Equal("testuser")) - inspect := podmanTest.Podman([]string{"volume", "inspect", volumeName, "--format", "{{.Mountpoint}}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("volume", "inspect", volumeName, "--format", "{{.Mountpoint}}") Expect(inspect.OutputToStringArray()).To(HaveLen(1)) path := inspect.OutputToString() @@ -5662,13 +5369,8 @@ spec: err := writeYaml(secretYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"volume", "inspect", "newsecret", "--format", "{{.Mountpoint}}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + inspect := podmanTest.PodmanExitCleanly("volume", "inspect", "newsecret", "--format", "{{.Mountpoint}}") Expect(inspect.OutputToStringArray()).To(HaveLen(1)) path := inspect.OutputToString() @@ -5693,9 +5395,7 @@ cgroups="disabled"`), 0644) err = writeYaml(simplePodYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) }) It("podman kube --quiet with error", func() { @@ -5758,80 +5458,49 @@ spec: kube.WaitWithDefaultTimeout() Expect(kube).To(ExitWithError(125, "multi doc yaml could not be split: yaml: line 5: found character that cannot start any token")) - ps := podmanTest.Podman([]string{"pod", "ps", "-q"}) - ps.WaitWithDefaultTimeout() - Expect(ps).Should(ExitCleanly()) + ps := podmanTest.PodmanExitCleanly("pod", "ps", "-q") Expect(ps.OutputToStringArray()).To(BeEmpty()) }) It("with named volume subpaths", func() { SkipIfRemote("volume export does not exist on remote") - volumeCreate := podmanTest.Podman([]string{"volume", "create", "testvol1"}) - volumeCreate.WaitWithDefaultTimeout() - Expect(volumeCreate).Should(ExitCleanly()) - - session := podmanTest.Podman([]string{"run", "--volume", "testvol1:/data", CITEST_IMAGE, "sh", "-c", "mkdir -p /data/testing/onlythis && touch /data/testing/onlythis/123.txt && echo hi >> /data/testing/onlythis/123.txt"}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "create", "testvol1") + podmanTest.PodmanExitCleanly("run", "--volume", "testvol1:/data", CITEST_IMAGE, "sh", "-c", "mkdir -p /data/testing/onlythis && touch /data/testing/onlythis/123.txt && echo hi >> /data/testing/onlythis/123.txt") tar := filepath.Join(podmanTest.TempDir, "out.tar") - session = podmanTest.Podman([]string{"volume", "export", "--output", tar, "testvol1"}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "export", "--output", tar, "testvol1") - volumeCreate = podmanTest.Podman([]string{"volume", "create", "testvol"}) - volumeCreate.WaitWithDefaultTimeout() - Expect(volumeCreate).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "create", "testvol") - volumeImp := podmanTest.Podman([]string{"volume", "import", "testvol", filepath.Join(podmanTest.TempDir, "out.tar")}) - volumeImp.WaitWithDefaultTimeout() - Expect(volumeImp).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "import", "testvol", filepath.Join(podmanTest.TempDir, "out.tar")) err = writeYaml(subpathTestNamedVolume, kubeYaml) Expect(err).ToNot(HaveOccurred()) - playKube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - playKube.WaitWithDefaultTimeout() - Expect(playKube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) - exec := podmanTest.Podman([]string{"exec", "testpod-testctr", "cat", "/var/123.txt"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec := podmanTest.PodmanExitCleanly("exec", "testpod-testctr", "cat", "/var/123.txt") Expect(exec.OutputToString()).Should(Equal("hi")) - teardown := podmanTest.Podman([]string{"kube", "down", "--force", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) + teardown := podmanTest.PodmanExitCleanly("kube", "down", "--force", kubeYaml) Expect(teardown.OutputToString()).Should(ContainSubstring("testvol")) // kube down --force should remove volumes // specified in the manifest but not externally // created volumes, testvol1 in this case - checkVol := podmanTest.Podman([]string{"volume", "ls", "--format", "{{.Name}}"}) - checkVol.WaitWithDefaultTimeout() - Expect(checkVol).Should(ExitCleanly()) + checkVol := podmanTest.PodmanExitCleanly("volume", "ls", "--format", "{{.Name}}") Expect(checkVol.OutputToString()).To(Equal("testvol1")) }) It("with graceful shutdown", func() { - volumeCreate := podmanTest.Podman([]string{"volume", "create", "testvol"}) - volumeCreate.WaitWithDefaultTimeout() - Expect(volumeCreate).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("volume", "create", "testvol") err = writeYaml(signalTest, kubeYaml) Expect(err).ToNot(HaveOccurred()) - playKube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - playKube.WaitWithDefaultTimeout() - Expect(playKube).Should(ExitCleanly()) - - teardown := podmanTest.Podman([]string{"kube", "down", kubeYaml}) - teardown.WaitWithDefaultTimeout() - Expect(teardown).Should(ExitCleanly()) - - session := podmanTest.Podman([]string{"run", "--volume", "testvol:/testvol", CITEST_IMAGE, "sh", "-c", "cat /testvol/termfile"}) - session.WaitWithDefaultTimeout() + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("kube", "down", kubeYaml) + session := podmanTest.PodmanExitCleanly("run", "--volume", "testvol:/testvol", CITEST_IMAGE, "sh", "-c", "cat /testvol/termfile") Expect(session.OutputToString()).Should(ContainSubstring("TERMINATED")) }) @@ -5855,37 +5524,21 @@ spec: err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).To(Not(HaveOccurred())) - playKube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - playKube.WaitWithDefaultTimeout() - Expect(playKube).Should(ExitCleanly()) - exec := podmanTest.Podman([]string{"exec", "testpod-testctr", "ls", "/var"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + exec := podmanTest.PodmanExitCleanly("exec", "testpod-testctr", "ls", "/var") Expect(exec.OutputToString()).Should(ContainSubstring("123.txt")) }) It("with unsafe subpaths", func() { SkipIfRemote("volume export does not exist on remote") - volumeCreate := podmanTest.Podman([]string{"volume", "create", "testvol1"}) - volumeCreate.WaitWithDefaultTimeout() - Expect(volumeCreate).Should(ExitCleanly()) - - session := podmanTest.Podman([]string{"run", "--volume", "testvol1:/data", CITEST_IMAGE, "sh", "-c", "mkdir -p /data/testing && ln -s /etc /data/testing/onlythis"}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "create", "testvol1") + podmanTest.PodmanExitCleanly("run", "--volume", "testvol1:/data", CITEST_IMAGE, "sh", "-c", "mkdir -p /data/testing && ln -s /etc /data/testing/onlythis") tar := filepath.Join(podmanTest.TempDir, "out.tar") - session = podmanTest.Podman([]string{"volume", "export", "--output", tar, "testvol1"}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - volumeCreate = podmanTest.Podman([]string{"volume", "create", "testvol"}) - volumeCreate.WaitWithDefaultTimeout() - Expect(volumeCreate).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "export", "--output", tar, "testvol1") - volumeImp := podmanTest.Podman([]string{"volume", "import", "testvol", filepath.Join(podmanTest.TempDir, "out.tar")}) - volumeImp.WaitWithDefaultTimeout() - Expect(volumeImp).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("volume", "create", "testvol") + podmanTest.PodmanExitCleanly("volume", "import", "testvol", filepath.Join(podmanTest.TempDir, "out.tar")) err = writeYaml(subpathTestNamedVolume, kubeYaml) Expect(err).ToNot(HaveOccurred()) @@ -5936,9 +5589,7 @@ spec: kube.WaitWithDefaultTimeout() Expect(kube).Should(Exit(0), string(out)) - exec := podmanTest.Podman([]string{"exec", "testpod-testctr", "ls", "/etc/"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec := podmanTest.PodmanExitCleanly("exec", "testpod-testctr", "ls", "/etc/") Expect(exec.OutputToString()).ShouldNot(HaveLen(3)) Expect(exec.OutputToString()).Should(ContainSubstring("BAR")) // we want to check that we can mount a subpath but not replace the entire dir @@ -5948,10 +5599,7 @@ spec: err := writeYaml(publishPortsPodWithoutPorts, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) curlTest := podmanTest.Podman([]string{"run", "--network", "host", NGINX_IMAGE, "curl", "-s", "localhost:19000"}) curlTest.WaitWithDefaultTimeout() Expect(curlTest).Should(ExitWithError(7, "")) @@ -5961,10 +5609,7 @@ spec: err := writeYaml(publishPortsPodWithoutPorts, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19002:80", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19002:80", kubeYaml) testHTTPServer("19002", false, "podman rulez") }) @@ -5984,10 +5629,7 @@ spec: err := writeYaml(publishPortsPodWithContainerPort, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(Exit(0)) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) testHTTPServer("80", true, "connection refused") }) @@ -5996,10 +5638,7 @@ spec: err := writeYaml(publishPortsPodWithContainerPort, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish-all=true", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(Exit(0)) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish-all=true", kubeYaml) testHTTPServer("80", false, "podman rulez") }) }) @@ -6008,10 +5647,7 @@ spec: err := writeYaml(publishPortsPodWithContainerPort, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19003:80", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19003:80", kubeYaml) testHTTPServer("19003", false, "podman rulez") }) @@ -6019,10 +5655,7 @@ spec: err := writeYaml(publishPortsPodWithContainerHostPort, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19004:80", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19004:80", kubeYaml) testHTTPServer("19004", false, "podman rulez") }) @@ -6030,10 +5663,7 @@ spec: err := writeYaml(publishPortsPodWithContainerHostPort, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19005:80", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19005:80", kubeYaml) testHTTPServer("19001", true, "connection refused") testHTTPServer("19005", false, "podman rulez") }) @@ -6042,10 +5672,7 @@ spec: err := writeYaml(publishPortsPodWithoutPorts, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19006:80", "--publish", "19007:80", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19006:80", "--publish", "19007:80", kubeYaml) testHTTPServer("19006", false, "podman rulez") testHTTPServer("19007", false, "podman rulez") }) @@ -6054,10 +5681,7 @@ spec: err := writeYaml(publishPortsEchoWithHostPortUDP, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19010:19008/tcp", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19010:19008/tcp", kubeYaml) verifyPodPorts(podmanTest, "network-echo", "19008/tcp:[{0.0.0.0 19010}]", "19008/udp:[{0.0.0.0 19009}]") }) @@ -6065,9 +5689,7 @@ spec: err := writeYaml(publishPortsEchoWithHostPortTCP, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", "--publish", "19012:19008/udp", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", "--publish", "19012:19008/udp", kubeYaml) verifyPodPorts(podmanTest, "network-echo", "19008/tcp:[{0.0.0.0 19011}]", "19008/udp:[{0.0.0.0 19012}]") }) @@ -6094,18 +5716,11 @@ spec: err := writeYaml(podWithHostPIDDefined, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - logs := podmanTest.Podman([]string{"pod", "logs", "-c", "test-hostpid-testimage", "test-hostpid"}) - logs.WaitWithDefaultTimeout() - Expect(logs).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + logs := podmanTest.PodmanExitCleanly("pod", "logs", "-c", "test-hostpid-testimage", "test-hostpid") Expect(logs.OutputToString()).To(Not(Equal("1")), "PID should never be 1 because of host pidns") - inspect := podmanTest.Podman([]string{"inspect", "test-hostpid-testimage", "--format", "{{ .HostConfig.PidMode }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", "test-hostpid-testimage", "--format", "{{ .HostConfig.PidMode }}") Expect(inspect.OutputToString()).To(Equal("host")) }) @@ -6113,17 +5728,9 @@ spec: err := writeYaml(podWithHostIPCDefined, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - wait := podmanTest.Podman([]string{"wait", "test-hostipc-testimage"}) - wait.WaitWithDefaultTimeout() - Expect(wait).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", "test-hostipc-testimage", "--format", "{{ .HostConfig.IpcMode }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("wait", "test-hostipc-testimage") + inspect := podmanTest.PodmanExitCleanly("inspect", "test-hostipc-testimage", "--format", "{{ .HostConfig.IpcMode }}") Expect(inspect.OutputToString()).To(Equal("host")) cmd := exec.Command("ls", "-l", "/proc/self/ns/ipc") @@ -6132,9 +5739,7 @@ spec: fields := strings.Split(string(res), " ") hostIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n") - logs := podmanTest.Podman([]string{"pod", "logs", "-c", "test-hostipc-testimage", "test-hostipc"}) - logs.WaitWithDefaultTimeout() - Expect(logs).Should(ExitCleanly()) + logs := podmanTest.PodmanExitCleanly("pod", "logs", "-c", "test-hostipc-testimage", "test-hostipc") fields = strings.Split(logs.OutputToString(), " ") ctrIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n") @@ -6144,26 +5749,14 @@ spec: It("with ctrName should be in network alias", func() { ctrName := "test-ctr" ctrNameInKubePod := ctrName + "-pod-" + ctrName - session1 := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, CITEST_IMAGE, "top"}) - session1.WaitWithDefaultTimeout() - Expect(session1).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("run", "-d", "--name", ctrName, CITEST_IMAGE, "top") outputFile := filepath.Join(podmanTest.RunRoot, "pod.yaml") - kube := podmanTest.Podman([]string{"kube", "generate", ctrName, "-f", outputFile}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - rm := podmanTest.Podman([]string{"pod", "rm", "-t", "0", "-f", ctrName}) - rm.WaitWithDefaultTimeout() - Expect(rm).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "generate", ctrName, "-f", outputFile) + podmanTest.PodmanExitCleanly("pod", "rm", "-t", "0", "-f", ctrName) - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", ctrNameInKubePod}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", ctrNameInKubePod) Expect(inspect.OutputToString()).To(ContainSubstring("\"Aliases\": [ \"" + ctrName + "\"")) }) @@ -6172,17 +5765,9 @@ spec: err := writeYaml(podWithSysctlDefined, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - wait := podmanTest.Podman([]string{"wait", "test-sysctl-testimage"}) - wait.WaitWithDefaultTimeout() - Expect(wait).Should(ExitCleanly()) - - logs := podmanTest.Podman([]string{"pod", "logs", "-c", "test-sysctl-testimage", "test-sysctl"}) - logs.WaitWithDefaultTimeout() - Expect(logs).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + podmanTest.PodmanExitCleanly("wait", "test-sysctl-testimage") + logs := podmanTest.PodmanExitCleanly("pod", "logs", "-c", "test-sysctl-testimage", "test-sysctl") Expect(logs.OutputToString()).To(ContainSubstring("kernel.msgmax = 65535")) Expect(logs.OutputToString()).To(ContainSubstring("net.core.somaxconn = 65535")) }) @@ -6216,9 +5801,7 @@ spec: err := generateKubeYaml("pod", pod, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) }) It("test pod with volumes-from annotation in yaml", func() { @@ -6231,37 +5814,19 @@ spec: err := os.MkdirAll(vol1, 0755) Expect(err).ToNot(HaveOccurred()) - session := podmanTest.Podman([]string{"create", "--name", ctr1, "-v", vol1, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"create", "--volumes-from", ctr1, "--name", ctr2, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "-f", outputFile, ctr2}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("create", "--name", ctr1, "-v", vol1, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("create", "--volumes-from", ctr1, "--name", ctr2, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "-f", outputFile, ctr2) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - inspectCtr2 := podmanTest.Podman([]string{"inspect", "-f", "'{{ .HostConfig.Binds }}'", ctrNameInKubePod}) - inspectCtr2.WaitWithDefaultTimeout() - Expect(inspectCtr2).Should(ExitCleanly()) + inspectCtr2 := podmanTest.PodmanExitCleanly("inspect", "-f", "'{{ .HostConfig.Binds }}'", ctrNameInKubePod) Expect(inspectCtr2.OutputToString()).To(ContainSubstring(":" + vol1 + ":rw")) - inspectCtr1 := podmanTest.Podman([]string{"inspect", "-f", "'{{ .HostConfig.Binds }}'", ctr1}) - inspectCtr1.WaitWithDefaultTimeout() - Expect(inspectCtr1).Should(ExitCleanly()) - + inspectCtr1 := podmanTest.PodmanExitCleanly("inspect", "-f", "'{{ .HostConfig.Binds }}'", ctr1) Expect(inspectCtr2.OutputToString()).To(Equal(inspectCtr1.OutputToString())) // see https://github.com/containers/podman/pull/19637, we should not see any warning/errors here - podrm := podmanTest.Podman([]string{"kube", "down", outputFile}) - podrm.WaitWithDefaultTimeout() - Expect(podrm).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "down", outputFile) }) It("test volumes-from annotation with source containers external", func() { @@ -6283,13 +5848,8 @@ spec: err2 := os.MkdirAll(vol2, 0755) Expect(err2).ToNot(HaveOccurred()) - session := podmanTest.Podman([]string{"create", "--name", srcctr1, "-v", vol1, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"create", "--name", srcctr2, "-v", vol2, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("create", "--name", srcctr1, "-v", vol1, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("create", "--name", srcctr2, "-v", vol2, CITEST_IMAGE) podName := tgtctr pod := getPod( @@ -6300,19 +5860,14 @@ spec: err3 := generateKubeYaml("pod", pod, kubeYaml) Expect(err3).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // Assert volumes are accessible inside the target container ctrNameInKubePod := podName + "-" + tgtctr inspect := podmanTest.InspectContainer(ctrNameInKubePod) Expect(inspect).To(HaveLen(1)) - exec := podmanTest.Podman([]string{"exec", ctrNameInKubePod, "ls", "-d", vol1, vol2}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec := podmanTest.PodmanExitCleanly("exec", ctrNameInKubePod, "ls", "-d", vol1, vol2) Expect(exec.OutputToString()).To(ContainSubstring(vol1)) Expect(exec.OutputToString()).To(ContainSubstring(vol2)) }) @@ -6331,9 +5886,7 @@ spec: err := writeYaml(volumesFromPodYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) inspect := podmanTest.InspectContainer(tgtctrInKubePod) Expect(inspect).To(HaveLen(1)) @@ -6343,18 +5896,11 @@ spec: // the target container. volFile := filepath.Join(vol, RandomString(10)+".txt") - exec := podmanTest.Podman([]string{"exec", srcctrInKubePod, "touch", volFile}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) - - exec = podmanTest.Podman([]string{"exec", srcctrInKubePod, "ls", volFile}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("exec", srcctrInKubePod, "touch", volFile) + exec := podmanTest.PodmanExitCleanly("exec", srcctrInKubePod, "ls", volFile) Expect(exec.OutputToString()).To(ContainSubstring(volFile)) - exec = podmanTest.Podman([]string{"exec", tgtctrInKubePod, "ls", volFile}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec = podmanTest.PodmanExitCleanly("exec", tgtctrInKubePod, "ls", volFile) Expect(exec.OutputToString()).To(ContainSubstring(volFile)) }) @@ -6376,22 +5922,12 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--rm", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("create", "--rm", "--name", ctr, CITEST_IMAGE) - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.AutoRemove }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("true")) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.AutoRemove }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("true")) }) It("test with reserved privileged annotation in yaml", func() { @@ -6399,22 +5935,11 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--privileged", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.Privileged }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("true")) + podmanTest.PodmanExitCleanly("create", "--privileged", "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.Privileged }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("true")) }) It("test with reserved init annotation in yaml", func() { @@ -6422,22 +5947,11 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--init", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .Path }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("/run/podman-init")) + podmanTest.PodmanExitCleanly("create", "--init", "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .Path }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("/run/podman-init")) }) It("test with reserved CIDFile annotation in yaml", func() { @@ -6446,22 +5960,11 @@ spec: outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") cidFile := filepath.Join(podmanTest.TempDir, RandomString(10)+".txt") - session := podmanTest.Podman([]string{"create", "--cidfile", cidFile, "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.ContainerIDFile }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal(cidFile)) + podmanTest.PodmanExitCleanly("create", "--cidfile", cidFile, "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.ContainerIDFile }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal(cidFile)) }) @@ -6470,22 +5973,11 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--security-opt", "seccomp=unconfined", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("[seccomp=unconfined]")) + podmanTest.PodmanExitCleanly("create", "--security-opt", "seccomp=unconfined", "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("[seccomp=unconfined]")) }) It("test with reserved Apparmor annotation in yaml", func() { @@ -6493,22 +5985,11 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--security-opt", "apparmor=unconfined", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("[apparmor=unconfined]")) + podmanTest.PodmanExitCleanly("create", "--security-opt", "apparmor=unconfined", "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("[apparmor=unconfined]")) }) It("test with reserved Label annotation in yaml", func() { @@ -6516,22 +5997,11 @@ spec: ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--security-opt", "label=level:s0", "--name", ctr, CITEST_IMAGE}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("[label=level:s0]")) + podmanTest.PodmanExitCleanly("create", "--security-opt", "label=level:s0", "--name", ctr, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.SecurityOpt }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("[label=level:s0]")) }) It("test with reserved PublishAll annotation in yaml", func() { @@ -6544,8 +6014,7 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) podmanTest.BuildImage(dockerfile, imageName, "false") // Verify that the buildah is just passing through the EXPOSE keys - inspect := podmanTest.Podman([]string{"inspect", imageName}) - inspect.WaitWithDefaultTimeout() + inspect := podmanTest.PodmanExitCleanly("inspect", imageName) image := inspect.InspectImageJSON() Expect(image).To(HaveLen(1)) Expect(image[0].Config.ExposedPorts).To(HaveLen(3)) @@ -6557,22 +6026,11 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) ctrNameInKubePod := ctr + "-pod-" + ctr outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - session := podmanTest.Podman([]string{"create", "--publish-all", "--name", ctr, imageName, "true"}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "generate", "--podman-only", "-f", outputFile, ctr}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - session = podmanTest.Podman([]string{"inspect", "-f", "{{ .HostConfig.PublishAllPorts }}", ctrNameInKubePod}) - session.WaitWithDefaultTimeout() - Expect(session).Should(ExitCleanly()) - Expect(session.OutputToString()).To(Equal("true")) + podmanTest.PodmanExitCleanly("create", "--publish-all", "--name", ctr, imageName, "true") + podmanTest.PodmanExitCleanly("kube", "generate", "--podman-only", "-f", outputFile, ctr) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect = podmanTest.PodmanExitCleanly("inspect", "-f", "{{ .HostConfig.PublishAllPorts }}", ctrNameInKubePod) + Expect(inspect.OutputToString()).To(Equal("true")) }) It("test with valid Umask value", func() { @@ -6581,26 +6039,13 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) ctrNameInPod := "ctr-pod-ctr" outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - create := podmanTest.Podman([]string{"create", "-t", "--restart", "never", "--name", ctrName, CITEST_IMAGE, "top"}) - create.WaitWithDefaultTimeout() - Expect(create).Should(ExitCleanly()) - - generate := podmanTest.Podman([]string{"kube", "generate", "-f", outputFile, ctrName}) - generate.WaitWithDefaultTimeout() - Expect(generate).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - exec := podmanTest.Podman([]string{"exec", ctrNameInPod, "/bin/sh", "-c", "umask"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("create", "-t", "--restart", "never", "--name", ctrName, CITEST_IMAGE, "top") + podmanTest.PodmanExitCleanly("kube", "generate", "-f", outputFile, ctrName) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + exec := podmanTest.PodmanExitCleanly("exec", ctrNameInPod, "/bin/sh", "-c", "umask") Expect(exec.OutputToString()).To(Equal(defaultUmask)) - inspect := podmanTest.Podman([]string{"inspect", ctrNameInPod, "-f", "{{ .Config.Umask }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + inspect := podmanTest.PodmanExitCleanly("inspect", ctrNameInPod, "-f", "{{ .Config.Umask }}") Expect(inspect.OutputToString()).To(Equal(defaultUmask)) }) @@ -6609,34 +6054,18 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) infraName := "infra-ctr" podName := "mypod" outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - pod := podmanTest.Podman([]string{"pod", "create", "--infra-name", infraName, podName}) - pod.WaitWithDefaultTimeout() - Expect(pod).Should(ExitCleanly()) - - ctr := podmanTest.Podman([]string{"create", "--pod", podName, CITEST_IMAGE, "top"}) - ctr.WaitWithDefaultTimeout() - Expect(ctr).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("pod", "create", "--infra-name", infraName, podName) + podmanTest.PodmanExitCleanly("create", "--pod", podName, CITEST_IMAGE, "top") // Generate kube yaml and it should have the infra name annotation set - gen := podmanTest.Podman([]string{"kube", "generate", "-f", outputFile, podName}) - gen.WaitWithDefaultTimeout() - Expect(gen).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "generate", "-f", outputFile, podName) // Remove the pod so it can be recreated via kube play - rm := podmanTest.Podman([]string{"pod", "rm", "-f", podName}) - rm.WaitWithDefaultTimeout() - Expect(rm).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "play", outputFile}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - + podmanTest.PodmanExitCleanly("pod", "rm", "-f", podName) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) // Expect the number of containers created to be 2, infra, and regular container numOfCtrs := podmanTest.NumberOfContainers() Expect(numOfCtrs).To(Equal(2)) - ps := podmanTest.Podman([]string{"ps", "--format", "{{.Names}}"}) - ps.WaitWithDefaultTimeout() - Expect(ps).Should(ExitCleanly()) + ps := podmanTest.PodmanExitCleanly("ps", "--format", "{{.Names}}") Expect(ps.OutputToString()).To(ContainSubstring(infraName)) }) @@ -6644,39 +6073,23 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) It("test with default infra name", func() { podName := "mypod" outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - pod := podmanTest.Podman([]string{"pod", "create", podName}) - pod.WaitWithDefaultTimeout() - Expect(pod).Should(ExitCleanly()) - - ctr := podmanTest.Podman([]string{"create", "--pod", podName, CITEST_IMAGE, "top"}) - ctr.WaitWithDefaultTimeout() - Expect(ctr).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("pod", "create", podName) + podmanTest.PodmanExitCleanly("create", "--pod", podName, CITEST_IMAGE, "top") // Generate kube yaml and it should have the infra name annotation set - gen := podmanTest.Podman([]string{"kube", "generate", "-f", outputFile, podName}) - gen.WaitWithDefaultTimeout() - Expect(gen).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "generate", "-f", outputFile, podName) // Remove the pod so it can be recreated via kube play - rm := podmanTest.Podman([]string{"pod", "rm", "-f", podName}) - rm.WaitWithDefaultTimeout() - Expect(rm).Should(ExitCleanly()) - - kube := podmanTest.Podman([]string{"kube", "play", outputFile}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("pod", "rm", "-f", podName) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) // Expect the number of containers created to be 2, infra, and regular container numOfCtrs := podmanTest.NumberOfContainers() Expect(numOfCtrs).To(Equal(2)) - podPs := podmanTest.Podman([]string{"pod", "ps", "-q"}) - podPs.WaitWithDefaultTimeout() - Expect(podPs).Should(ExitCleanly()) + podPs := podmanTest.PodmanExitCleanly("pod", "ps", "-q") podID := podPs.OutputToString() - ps := podmanTest.Podman([]string{"ps", "--format", "{{.Names}}"}) - ps.WaitWithDefaultTimeout() - Expect(ps).Should(ExitCleanly()) + ps := podmanTest.PodmanExitCleanly("ps", "--format", "{{.Names}}") Expect(ps.OutputToString()).To(ContainSubstring(podID[:12] + "-infra")) }) @@ -6685,13 +6098,8 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) err = writeYaml(listPodAndConfigMap, listYamlPathname) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", listYamlPathname}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", "test-list-pod-container", "--format", "'{{ .Config.Env }}'"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", listYamlPathname) + inspect := podmanTest.PodmanExitCleanly("inspect", "test-list-pod-container", "--format", "'{{ .Config.Env }}'") Expect(inspect.OutputToString()).To(ContainSubstring(`FOO=bar`)) }) @@ -6700,21 +6108,10 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE) ctrNameInPod := "ctr-pod-ctr" outputFile := filepath.Join(podmanTest.TempDir, "pod.yaml") - create := podmanTest.Podman([]string{"create", "--restart", "never", "--stop-timeout", "20", "--name", ctrName, CITEST_IMAGE}) - create.WaitWithDefaultTimeout() - Expect(create).Should(ExitCleanly()) - - generate := podmanTest.Podman([]string{"kube", "generate", "-f", outputFile, ctrName}) - generate.WaitWithDefaultTimeout() - Expect(generate).Should(ExitCleanly()) - - play := podmanTest.Podman([]string{"kube", "play", outputFile}) - play.WaitWithDefaultTimeout() - Expect(play).Should(ExitCleanly()) - - inspect := podmanTest.Podman([]string{"inspect", ctrNameInPod, "-f", "{{ .Config.StopTimeout }}"}) - inspect.WaitWithDefaultTimeout() - Expect(inspect).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("create", "--restart", "never", "--stop-timeout", "20", "--name", ctrName, CITEST_IMAGE) + podmanTest.PodmanExitCleanly("kube", "generate", "-f", outputFile, ctrName) + podmanTest.PodmanExitCleanly("kube", "play", outputFile) + inspect := podmanTest.PodmanExitCleanly("inspect", ctrNameInPod, "-f", "{{ .Config.StopTimeout }}") Expect(inspect.OutputToString()).To(Equal("20")) }) @@ -6737,26 +6134,20 @@ spec: err := writeYaml(netYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) // Get the name of the host hostname, err := os.Hostname() Expect(err).ToNot(HaveOccurred()) - exec := podmanTest.Podman([]string{"exec", "test-pod-alpine", "hostname"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec := podmanTest.PodmanExitCleanly("exec", "test-pod-alpine", "hostname") Expect(exec.OutputToString()).To(Equal(hostname)) // Check that the UTS namespace is set to host also hostUts := SystemExec("ls", []string{"-l", "/proc/self/ns/uts"}) Expect(hostUts).Should(ExitCleanly()) arr := strings.Split(hostUts.OutputToString(), " ") - exec = podmanTest.Podman([]string{"exec", "test-pod-alpine", "ls", "-l", "/proc/self/ns/uts"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec = podmanTest.PodmanExitCleanly("exec", "test-pod-alpine", "ls", "-l", "/proc/self/ns/uts") execArr := strings.Split(exec.OutputToString(), " ") Expect(execArr[len(execArr)-1]).To(ContainSubstring(arr[len(arr)-1])) }) @@ -6778,22 +6169,15 @@ spec: err := writeYaml(netYaml, kubeYaml) Expect(err).ToNot(HaveOccurred()) - kube := podmanTest.Podman([]string{"kube", "play", kubeYaml}) - kube.WaitWithDefaultTimeout() - Expect(kube).Should(ExitCleanly()) - - exec := podmanTest.Podman([]string{"exec", "test-pod-alpine", "hostname"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + podmanTest.PodmanExitCleanly("kube", "play", kubeYaml) + exec := podmanTest.PodmanExitCleanly("exec", "test-pod-alpine", "hostname") Expect(exec.OutputToString()).To(Equal("test-pod")) // Check that the UTS namespace is set to host also hostUts := SystemExec("ls", []string{"-l", "/proc/self/ns/uts"}) Expect(hostUts).Should(ExitCleanly()) arr := strings.Split(hostUts.OutputToString(), " ") - exec = podmanTest.Podman([]string{"exec", "test-pod-alpine", "ls", "-l", "/proc/self/ns/uts"}) - exec.WaitWithDefaultTimeout() - Expect(exec).Should(ExitCleanly()) + exec = podmanTest.PodmanExitCleanly("exec", "test-pod-alpine", "ls", "-l", "/proc/self/ns/uts") execArr := strings.Split(exec.OutputToString(), " ") Expect(execArr[len(execArr)-1]).To(Not(ContainSubstring(arr[len(arr)-1]))) })