Merge pull request #67982 from zetaab/isshut

Automatic merge from submit-queue (batch tested with PRs 66577, 67948, 68001, 67982). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.

implement InstanceShutdownByProviderID to openstack

**What this PR does / why we need it**: without this openstack cannot get shutdown taint when instance is shutdown (original pr where this feature was added https://github.com/kubernetes/kubernetes/pull/60009)

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
Openstack supports now node shutdown taint. Taint is added when instance is shutdown in openstack.
```
pull/8/head
Kubernetes Submit Queue 2018-08-29 16:33:40 -07:00 committed by GitHub
commit e41d9f1553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -36,6 +36,10 @@ type Instances struct {
opts MetadataOpts
}
const (
instanceShutoff = "SHUTOFF"
)
// Instances returns an implementation of Instances for OpenStack.
func (os *OpenStack) Instances() (cloudprovider.Instances, bool) {
glog.V(4).Info("openstack.Instances() called")
@ -127,7 +131,21 @@ func (i *Instances) InstanceExistsByProviderID(ctx context.Context, providerID s
// InstanceShutdownByProviderID returns true if the instances is in safe state to detach volumes
func (i *Instances) InstanceShutdownByProviderID(ctx context.Context, 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 {
return false, err
}
// SHUTOFF is the only state where we can detach volumes immediately
if server.Status == instanceShutoff {
return true, nil
}
return false, nil
}
// InstanceID returns the kubelet's cloud provider ID.