Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 93acbe8

Browse files
committed
Implement InstanceExistsByProviderID() for cloud providers
Fix #51406 If cloud providers(like aws, gce etc...) implement ExternalID() and support getting instance by ProviderID , they also implement InstanceExistsByProviderID().
1 parent e24e335 commit 93acbe8

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

pkg/cloudprovider/providers/openstack/openstack_instances.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,25 @@ func (i *Instances) ExternalID(name types.NodeName) (string, error) {
116116
// InstanceExistsByProviderID returns true if the instance with the given provider id still exists and is running.
117117
// If false is returned with no error, the instance will be immediately deleted by the cloud controller manager.
118118
func (i *Instances) InstanceExistsByProviderID(providerID string) (bool, error) {
119-
return false, cloudprovider.NotImplemented
119+
instanceID, err := instanceIDFromProviderID(providerID)
120+
if err != nil {
121+
return false, err
122+
}
123+
124+
server, err := servers.Get(i.compute, instanceID).Extract()
125+
if err != nil {
126+
if isNotFound(err) {
127+
return false, nil
128+
}
129+
return false, err
130+
}
131+
132+
if server.Status != "ACTIVE" {
133+
glog.Warningf("the instance %s is not active", instanceID)
134+
return false, nil
135+
}
136+
137+
return true, nil
120138
}
121139

122140
// InstanceID returns the kubelet's cloud provider ID.

0 commit comments

Comments
 (0)