Skip to content

Commit

Permalink
Merge pull request #161 from openshift-cherrypick-robot/cherry-pick-1…
Browse files Browse the repository at this point in the history
…58-to-release-4.5

[release-4.5] Bug 1820654: Fallback to Status Replicas if Replicas nil when listing NodeGroups
  • Loading branch information
openshift-merge-robot committed Aug 7, 2020
2 parents f73aa2e + b389cb0 commit c821779
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -507,7 +507,7 @@ func (c *machineController) machineSetNodeGroups() ([]*nodegroup, error) {
if ng.MaxSize()-ng.MinSize() > 0 {
if ng.scalableResource.CanScaleFromZero() {
nodegroups = append(nodegroups, ng)
} else if pointer.Int32PtrDerefOr(machineSet.Spec.Replicas, 0) > 0 {
} else if pointer.Int32PtrDerefOr(machineSet.Spec.Replicas, machineSet.Status.Replicas) > 0 {
nodegroups = append(nodegroups, ng)
}
}
Expand Down
Expand Up @@ -776,6 +776,10 @@ func TestControllerNodeGroups(t *testing.T) {
if _, err := controller.nodeGroups(); err == nil {
t.Fatalf("expected an error")
}
if err := deleteTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 0)

// Test #8: machinedeployment with bad scaling bounds results in an error and no nodegroups
machineDeploymentConfigs = createMachineDeploymentTestConfigs("MachineDeployment", 2, 1, annotations)
Expand All @@ -785,6 +789,24 @@ func TestControllerNodeGroups(t *testing.T) {
if _, err := controller.nodeGroups(); err == nil {
t.Fatalf("expected an error")
}
if err := deleteTestConfigs(t, controller, machineDeploymentConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 0)

annotations = map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "5",
}

// Test #9: machineset with nil replicas results in falling back to status count
machineSetConfigs = createMachineSetTestConfigs("MachineSet", 1, 1, annotations)
machineSetConfigs[0].machineSet.Status.Replicas = *machineSetConfigs[0].machineSet.Spec.Replicas
machineSetConfigs[0].machineSet.Spec.Replicas = nil
if err := addTestConfigs(t, controller, machineSetConfigs...); err != nil {
t.Fatalf("unexpected error: %v", err)
}
assertNodegroupLen(t, controller, 1)
}

func TestControllerNodeGroupsNodeCount(t *testing.T) {
Expand Down

0 comments on commit c821779

Please sign in to comment.