Skip to content

Commit

Permalink
Merge pull request #1586 from umohnani8/farms
Browse files Browse the repository at this point in the history
Add Farms to config
  • Loading branch information
openshift-merge-robot authored Aug 5, 2023
2 parents 793174c + 8cad687 commit c32d5da
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 1 deletion.
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://[email protected]:22/run/podman/podman.sock
Expand Down Expand Up @@ -1241,6 +1251,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 @@ -864,6 +864,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 @@ -924,7 +985,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 @@ -798,3 +798,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]
8 changes: 8 additions & 0 deletions pkg/config/containers.conf-freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -660,3 +660,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 @@ -234,6 +234,7 @@ func DefaultConfig() (*Config, error) {
Engine: *defaultEngineConfig,
Secrets: defaultSecretConfig(),
Machine: defaultMachineConfig(),
Farms: defaultFarmConfig(),
}, nil
}

Expand All @@ -257,6 +258,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

0 comments on commit c32d5da

Please sign in to comment.