Skip to content

Commit

Permalink
fix: implement HasInstance() for OCI providers
Browse files Browse the repository at this point in the history
This implements HasInstance() for the OCI instance pool and node pool providers.
  • Loading branch information
alfredkrohmer committed Aug 12, 2024
1 parent a7ee2b2 commit db59e7a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Copyright 2021-2023 Oracle and/or its affiliates.
package instancepools

import (
"strings"

"github.com/pkg/errors"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -19,7 +21,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"strings"
)

// OciCloudProvider implements the CloudProvider interface for OCI. It contains an
Expand Down Expand Up @@ -66,8 +67,25 @@ func (ocp *OciCloudProvider) NodeGroupForNode(n *apiv1.Node) (cloudprovider.Node
}

// HasInstance returns whether a given node has a corresponding instance in this cloud provider
func (ocp *OciCloudProvider) HasInstance(n *apiv1.Node) (bool, error) {
return true, cloudprovider.ErrNotImplemented
func (ocp *OciCloudProvider) HasInstance(node *apiv1.Node) (bool, error) {
instance, err := ocicommon.NodeToOciRef(node)
if err != nil {
return false, err
}
instancePool, err := ocp.poolManager.GetInstancePoolForInstance(instance)
if err != nil {
return false, err
}
instances, err := ocp.poolManager.GetInstancePoolNodes(*instancePool)
if err != nil {
return false, err
}
for _, i := range instances {
if i.Id == instance.InstanceID {
return true, nil
}
}
return false, nil
}

// Pricing returns pricing model for this cloud provider or error if not available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,25 @@ func (ocp *OciCloudProvider) GetNodeGpuConfig(node *apiv1.Node) *cloudprovider.G
}

// HasInstance returns whether a given node has a corresponding instance in this cloud provider
func (ocp *OciCloudProvider) HasInstance(n *apiv1.Node) (bool, error) {
return true, cloudprovider.ErrNotImplemented
func (ocp *OciCloudProvider) HasInstance(node *apiv1.Node) (bool, error) {
instance, err := ocicommon.NodeToOciRef(node)
if err != nil {
return true, err
}
np, err := ocp.manager.GetNodePoolForInstance(instance)
if err != nil {
return true, err
}
nodes, err := ocp.manager.GetNodePoolNodes(np)
if err != nil {
return true, err
}
for _, n := range nodes {
if n.Id == instance.InstanceID {
return true, nil
}
}
return false, nil
}

// Pricing returns pricing model for this cloud provider or error if not available.
Expand Down

0 comments on commit db59e7a

Please sign in to comment.