Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement InstanceShutdownByProviderID to openstack #67982

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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")
Expand Down Expand Up @@ -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.
Expand Down