Skip to content

Commit f95adf7

Browse files
committed
Autoscaler should not try to monitor or scale virtual nodes and virtual node pools
1 parent 6aa6f02 commit f95adf7

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

cluster-autoscaler/cloudprovider/oci/nodepools/consts/annotations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ const (
2828

2929
// EphemeralStorageSize is the freeform tag key that would be used to determine the ephemeral-storage size of the node
3030
EphemeralStorageSize = "cluster-autoscaler/node-ephemeral-storage"
31+
32+
// OciNodePoolResourceIdent is the string identifier in the ocid that indicates the resource is a virtual node pool
33+
OciVirtualNodeResourceIdent = "virtualnode"
3134
)

cluster-autoscaler/cloudprovider/oci/nodepools/oci_cloud_provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
"k8s.io/apimachinery/pkg/api/resource"
1111
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
1212
ocicommon "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/common"
13+
npconsts "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/nodepools/consts"
1314
caerrors "k8s.io/autoscaler/cluster-autoscaler/utils/errors"
1415
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
1516
klog "k8s.io/klog/v2"
17+
"strings"
1618
)
1719

1820
// OciCloudProvider creates a cloud provider object that is compatible with node pools
@@ -86,6 +88,10 @@ func (ocp *OciCloudProvider) HasInstance(node *apiv1.Node) (bool, error) {
8688
if err != nil {
8789
return true, err
8890
}
91+
// Properly handle virtual nodes and missing node pool IDs to prevent crashes
92+
if np == nil || np.Id() == "" || strings.Contains(instance.InstanceID, npconsts.OciVirtualNodeResourceIdent) {
93+
return false, cloudprovider.ErrNotImplemented
94+
}
8995
nodes, err := ocp.manager.GetNodePoolNodes(np)
9096
if err != nil {
9197
return true, err

cluster-autoscaler/cloudprovider/oci/nodepools/oci_manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ func (m *ociManagerImpl) GetNodePoolNodes(np NodePool) ([]cloudprovider.Instance
630630

631631
// GetNodePoolForInstance returns NodePool to which the given instance belongs.
632632
func (m *ociManagerImpl) GetNodePoolForInstance(instance ocicommon.OciRef) (NodePool, error) {
633+
if strings.Contains(instance.InstanceID, npconsts.OciVirtualNodeResourceIdent) {
634+
return nil, nil
635+
}
633636
if instance.NodePoolID == "" {
634637
klog.V(4).Infof("node pool id missing from reference: %+v", instance)
635638

cluster-autoscaler/cloudprovider/oci/nodepools/oci_manager_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ func TestGetNodePoolForInstance(t *testing.T) {
9797
if np.Id() != "ocid2" {
9898
t.Fatalf("got unexpected ocid %q ; wanted \"ocid2\"", np.Id())
9999
}
100+
101+
// now verify node pool can be found via lookup up by instance id in cache
102+
np, err = manager.GetNodePoolForInstance(ocicommon.OciRef{InstanceID: "virtualnode"})
103+
if err != nil {
104+
t.Fatalf("unexpected error: %+v", err)
105+
}
106+
107+
if np != nil {
108+
t.Fatalf("got unexpected ocid %q ; wanted nil", np.Id())
109+
}
100110
}
101111

102112
func TestGetNodePoolNodes(t *testing.T) {

0 commit comments

Comments
 (0)