Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implement HasInstance() for OCI providers #7154

Merged
Merged
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,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
Loading