From 66b0ac4f57db973e83f0fbeb4640036b0e7fc24b Mon Sep 17 00:00:00 2001 From: Jesse Haka Date: Wed, 29 Aug 2018 09:25:30 +0300 Subject: [PATCH] implement InstanceShutdownByProviderID return error if instance does not exist do not export instanceshutoff --- .../openstack/openstack_instances.go | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/providers/openstack/openstack_instances.go b/pkg/cloudprovider/providers/openstack/openstack_instances.go index 638b78508d8..8971d67adfd 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_instances.go +++ b/pkg/cloudprovider/providers/openstack/openstack_instances.go @@ -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") @@ -132,7 +136,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.