Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/types/defaults/installconfig: Set defaults for null replicas #1146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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