Skip to content

Commit

Permalink
Add machine table to containers.conf
Browse files Browse the repository at this point in the history
Add machine teable to configure podman machine options. Move
machine_image to the machine table, and add disk size to the machine
table.

Signed-off-by: Ashley Cui <acui@redhat.com>
  • Loading branch information
ashley-cui committed Sep 23, 2021
1 parent 458d21c commit 43a2fbe
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 29 deletions.
18 changes: 13 additions & 5 deletions docs/containers.conf.5.md
Expand Up @@ -446,11 +446,6 @@ Indicates if Podman is running inside a VM via Podman Machine.
Podman uses this value to do extra setup around networking from the
container inside the VM to to host.

**machine_image**="testing"

Default image used when creating a new VM using `podman machine init`.
Options: `testing`, `stable`, or a custom path or download URL to an image

**multi_image_archive**=false

Allows for creating archives (e.g., tarballs) with more than one image. Some container engines, such as Podman, interpret additional arguments as tags for one image and hence do not store more than one image. The default behavior can be altered with this option.
Expand Down Expand Up @@ -607,6 +602,19 @@ Currently valid values are:

The driver specific options object.

## MACHINE TABLE
The `machine` table contains configurations for podman machine VMs

**image**="testing"

Default image used when creating a new VM using `podman machine init`.
Options: `testing`, `stable`, `next`, or a custom path or download URL to an image

**disk_size**=10

The size of the disk in GB created when init-ing a podman-machine VM


# FILES

**containers.conf**
Expand Down
13 changes: 10 additions & 3 deletions pkg/config/config.go
Expand Up @@ -54,6 +54,8 @@ type Config struct {
Containers ContainersConfig `toml:"containers"`
// Engine specifies how the container engine based on Engine will run
Engine EngineConfig `toml:"engine"`
// Machine specifies configurations of podman machine VMs
Machine MachineConfig `toml:"machine"`
// Network section defines the configuration of CNI Plugins
Network NetworkConfig `toml:"network"`
// Secret section defines configurations for the secret management
Expand Down Expand Up @@ -281,9 +283,6 @@ type EngineConfig struct {
// MachineEnabled indicates if Podman is running in a podman-machine VM
MachineEnabled bool `toml:"machine_enabled,omitempty"`

// MachineImage is the image used when creating a podman-machine VM
MachineImage string `toml:"machine_image,omitempty"`

// MultiImageArchive - if true, the container engine allows for storing
// archives (e.g., of the docker-archive transport) with multiple
// images. By default, Podman creates single-image archives.
Expand Down Expand Up @@ -490,6 +489,14 @@ type SecretConfig struct {
Opts map[string]string `toml:"opts,omitempty"`
}

// MachineConfig represents the "machine" TOML config table
type MachineConfig struct {
// DiskSize is the size of the disk in GB created when init-ing a podman-machine VM
DiskSize uint64 `toml:"disk_size,omitempty"`
// MachineImage is the image used when init-ing a podman-machine VM
Image string `toml:"image,omitempty"`
}

// Destination represents destination for remote service
type Destination struct {
// URI, required. Example: ssh://root@example.com:22/run/podman/podman.sock
Expand Down
16 changes: 14 additions & 2 deletions pkg/config/config_local_test.go
Expand Up @@ -374,12 +374,24 @@ var _ = Describe("Config Local", func() {
// Given
config, err := NewConfig("")
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Engine.MachineImage).To(gomega.Equal("testing"))
gomega.Expect(config.Machine.Image).To(gomega.Equal("testing"))
// When
config2, err := NewConfig("testdata/containers_default.conf")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config2.Engine.MachineImage).To(gomega.Equal("stable"))
gomega.Expect(config2.Machine.Image).To(gomega.Equal("stable"))
})

It("Set machine disk", func() {
// Given
config, err := NewConfig("")
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Machine.DiskSize).To(gomega.Equal(uint64(10)))
// When
config2, err := NewConfig("testdata/containers_default.conf")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config2.Machine.DiskSize).To(gomega.Equal(uint64(20)))
})

})
16 changes: 10 additions & 6 deletions pkg/config/containers.conf
Expand Up @@ -396,10 +396,6 @@ default_sysctls = [
#
#machine_enabled = false

# The image used when creating a podman-machine VM.
#
#machine_image = "testing"

# MultiImageArchive - if true, the container engine allows for storing archives
# (e.g., of the docker-archive transport) with multiple images. By default,
# Podman creates single-image archives.
Expand Down Expand Up @@ -559,8 +555,16 @@ default_sysctls = [
[engine.volume_plugins]
#testplugin = "/run/podman/plugins/test.sock"

# The [engine.volume_plugins] table MUST be the last entry in this file.
[machine]
# The image used when creating a podman-machine VM.
#
#image = "testing"
#
# The size of the disk in GB created when init-ing a podman-machine VM
#disk_size=10

# The [machine] table MUST be the last entry in this file.
# (Unless another table is added)
# TOML does not provide a way to end a table other than a further table being
# defined, so every key hereafter will be part of [volume_plugins] and not the
# defined, so every key hereafter will be part of [machine] and not the
# main config.
17 changes: 9 additions & 8 deletions pkg/config/default.go
Expand Up @@ -208,6 +208,7 @@ func DefaultConfig() (*Config, error) {
},
Engine: *defaultEngineConfig,
Secrets: defaultSecretConfig(),
Machine: defaultMachineConfig(),
}, nil
}

Expand All @@ -219,6 +220,14 @@ func defaultSecretConfig() SecretConfig {
}
}

// defaultMachineConfig returns the default machine configuration.
func defaultMachineConfig() MachineConfig {
return MachineConfig{
Image: "testing",
DiskSize: 10,
}
}

// defaultConfigFromMemory returns a default engine configuration. Note that the
// config is different for root and rootless. It also parses the storage.conf.
func defaultConfigFromMemory() (*EngineConfig, error) {
Expand Down Expand Up @@ -345,8 +354,6 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
// constants.
c.LockType = "shm"
c.MachineEnabled = false
c.MachineImage = "testing"

c.ChownCopiedFiles = true

return c, nil
Expand Down Expand Up @@ -566,9 +573,3 @@ func (c *Config) MachineEnabled() bool {
func (c *Config) RootlessNetworking() string {
return c.Containers.RootlessNetworking
}

// MachineImage returns the image to be
// used when creating a podman-machine VM
func (c *Config) MachineImage() string {
return c.Engine.MachineImage
}
14 changes: 9 additions & 5 deletions pkg/config/testdata/containers_default.conf
Expand Up @@ -153,9 +153,6 @@ tmp_dir = "/run/libpod"

machine_enabled = true

# The image used when creating a podman-machine VM.
machine_image = "stable"

# Whether to use chroot instead of pivot_root in the runtime
no_pivot_root = false

Expand Down Expand Up @@ -246,8 +243,15 @@ crun = [
"/usr/local/bin/crun",
]

# The [engine.runtimes] table MUST be the last thing in this file.
[machine]
# The image used when creating a podman-machine VM.
image = "stable"

# The size of the disk in GB created when init-ing a podman-machine VM
disk_size = 20

# The [machine] table MUST be the last thing in this file.
# (Unless another table is added)
# TOML does not provide a way to end a table other than a further table being
# defined, so every key hereafter will be part of [runtimes] and not the main
# defined, so every key hereafter will be part of [machine] and not the main
# config.

0 comments on commit 43a2fbe

Please sign in to comment.