Skip to content

Commit

Permalink
Implement InstanceExistsByProviderID() for cloud providers
Browse files Browse the repository at this point in the history
Fix kubernetes#51406
If cloud providers(like aws, gce etc...) implement ExternalID()
and support getting instance by ProviderID , they also implement
InstanceExistsByProviderID().
  • Loading branch information
FengyunPan2 committed Oct 20, 2017
1 parent e24e335 commit 93acbe8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/cloudprovider/providers/openstack/openstack_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,25 @@ func (i *Instances) ExternalID(name types.NodeName) (string, error) {
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
func (i *Instances) InstanceExistsByProviderID(providerID string) (bool, error) {
return false, cloudprovider.NotImplemented
instanceID, err := instanceIDFromProviderID(providerID)
if err != nil {
return false, err
}

server, err := servers.Get(i.compute, instanceID).Extract()
if err != nil {
if isNotFound(err) {
return false, nil
}
return false, err
}

if server.Status != "ACTIVE" {
glog.Warningf("the instance %s is not active", instanceID)
return false, nil
}

return true, nil
}

// InstanceID returns the kubelet's cloud provider ID.
Expand Down

0 comments on commit 93acbe8

Please sign in to comment.