Skip to content

Commit

Permalink
pkg/types/defaults/installconfig: Set defaults for null replicas
Browse files Browse the repository at this point in the history
We don't currently support configuring zero workers [1], largely
because some key operators still do not tolerate masters.  Still, some
users are attempting to work around our checks by leaving 'replicas'
unset (which ends up as nil in Go) [2].  This commit adjusts our
install-config defaulting to fill in the default replica counts when
the user provides machine-pool entries but leaves replicas unset.

[1]: #958
[2]: https://bugzilla.redhat.com/show_bug.cgi?id=1670005#c1
  • Loading branch information
wking committed Jan 29, 2019
1 parent e8ce3e4 commit 9eeb259
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 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

0 comments on commit 9eeb259

Please sign in to comment.