Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Farms to config #1586

Merged
merged 2 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,17 @@ Virtualization provider to be used for running a podman-machine VM. Empty value
is interpreted as the default provider for the current host OS. On Linux/Mac
default is `QEMU` and on Windows it is `WSL`.

## FARMS TABLE
The `farms` table contains configuration options used to group up remote connections into farms that will be used when sending out builds to different machines in a farm via `podman buildfarm`.

**default**=""

The default farm to use when farming out builds.

**[farms.list]**

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

# FILES

**containers.conf**
Expand Down
14 changes: 14 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type Config struct {
Secrets SecretConfig `toml:"secrets"`
// ConfigMap section defines configurations for the configmaps management
ConfigMaps ConfigMapConfig `toml:"configmaps"`
// Farms defines configurations for the buildfarm farms
Farms FarmConfig `toml:"farms"`
}

// ContainersConfig represents the "containers" TOML config table
Expand Down Expand Up @@ -676,6 +678,14 @@ type MachineConfig struct {
Provider string `toml:"provider,omitempty"`
}

// FarmConfig represents the "farm" TOML config tabls
type FarmConfig struct {
// Default is the default farm to be used when farming out builds
Default string `toml:"default,omitempty"`
// List is a map of farms created where key=farm-name and value=list of connections
List map[string][]string `toml:"list,omitempty"`
}

// Destination represents destination for remote service
type Destination struct {
// URI, required. Example: ssh://root@example.com:22/run/podman/podman.sock
Expand Down Expand Up @@ -1276,6 +1286,10 @@ func ReadCustomConfig() (*Config, error) {
return nil, err
}
}
// Let's always initialize the farm list so it is never nil
if newConfig.Farms.List == nil {
newConfig.Farms.List = make(map[string][]string)
}
return newConfig, nil
}

Expand Down
63 changes: 62 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,67 @@ image_copy_tmp_dir="storage"`
})
})

Describe("Farms", func() {
ConfPath := struct {
Value string
IsSet bool
}{}

BeforeEach(func() {
ConfPath.Value, ConfPath.IsSet = os.LookupEnv("CONTAINERS_CONF")
conf, _ := os.CreateTemp("", "containersconf")
os.Setenv("CONTAINERS_CONF", conf.Name())
})

AfterEach(func() {
os.Remove(os.Getenv("CONTAINERS_CONF"))
if ConfPath.IsSet {
os.Setenv("CONTAINERS_CONF", ConfPath.Value)
} else {
os.Unsetenv("CONTAINERS_CONF")
}
})

It("succeed to set and read", func() {
cfg, err := ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg.Engine.ActiveService = "QA"
cfg.Engine.ServiceDestinations = map[string]Destination{
"QA": {
URI: "https://qa/run/podman/podman.sock",
Identity: "/.ssh/id_rsa",
},
}
err = cfg.Write()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

// test that connections were written correctly
cfg, err = ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(cfg.Engine.ActiveService, "QA")
gomega.Expect(cfg.Engine.ServiceDestinations["QA"].URI,
"https://qa/run/podman/podman.sock")
gomega.Expect(cfg.Engine.ServiceDestinations["QA"].Identity,
"/.ssh/id_rsa")

// Create farm
cfg.Farms.Default = "Farm-1"
cfg.Farms.List = map[string][]string{
"Farm-1": {"QA"},
}
err = cfg.Write()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

cfg, err = ReadCustomConfig()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

gomega.Expect(cfg.Farms.Default, "Farm-1")
gomega.Expect(cfg.Farms.List["Farm-1"],
"QA")
})
})

Describe("Reload", func() {
It("test new config from reload", func() {
// Default configuration
Expand Down Expand Up @@ -927,7 +988,7 @@ env=["foo=bar"]`
gomega.Expect(err).ToNot(gomega.HaveOccurred())
// config should only contain empty stanzas
gomega.Expect(string(b)).To(gomega.
Equal("[containers]\n\n[engine]\n\n[machine]\n\n[network]\n\n[secrets]\n\n[configmaps]\n"))
Equal("[containers]\n\n[engine]\n\n[machine]\n\n[network]\n\n[secrets]\n\n[configmaps]\n\n[farms]\n"))
})

It("validate ImageVolumeMode", func() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,11 @@ default_sysctls = [
# 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 [machine] and not the
# main config.

[farms]
umohnani8 marked this conversation as resolved.
Show resolved Hide resolved
#
# the default farm to use when farming out builds
# default = ""
#
# map of existing farms
#[farms.list]
8 changes: 8 additions & 0 deletions pkg/config/containers.conf-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -661,3 +661,11 @@ default_sysctls = [
# 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 [machine] and not the
# main config.

[farms]
#
# the default farm to use when farming out builds
# default = ""
#
# map of existing farms
#[farms.list]
9 changes: 9 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func DefaultConfig() (*Config, error) {
Engine: *defaultEngineConfig,
Secrets: defaultSecretConfig(),
Machine: defaultMachineConfig(),
Farms: defaultFarmConfig(),
}, nil
}

Expand All @@ -258,6 +259,14 @@ func defaultMachineConfig() MachineConfig {
}
}

// defaultFarmConfig returns the default farms configuration.
func defaultFarmConfig() FarmConfig {
emptyList := make(map[string][]string)
return FarmConfig{
List: emptyList,
}
}

// 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
13 changes: 13 additions & 0 deletions pkg/ssh/connection_golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ func golangConnectionCreate(options ConnectionCreateOptions) error {
} else {
cfg.Engine.ServiceDestinations[options.Name] = *dst
}

// Create or update an existing farm with the connection being added
if options.Farm != "" {
if len(cfg.Farms.List) == 0 {
cfg.Farms.Default = options.Farm
}
if val, ok := cfg.Farms.List[options.Farm]; ok {
cfg.Farms.List[options.Farm] = append(val, options.Name)
} else {
cfg.Farms.List[options.Farm] = []string{options.Name}
}
}

return cfg.Write()
}

Expand Down
1 change: 1 addition & 0 deletions pkg/ssh/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ConnectionCreateOptions struct {
Identity string
Socket string
Default bool
Farm string
}

type ConnectionDialOptions struct {
Expand Down