Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Copyright 2021-2023 Oracle and/or its affiliates.
package instancepools

import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/vendor-internal/github.com/oracle/oci-go-sdk/v65/common"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -150,6 +151,7 @@ func (ocp *OciCloudProvider) Refresh() error {

// BuildOCI constructs the OciCloudProvider object that implements the could provider interface (InstancePoolManager).
func BuildOCI(opts *coreoptions.AutoscalerOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider {
common.EnableInstanceMetadataServiceLookup()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the effects of invoking this external function from within BuildOCI?

ocidType, err := ocicommon.GetAllPoolTypes(opts.NodeGroups)
if err != nil {
klog.Fatalf("Failed to get pool type: %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ const (

// EphemeralStorageSize is the freeform tag key that would be used to determine the ephemeral-storage size of the node
EphemeralStorageSize = "cluster-autoscaler/node-ephemeral-storage"

// OciVirtualNodeResourceIdent is the string identifier in the ocid that indicates the resource is a virtual node pool
OciVirtualNodeResourceIdent = "virtualnode"
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
ocicommon "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/common"
npconsts "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/oci/nodepools/consts"
caerrors "k8s.io/autoscaler/cluster-autoscaler/utils/errors"
"k8s.io/autoscaler/cluster-autoscaler/utils/gpu"
klog "k8s.io/klog/v2"
"strings"
)

// OciCloudProvider creates a cloud provider object that is compatible with node pools
Expand Down Expand Up @@ -86,6 +88,10 @@ func (ocp *OciCloudProvider) HasInstance(node *apiv1.Node) (bool, error) {
if err != nil {
return true, err
}
// Properly handle virtual nodes and missing node pool IDs to prevent crashes
if np == nil || np.Id() == "" || strings.Contains(instance.InstanceID, npconsts.OciVirtualNodeResourceIdent) {
return false, cloudprovider.ErrNotImplemented
}
nodes, err := ocp.manager.GetNodePoolNodes(np)
if err != nil {
return true, err
Expand Down
3 changes: 3 additions & 0 deletions cluster-autoscaler/cloudprovider/oci/nodepools/oci_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ func (m *ociManagerImpl) GetNodePoolNodes(np NodePool) ([]cloudprovider.Instance

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

Expand Down
10 changes: 10 additions & 0 deletions cluster-autoscaler/cloudprovider/oci/nodepools/oci_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ func TestGetNodePoolForInstance(t *testing.T) {
if np.Id() != "ocid2" {
t.Fatalf("got unexpected ocid %q ; wanted \"ocid2\"", np.Id())
}

// now verify node pool can be found via lookup up by instance id in cache
np, err = manager.GetNodePoolForInstance(ocicommon.OciRef{InstanceID: "virtualnode"})
if err != nil {
t.Fatalf("unexpected error: %+v", err)
}

if np != nil {
t.Fatalf("got unexpected ocid %q ; wanted nil", np.Id())
}
}

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