mirror of https://github.com/k3s-io/k3s
Merge pull request #68033 from yastij/instanceShutdown-azure
Automatic merge from submit-queue. 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 for azure **What this PR does / why we need it**: implements #66265 **Which issue(s) this PR fixes**: Fixes #66265 **Special notes for your reviewer**: **Release note**: ```release-note Support NodeShutdown taint for azure ```pull/8/head
commit
10bde5090b
|
@ -893,3 +893,7 @@ func (f *fakeVMSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
|
||||||
func (f *fakeVMSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, error) {
|
func (f *fakeVMSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, error) {
|
||||||
return nil, fmt.Errorf("unimplemented")
|
return nil, fmt.Errorf("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *fakeVMSet) GetProvisioningStateByNodeName(name string) (string, error) {
|
||||||
|
return "", fmt.Errorf("unimplemented")
|
||||||
|
}
|
||||||
|
|
|
@ -143,7 +143,17 @@ func (az *Cloud) InstanceExistsByProviderID(ctx context.Context, providerID stri
|
||||||
|
|
||||||
// InstanceShutdownByProviderID returns true if the instance is in safe state to detach volumes
|
// InstanceShutdownByProviderID returns true if the instance is in safe state to detach volumes
|
||||||
func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) {
|
func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID string) (bool, error) {
|
||||||
return false, cloudprovider.NotImplemented
|
nodeName, err := az.vmSet.GetNodeNameByProviderID(providerID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioningState, err := az.vmSet.GetProvisioningStateByNodeName(string(nodeName))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ToLower(provisioningState) == "stopped" || strings.ToLower(provisioningState) == "deallocated", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getComputeMetadata gets compute information from instance metadata.
|
// getComputeMetadata gets compute information from instance metadata.
|
||||||
|
|
|
@ -346,6 +346,15 @@ func (as *availabilitySet) GetInstanceIDByNodeName(name string) (string, error)
|
||||||
return *machine.ID, nil
|
return *machine.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (as *availabilitySet) GetProvisioningStateByNodeName(name string) (provisioningState string, err error) {
|
||||||
|
vm, err := as.getVirtualMachine(types.NodeName(name))
|
||||||
|
if err != nil {
|
||||||
|
return provisioningState, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return *vm.ProvisioningState, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetNodeNameByProviderID gets the node name by provider ID.
|
// GetNodeNameByProviderID gets the node name by provider ID.
|
||||||
func (as *availabilitySet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
|
func (as *availabilitySet) GetNodeNameByProviderID(providerID string) (types.NodeName, error) {
|
||||||
// NodeName is part of providerID for standard instances.
|
// NodeName is part of providerID for standard instances.
|
||||||
|
|
|
@ -64,4 +64,7 @@ type VMSet interface {
|
||||||
DetachDiskByName(diskName, diskURI string, nodeName types.NodeName) error
|
DetachDiskByName(diskName, diskURI string, nodeName types.NodeName) error
|
||||||
// GetDataDisks gets a list of data disks attached to the node.
|
// GetDataDisks gets a list of data disks attached to the node.
|
||||||
GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, error)
|
GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, error)
|
||||||
|
|
||||||
|
// GetProvisioningStateByNodeName gets the provisioning state by node name.
|
||||||
|
GetProvisioningStateByNodeName(name string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,15 @@ func (ss *scaleSet) getVmssVM(nodeName string) (ssName, instanceID string, vm co
|
||||||
return ssName, instanceID, *(cachedVM.(*compute.VirtualMachineScaleSetVM)), nil
|
return ssName, instanceID, *(cachedVM.(*compute.VirtualMachineScaleSetVM)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ss *scaleSet) GetProvisioningStateByNodeName(name string) (provisioningState string, err error) {
|
||||||
|
_, _, vm, err := ss.getVmssVM(name)
|
||||||
|
if err != nil {
|
||||||
|
return provisioningState, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return *vm.ProvisioningState, nil
|
||||||
|
}
|
||||||
|
|
||||||
// getCachedVirtualMachineByInstanceID gets scaleSetVMInfo from cache.
|
// getCachedVirtualMachineByInstanceID gets scaleSetVMInfo from cache.
|
||||||
// The node must belong to one of scale sets.
|
// The node must belong to one of scale sets.
|
||||||
func (ss *scaleSet) getVmssVMByInstanceID(resourceGroup, scaleSetName, instanceID string) (vm compute.VirtualMachineScaleSetVM, err error) {
|
func (ss *scaleSet) getVmssVMByInstanceID(resourceGroup, scaleSetName, instanceID string) (vm compute.VirtualMachineScaleSetVM, err error) {
|
||||||
|
|
Loading…
Reference in New Issue