diff --git a/pkg/types/defaults/installconfig.go b/pkg/types/defaults/installconfig.go index a249eed11e8..e36864903b3 100644 --- a/pkg/types/defaults/installconfig.go +++ b/pkg/types/defaults/installconfig.go @@ -9,6 +9,7 @@ import ( libvirtdefaults "github.com/openshift/installer/pkg/types/libvirt/defaults" nonedefaults "github.com/openshift/installer/pkg/types/none/defaults" openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults" + "k8s.io/utils/pointer" ) var ( @@ -43,23 +44,40 @@ func SetInstallConfigDefaults(c *types.InstallConfig) { }, } } + numberOfMasters := int64(3) + numberOfWorkers := int64(3) + if c.Platform.Libvirt != nil { + numberOfMasters = 1 + numberOfWorkers = 1 + } if len(c.Machines) == 0 { - numberOfMasters := int64(3) - numberOfWorkers := int64(3) - if c.Platform.Libvirt != nil { - numberOfMasters = 1 - numberOfWorkers = 1 - } c.Machines = []types.MachinePool{ { Name: "master", - Replicas: func(x int64) *int64 { return &x }(numberOfMasters), + Replicas: &numberOfMasters, }, { Name: "worker", - Replicas: func(x int64) *int64 { return &x }(numberOfWorkers), + Replicas: &numberOfWorkers, }, } + } else { + for i := range c.Machines { + switch c.Machines[i].Name { + case "master": + if c.Machines[i].Replicas == nil { + c.Machines[i].Replicas = &numberOfMasters + } + case "worker": + if c.Machines[i].Replicas == nil { + c.Machines[i].Replicas = &numberOfWorkers + } + default: + if c.Machines[i].Replicas == nil { + c.Machines[i].Replicas = pointer.Int64Ptr(0) + } + } + } } switch { case c.Platform.AWS != nil: diff --git a/pkg/types/defaults/installconfig_test.go b/pkg/types/defaults/installconfig_test.go index 2a4216cdd84..bfb1caeeb07 100644 --- a/pkg/types/defaults/installconfig_test.go +++ b/pkg/types/defaults/installconfig_test.go @@ -16,6 +16,7 @@ import ( nonedefaults "github.com/openshift/installer/pkg/types/none/defaults" "github.com/openshift/installer/pkg/types/openstack" openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults" + "k8s.io/utils/pointer" ) func defaultInstallConfig() *types.InstallConfig { @@ -192,7 +193,10 @@ func TestSetInstallConfigDefaults(t *testing.T) { }, expected: func() *types.InstallConfig { c := defaultInstallConfig() - c.Machines = []types.MachinePool{{Name: "test-machine"}} + c.Machines = []types.MachinePool{{ + Name: "test-machine", + Replicas: pointer.Int64Ptr(0), + }} return c }(), }, diff --git a/pkg/types/machinepools.go b/pkg/types/machinepools.go index 89d5a985464..595fa0d691f 100644 --- a/pkg/types/machinepools.go +++ b/pkg/types/machinepools.go @@ -12,8 +12,7 @@ type MachinePool struct { Name string `json:"name"` // Replicas is the count of machines for this machine pool. - // Default is 1. - Replicas *int64 `json:"replicas"` + Replicas *int64 `json:"replicas,omitempty"` // Platform is configuration for machine pool specific to the platfrom. Platform MachinePoolPlatform `json:"platform"`