Skip to content

Commit

Permalink
Merge pull request #1146 from wking/defaults-for-null-replicas
Browse files Browse the repository at this point in the history
pkg/types/defaults/installconfig: Set defaults for null replicas
  • Loading branch information
openshift-merge-robot committed Jan 30, 2019
2 parents 1fc7ccd + 4b553cd commit d3ff3af
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
34 changes: 26 additions & 8 deletions pkg/types/defaults/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion pkg/types/defaults/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}(),
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/types/machinepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit d3ff3af

Please sign in to comment.