Skip to content

Commit 6821d97

Browse files
committed
Add Farms TOML table
Add two new fields Farms and DefaultFarm to the Config to be used by the new podman buildfarm command. Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
1 parent ff82985 commit 6821d97

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

docs/containers.conf.5.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,17 @@ Virtualization provider to be used for running a podman-machine VM. Empty value
848848
is interpreted as the default provider for the current host OS. On Linux/Mac
849849
default is `QEMU` and on Windows it is `WSL`.
850850

851+
## FARMS TABLE
852+
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`.
853+
854+
**default**=""
855+
856+
The default farm to use when farming out builds.
857+
858+
**[farms.list]**
859+
860+
Map of farms created where the key is the farm name and the value is the list of system connections.
861+
851862
# FILES
852863

853864
**containers.conf**

pkg/config/config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type Config struct {
7979
Secrets SecretConfig `toml:"secrets"`
8080
// ConfigMap section defines configurations for the configmaps management
8181
ConfigMaps ConfigMapConfig `toml:"configmaps"`
82+
// Farms defines configurations for the buildfarm farms
83+
Farms FarmConfig `toml:"farms"`
8284
}
8385

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

681+
// FarmConfig represents the "farm" TOML config tabls
682+
type FarmConfig struct {
683+
// Default is the default farm to be used when farming out builds
684+
Default string `toml:"default,omitempty"`
685+
// List is a map of farms created where key=farm-name and value=list of connections
686+
List map[string][]string `toml:"list,omitempty"`
687+
}
688+
679689
// Destination represents destination for remote service
680690
type Destination struct {
681691
// URI, required. Example: ssh://root@example.com:22/run/podman/podman.sock
@@ -1276,6 +1286,10 @@ func ReadCustomConfig() (*Config, error) {
12761286
return nil, err
12771287
}
12781288
}
1289+
// Let's always initialize the farm list so it is never nil
1290+
if newConfig.Farms.List == nil {
1291+
newConfig.Farms.List = make(map[string][]string)
1292+
}
12791293
return newConfig, nil
12801294
}
12811295

pkg/config/config_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,67 @@ image_copy_tmp_dir="storage"`
867867
})
868868
})
869869

870+
Describe("Farms", func() {
871+
ConfPath := struct {
872+
Value string
873+
IsSet bool
874+
}{}
875+
876+
BeforeEach(func() {
877+
ConfPath.Value, ConfPath.IsSet = os.LookupEnv("CONTAINERS_CONF")
878+
conf, _ := os.CreateTemp("", "containersconf")
879+
os.Setenv("CONTAINERS_CONF", conf.Name())
880+
})
881+
882+
AfterEach(func() {
883+
os.Remove(os.Getenv("CONTAINERS_CONF"))
884+
if ConfPath.IsSet {
885+
os.Setenv("CONTAINERS_CONF", ConfPath.Value)
886+
} else {
887+
os.Unsetenv("CONTAINERS_CONF")
888+
}
889+
})
890+
891+
It("succeed to set and read", func() {
892+
cfg, err := ReadCustomConfig()
893+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
894+
895+
cfg.Engine.ActiveService = "QA"
896+
cfg.Engine.ServiceDestinations = map[string]Destination{
897+
"QA": {
898+
URI: "https://qa/run/podman/podman.sock",
899+
Identity: "/.ssh/id_rsa",
900+
},
901+
}
902+
err = cfg.Write()
903+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
904+
905+
// test that connections were written correctly
906+
cfg, err = ReadCustomConfig()
907+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
908+
gomega.Expect(cfg.Engine.ActiveService, "QA")
909+
gomega.Expect(cfg.Engine.ServiceDestinations["QA"].URI,
910+
"https://qa/run/podman/podman.sock")
911+
gomega.Expect(cfg.Engine.ServiceDestinations["QA"].Identity,
912+
"/.ssh/id_rsa")
913+
914+
// Create farm
915+
cfg.Farms.Default = "Farm-1"
916+
cfg.Farms.List = map[string][]string{
917+
"Farm-1": {"QA"},
918+
}
919+
err = cfg.Write()
920+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
921+
922+
cfg, err = ReadCustomConfig()
923+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
924+
925+
gomega.Expect(cfg.Farms.Default, "Farm-1")
926+
gomega.Expect(cfg.Farms.List["Farm-1"],
927+
"QA")
928+
})
929+
})
930+
870931
Describe("Reload", func() {
871932
It("test new config from reload", func() {
872933
// Default configuration

pkg/config/containers.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,11 @@ default_sysctls = [
799799
# TOML does not provide a way to end a table other than a further table being
800800
# defined, so every key hereafter will be part of [machine] and not the
801801
# main config.
802+
803+
[farms]
804+
#
805+
# the default farm to use when farming out builds
806+
# default = ""
807+
#
808+
# map of existing farms
809+
#[farms.list]

pkg/config/containers.conf-freebsd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,11 @@ default_sysctls = [
661661
# TOML does not provide a way to end a table other than a further table being
662662
# defined, so every key hereafter will be part of [machine] and not the
663663
# main config.
664+
665+
[farms]
666+
#
667+
# the default farm to use when farming out builds
668+
# default = ""
669+
#
670+
# map of existing farms
671+
#[farms.list]

pkg/config/default.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func DefaultConfig() (*Config, error) {
235235
Engine: *defaultEngineConfig,
236236
Secrets: defaultSecretConfig(),
237237
Machine: defaultMachineConfig(),
238+
Farms: defaultFarmConfig(),
238239
}, nil
239240
}
240241

@@ -258,6 +259,14 @@ func defaultMachineConfig() MachineConfig {
258259
}
259260
}
260261

262+
// defaultFarmConfig returns the default farms configuration.
263+
func defaultFarmConfig() FarmConfig {
264+
emptyList := make(map[string][]string)
265+
return FarmConfig{
266+
List: emptyList,
267+
}
268+
}
269+
261270
// defaultConfigFromMemory returns a default engine configuration. Note that the
262271
// config is different for root and rootless. It also parses the storage.conf.
263272
func defaultConfigFromMemory() (*EngineConfig, error) {

0 commit comments

Comments
 (0)