Update system connection to add to farm

A new --farm flag is being added to podman system connection
add so that when a new connection is added it can be added to a new
or existing farm. Update the code here to be able to do that.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
Urvashi Mohnani 2023-07-26 10:06:38 -04:00
parent 42a36d1ba1
commit a489f0261c
3 changed files with 15 additions and 1 deletions

View File

@ -988,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() {

View File

@ -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()
}

View File

@ -24,6 +24,7 @@ type ConnectionCreateOptions struct {
Identity string
Socket string
Default bool
Farm string
}
type ConnectionDialOptions struct {