diff --git a/pkg/openstack/instancesv2.go b/pkg/openstack/instancesv2.go index 3e6f770f7e..2ce048cc9d 100644 --- a/pkg/openstack/instancesv2.go +++ b/pkg/openstack/instancesv2.go @@ -20,6 +20,7 @@ import ( "context" "fmt" sysos "os" + "strings" "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" @@ -79,6 +80,18 @@ func (os *OpenStack) instancesv2() (*InstancesV2, bool) { // InstanceExists indicates whether a given node exists according to the cloud provider func (i *InstancesV2) InstanceExists(ctx context.Context, node *v1.Node) (bool, error) { + if i.regionProviderID { + if node.Spec.ProviderID == "" { + klog.V(4).Infof("Instance %s should initialized first", node.Name) + return true, nil + } + + if !strings.HasPrefix(node.Spec.ProviderID, ProviderName+"://") { + klog.V(4).Infof("Instance %s is not an OpenStack instance", node.Name) + return true, nil + } + } + _, err := i.getInstance(ctx, node) if err == cloudprovider.InstanceNotFound { klog.V(6).Infof("instance not found for node: %s", node.Name) @@ -94,6 +107,18 @@ func (i *InstancesV2) InstanceExists(ctx context.Context, node *v1.Node) (bool, // InstanceShutdown returns true if the instance is shutdown according to the cloud provider. func (i *InstancesV2) InstanceShutdown(ctx context.Context, node *v1.Node) (bool, error) { + if i.regionProviderID { + if node.Spec.ProviderID == "" { + klog.V(4).Infof("Instance %s should initialized first", node.Name) + return false, nil + } + + if !strings.HasPrefix(node.Spec.ProviderID, ProviderName+"://") { + klog.V(4).Infof("Instance %s is not an OpenStack instance", node.Name) + return false, nil + } + } + server, err := i.getInstance(ctx, node) if err != nil { return false, err