Skip to content

Commit

Permalink
Merge pull request #1993 from grisu48/podmansh_sh
Browse files Browse the repository at this point in the history
Allow configuration of podmansh
  • Loading branch information
openshift-merge-bot[bot] committed May 22, 2024
2 parents a1de641 + e41e56f commit 1a97fd1
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 14 deletions.
23 changes: 19 additions & 4 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,6 @@ depend on the compression format used. For gzip, valid options are
1-9, with a default of 5. For zstd, valid options are 1-20, with a
default of 3.

**podmansh_timeout**=30

Number of seconds to wait for podmansh logins.

## SERVICE DESTINATION TABLE
The `engine.service_destinations` table contains configuration options used to set up remote connections to the podman service for the podman API.

Expand Down Expand Up @@ -974,6 +970,25 @@ The default farm to use when farming out builds.

Map of farms created where the key is the farm name and the value is the list of system connections.

## PODMANSH TABLE
The `podmansh` table contains configuration options used by podmansh.

**shell**="/bin/sh"

The shell to spawn in the container.
The default value is `/bin/sh`.

**container**="podmansh"

Name of the container that podmansh joins.
The default value is `podmansh`.

**timeout**=0

Number of seconds to wait for podmansh logins. This value if favoured over the deprecated field `engine.podmansh_timeout` if set.
The default value is 30.


# FILES

**containers.conf**
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type Config struct {
ConfigMaps ConfigMapConfig `toml:"configmaps"`
// Farms defines configurations for the buildfarm farms
Farms FarmConfig `toml:"farms"`
// Podmansh defined configurations for the podman shell
Podmansh PodmanshConfig `toml:"podmansh"`

loadedModules []string // only used at runtime to store which modules were loaded
}
Expand Down Expand Up @@ -543,6 +545,7 @@ type EngineConfig struct {
// PodmanshTimeout is the number of seconds to wait for podmansh logins.
// In other words, the timeout for the `podmansh` container to be in running
// state.
// Deprecated: Use podmansh.Timeout instead. podmansh.Timeout has precedence.
PodmanshTimeout uint `toml:"podmansh_timeout,omitempty,omitzero"`
}

Expand Down Expand Up @@ -695,6 +698,19 @@ type Destination struct {
IsMachine bool `json:",omitempty" toml:"is_machine,omitempty"`
}

// PodmanshConfig represents configuration for the podman shell
type PodmanshConfig struct {
// Shell to start in container, default: "/bin/sh"
Shell string `toml:"shell,omitempty"`
// Name of the container the podmansh user should join
Container string `toml:"container,omitempty"`

// Timeout is the number of seconds to wait for podmansh logins.
// In other words, the timeout for the `podmansh` container to be in running
// state.
Timeout uint `toml:"timeout,omitempty,omitzero"`
}

// Consumes container image's os and arch and returns if any dedicated runtime was
// configured otherwise returns default runtime.
func (c *EngineConfig) ImagePlatformToRuntime(os string, arch string) string {
Expand Down Expand Up @@ -1207,3 +1223,13 @@ func (c *Config) FindInitBinary() (string, error) {
}
return c.FindHelperBinary(defaultInitName, true)
}

// PodmanshTimeout returns the timeout in seconds for podmansh to connect to the container.
// Returns podmansh.Timeout if set, otherwise engine.PodmanshTimeout for backwards compatibility.
func (c *Config) PodmanshTimeout() uint {
// podmansh.Timeout has precedence, if set
if c.Podmansh.Timeout > 0 {
return c.Podmansh.Timeout
}
return c.Engine.PodmanshTimeout
}
35 changes: 34 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ var _ = Describe("Config", func() {
gomega.Expect(defaultConfig.Engine.DBBackend).To(gomega.Equal(""))
gomega.Expect(defaultConfig.Engine.PodmanshTimeout).To(gomega.BeEquivalentTo(30))
gomega.Expect(defaultConfig.Engine.AddCompression.Get()).To(gomega.BeEmpty())
gomega.Expect(defaultConfig.Podmansh.Container).To(gomega.Equal("podmansh"))
gomega.Expect(defaultConfig.Podmansh.Shell).To(gomega.Equal("/bin/sh"))
gomega.Expect(defaultConfig.Podmansh.Timeout).To(gomega.BeEquivalentTo(0))

path, err := defaultConfig.ImageCopyTmpDir()
gomega.Expect(err).ToNot(gomega.HaveOccurred())
Expand Down Expand Up @@ -131,6 +134,33 @@ var _ = Describe("Config", func() {
gomega.Expect(defaultConfig.Containers.EnableLabeling).To(gomega.Equal(selinux.GetEnabled()))
gomega.Expect(defaultConfig.Containers.EnableLabeledUsers).To(gomega.BeFalse())
})

It("Check podmansh timeout settings", func() {
// Note: Podmansh.Timeout must be preferred over Engine.PodmanshTimeout

// Given
defaultConfig, _ := NewConfig("")
// When
defaultConfig.Engine.PodmanshTimeout = 30
defaultConfig.Podmansh.Timeout = 0

// Then
gomega.Expect(defaultConfig.PodmanshTimeout()).To(gomega.Equal(uint(30)))

// When
defaultConfig.Engine.PodmanshTimeout = 0
defaultConfig.Podmansh.Timeout = 42

// Then
gomega.Expect(defaultConfig.PodmanshTimeout()).To(gomega.Equal(uint(42)))

// When
defaultConfig.Engine.PodmanshTimeout = 300
defaultConfig.Podmansh.Timeout = 42

// Then
gomega.Expect(defaultConfig.PodmanshTimeout()).To(gomega.Equal(uint(42)))
})
})

Describe("ValidateNetworkConfig", func() {
Expand Down Expand Up @@ -305,8 +335,11 @@ image_copy_tmp_dir="storage"`
gomega.Expect(defaultConfig.Engine.HelperBinariesDir.Get()).To(gomega.Equal(helperDirs))
gomega.Expect(defaultConfig.Engine.ServiceTimeout).To(gomega.BeEquivalentTo(300))
gomega.Expect(defaultConfig.Engine.InfraImage).To(gomega.BeEquivalentTo("k8s.gcr.io/pause:3.4.1"))
gomega.Expect(defaultConfig.Machine.Volumes.Get()).To(gomega.BeEquivalentTo(volumes))
gomega.Expect(defaultConfig.Engine.PodmanshTimeout).To(gomega.BeEquivalentTo(300))
gomega.Expect(defaultConfig.Machine.Volumes.Get()).To(gomega.BeEquivalentTo(volumes))
gomega.Expect(defaultConfig.Podmansh.Timeout).To(gomega.BeEquivalentTo(42))
gomega.Expect(defaultConfig.Podmansh.Shell).To(gomega.Equal("/bin/zsh"))
gomega.Expect(defaultConfig.Podmansh.Container).To(gomega.BeEquivalentTo("podmansh-1"))
gomega.Expect(defaultConfig.Engine.HealthcheckEvents).To(gomega.BeFalse())
newV, err := defaultConfig.MachineVolumes()
if newVolumes[0] == ":" {
Expand Down
14 changes: 11 additions & 3 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,6 @@ default_sysctls = [
# A value of 0 is treated as no timeout.
#volume_plugin_timeout = 5

# Default timeout in seconds for podmansh logins.
#podmansh_timeout = 30

# Paths to look for a valid OCI runtime (crun, runc, kata, runsc, krun, etc)
[engine.runtimes]
#crun = [
Expand Down Expand Up @@ -889,3 +886,14 @@ default_sysctls = [
#
# map of existing farms
#[farms.list]

[podmansh]
# Shell to spawn in container. Default: /bin/sh.
#shell = "/bin/sh"
#
# Name of the container the podmansh user should join.
#container = "podmansh"
#
# Default timeout in seconds for podmansh logins.
# Favored over the deprecated "podmansh_timeout" field.
#timeout = 30
23 changes: 18 additions & 5 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ func defaultConfig() (*Config, error) {
CNIPluginDirs: attributedstring.NewSlice(DefaultCNIPluginDirs),
NetavarkPluginDirs: attributedstring.NewSlice(DefaultNetavarkPluginDirs),
},
Engine: *defaultEngineConfig,
Secrets: defaultSecretConfig(),
Machine: defaultMachineConfig(),
Farms: defaultFarmConfig(),
Engine: *defaultEngineConfig,
Secrets: defaultSecretConfig(),
Machine: defaultMachineConfig(),
Farms: defaultFarmConfig(),
Podmansh: defaultPodmanshConfig(),
}, nil
}

Expand Down Expand Up @@ -307,6 +308,18 @@ func defaultFarmConfig() FarmConfig {
}
}

// defaultPodmanshConfig returns the default podmansh configuration.
func defaultPodmanshConfig() PodmanshConfig {
return PodmanshConfig{
Shell: "/bin/sh",
Container: "podmansh",

// A value of 0 means "not set", needed to distinguish if engine.podmansh_timeout or podmansh.timeout should be used
// This is needed to keep backwards compatibility to engine.PodmanshTimeout.
Timeout: uint(0),
}
}

// defaultEngineConfig returns a default engine configuration. Note that the
// config is different for root and rootless. It also parses the storage.conf.
func defaultEngineConfig() (*EngineConfig, error) {
Expand Down Expand Up @@ -360,7 +373,7 @@ func defaultEngineConfig() (*EngineConfig, error) {
c.CgroupManager = defaultCgroupManager()
c.ServiceTimeout = uint(5)
c.StopTimeout = uint(10)
c.PodmanshTimeout = uint(30)
c.PodmanshTimeout = uint(30) // deprecated: use podmansh.timeout instead, kept for backwards-compatibility
c.ExitCommandDelay = uint(5 * 60)
c.Remote = isRemote()
c.Retry = 3
Expand Down
10 changes: 9 additions & 1 deletion pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ runtime_supports_json = ["runc"]
# SSH config file path
ssh_config = "/foo/bar/.ssh/config"

# Number of seconds to wait for podmansh logins.
# Deprecated in favor of podmansh.Timeout, should not be used anymore.
podmansh_timeout = 300

# Paths to look for a valid OCI runtime (runc, runv, etc)
Expand All @@ -307,6 +307,14 @@ crun = [
"/usr/local/bin/crun",
]

[podmansh]
# Shell to start in container. Default: /bin/sh.
shell = "/bin/zsh"
# Name of the container the podmansh user should join.
container = "podmansh-1"
# Number of seconds to wait for podmansh logins.
timeout = 42

[machine]
# Number of CPU's a machine is created with.
cpus=1
Expand Down

1 comment on commit 1a97fd1

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.