Skip to content

Commit

Permalink
[occm] multizone race condition
Browse files Browse the repository at this point in the history
We cannot definitively determine whether a node exists within our zone without the provider ID string.
  • Loading branch information
sergelogvinov committed May 8, 2024
1 parent 2f186d6 commit 6016b87
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/openstack/instancesv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
sysos "os"
"strings"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 6016b87

Please sign in to comment.