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

Commit b205af9

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #51409 from FengyunPan/implement-InstanceExistsByProviderID
Automatic merge from submit-queue (batch tested with PRs 51409, 54616). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. 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(). /assign wlan0 /assign @luxas **Release note**: ```release-note NONE ```
2 parents 6119229 + 93acbe8 commit b205af9

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)