Skip to content

Commit 2ca7d9c

Browse files
domenicbozzutojlamillan
authored andcommitted
Ignore string case when comparing instance pool summary state
This fixes an issue where existing nodes would be categorized as upcoming. When the cluster state was updated and HasInstance was called, this function would be invoked to check the instance state. The OCI API for instance pools actually returns "Running" (instead of the expected "RUNNING"); this would cause the instance to be flagged as 'Deleted' in the readiness state, and when the calculation for newNodes was made, since a running node belonging to the pool instance was counted as deleted and not registered, the upcoming node count was incorrectly non-zero.
1 parent c439b3a commit 2ca7d9c

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

cluster-autoscaler/cloudprovider/oci/instancepools/oci_instance_pool_manager.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,30 +267,32 @@ func (m *InstancePoolManagerImpl) GetInstancePoolNodes(ip InstancePoolNodeGroup)
267267
var providerInstances []cloudprovider.Instance
268268
for _, instance := range *instanceSummaries {
269269
status := &cloudprovider.InstanceStatus{}
270-
switch *instance.State {
271-
case string(core.InstanceLifecycleStateStopped), string(core.InstanceLifecycleStateTerminated):
270+
switch strings.ToLower(*instance.State) {
271+
case strings.ToLower(string(core.InstanceLifecycleStateStopped)), strings.ToLower(string(core.InstanceLifecycleStateTerminated)):
272272
klog.V(4).Infof("skipping instance is in stopped/terminated state: %q", *instance.Id)
273-
case string(core.InstanceLifecycleStateRunning):
273+
case strings.ToLower(string(core.InstanceLifecycleStateRunning)):
274274
status.State = cloudprovider.InstanceRunning
275-
case string(core.InstanceLifecycleStateCreatingImage):
275+
case strings.ToLower(string(core.InstanceLifecycleStateCreatingImage)):
276276
status.State = cloudprovider.InstanceCreating
277-
case string(core.InstanceLifecycleStateStarting):
277+
case strings.ToLower(string(core.InstanceLifecycleStateStarting)):
278278
status.State = cloudprovider.InstanceCreating
279-
case string(core.InstanceLifecycleStateMoving):
279+
case strings.ToLower(string(core.InstanceLifecycleStateMoving)):
280280
status.State = cloudprovider.InstanceCreating
281-
case string(core.InstanceLifecycleStateProvisioning):
281+
case strings.ToLower(string(core.InstanceLifecycleStateProvisioning)):
282282
status.State = cloudprovider.InstanceCreating
283-
case string(core.InstanceLifecycleStateTerminating):
283+
case strings.ToLower(string(core.InstanceLifecycleStateTerminating)):
284284
status.State = cloudprovider.InstanceDeleting
285-
case string(core.InstanceLifecycleStateStopping):
285+
case strings.ToLower(string(core.InstanceLifecycleStateStopping)):
286286
status.State = cloudprovider.InstanceDeleting
287-
case consts.InstanceStateUnfulfilled:
287+
case strings.ToLower(consts.InstanceStateUnfulfilled):
288288
status.State = cloudprovider.InstanceCreating
289289
status.ErrorInfo = &cloudprovider.InstanceErrorInfo{
290290
ErrorClass: cloudprovider.OutOfResourcesErrorClass,
291291
ErrorCode: consts.InstanceStateUnfulfilled,
292292
ErrorMessage: "OCI cannot provision additional instances for this instance pool. Review quota and/or capacity.",
293293
}
294+
default:
295+
klog.Warningf("instance %s has unknown state: %s", *instance.Id, *instance.State)
294296
}
295297

296298
klog.V(5).Infof("instance %s is in state: %s", *instance.Id, *instance.State)

cluster-autoscaler/cloudprovider/oci/instancepools/oci_instance_pool_manager_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ package instancepools
66

77
import (
88
"context"
9+
"reflect"
10+
"testing"
11+
912
apiv1 "k8s.io/api/core/v1"
1013
ocicommon "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/common"
1114
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/core"
1215
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/workrequests"
1316
kubeletapis "k8s.io/kubelet/pkg/apis"
14-
"reflect"
15-
"testing"
1617

1718
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
1819
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common"
@@ -372,6 +373,12 @@ func TestGetInstancePoolNodes(t *testing.T) {
372373
AvailabilityDomain: common.String("PHX-AD-1"),
373374
State: common.String(string(core.InstanceLifecycleStateTerminating)),
374375
},
376+
{
377+
// Instance state is running with varied capitalization
378+
Id: common.String("ocid1.instance.oc1.phx.aaa3"),
379+
AvailabilityDomain: common.String("PHX-AD-1"),
380+
State: common.String("Running"),
381+
},
375382
}
376383

377384
expected := []cloudprovider.Instance{
@@ -387,6 +394,12 @@ func TestGetInstancePoolNodes(t *testing.T) {
387394
State: cloudprovider.InstanceDeleting,
388395
},
389396
},
397+
{
398+
Id: "ocid1.instance.oc1.phx.aaa3",
399+
Status: &cloudprovider.InstanceStatus{
400+
State: cloudprovider.InstanceRunning,
401+
},
402+
},
390403
}
391404

392405
manager := &InstancePoolManagerImpl{instancePoolCache: nodePoolCache, cfg: &ocicommon.CloudConfig{}}

0 commit comments

Comments
 (0)