mirror of https://github.com/kubernetes/kops.git
azure: Implement DeleteInstance for rolling update
This commit is contained in:
parent
bca0836e36
commit
28939f865b
|
@ -476,7 +476,8 @@ func (c *RollingUpdateCluster) reconcileInstanceGroup() error {
|
|||
if c.Cluster.Spec.GetCloudProvider() != api.CloudProviderOpenstack &&
|
||||
c.Cluster.Spec.GetCloudProvider() != api.CloudProviderHetzner &&
|
||||
c.Cluster.Spec.GetCloudProvider() != api.CloudProviderScaleway &&
|
||||
c.Cluster.Spec.GetCloudProvider() != api.CloudProviderDO {
|
||||
c.Cluster.Spec.GetCloudProvider() != api.CloudProviderDO &&
|
||||
c.Cluster.Spec.GetCloudProvider() != api.CloudProviderAzure {
|
||||
return nil
|
||||
}
|
||||
rto := fi.RunTasksOptions{}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||
"k8s.io/klog/v2"
|
||||
|
@ -192,7 +193,9 @@ func (c *azureCloudImplementation) FindVNetInfo(id, resourceGroup string) (*fi.V
|
|||
}
|
||||
|
||||
func (c *azureCloudImplementation) DeleteInstance(i *cloudinstances.CloudInstance) error {
|
||||
return errors.New("DeleteInstance not implemented on azureCloud")
|
||||
vmssName := i.CloudInstanceGroup.HumanName
|
||||
instanceID := strings.TrimPrefix(i.ID, vmssName+"_")
|
||||
return c.vmscaleSetVMsClient.Delete(context.TODO(), "my.k8s", vmssName, instanceID)
|
||||
}
|
||||
|
||||
// DeregisterInstance drains a cloud instance and loadbalancers.
|
||||
|
|
|
@ -67,6 +67,17 @@ func (c *mockVMScaleSetVMsClient) List(ctx context.Context, resourceGroupName, v
|
|||
return c.vms, nil
|
||||
}
|
||||
|
||||
func (c *mockVMScaleSetVMsClient) Delete(ctx context.Context, resourceGroupName, vmssName, instanceID string) error {
|
||||
var l []*compute.VirtualMachineScaleSetVM
|
||||
for _, vm := range c.vms {
|
||||
if *vm.ID != instanceID {
|
||||
l = append(l, vm)
|
||||
}
|
||||
}
|
||||
c.vms = l
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestFindEtcdStatus(t *testing.T) {
|
||||
clusterName := "my-cluster"
|
||||
c := &azureCloudImplementation{
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
// VMScaleSetVMsClient is a client for managing VMs in VM Scale Sets.
|
||||
type VMScaleSetVMsClient interface {
|
||||
List(ctx context.Context, resourceGroupName, vmssName string) ([]*compute.VirtualMachineScaleSetVM, error)
|
||||
Delete(ctx context.Context, resourceGroupName, vmssName, instanceId string) error
|
||||
}
|
||||
|
||||
type vmScaleSetVMsClientImpl struct {
|
||||
|
@ -48,6 +49,17 @@ func (c *vmScaleSetVMsClientImpl) List(ctx context.Context, resourceGroupName, v
|
|||
return l, nil
|
||||
}
|
||||
|
||||
func (c *vmScaleSetVMsClientImpl) Delete(ctx context.Context, resourceGroupName, vmssName, instanceId string) error {
|
||||
future, err := c.c.BeginDelete(ctx, resourceGroupName, vmssName, instanceId, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("deleting VMSS VM: %w", err)
|
||||
}
|
||||
if _, err = future.PollUntilDone(ctx, nil); err != nil {
|
||||
return fmt.Errorf("waiting for VMSS VM deletion completion: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func newVMScaleSetVMsClientImpl(subscriptionID string, cred *azidentity.DefaultAzureCredential) (*vmScaleSetVMsClientImpl, error) {
|
||||
c, err := compute.NewVirtualMachineScaleSetVMsClient(subscriptionID, cred, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -463,6 +463,13 @@ func (c *MockVMScaleSetVMsClient) List(ctx context.Context, resourceGroupName, v
|
|||
return l, nil
|
||||
}
|
||||
|
||||
// Delete deletes a VM Scale Set VMs.
|
||||
func (c *MockVMScaleSetVMsClient) Delete(ctx context.Context, resourceGroupName, vmssName, instanceID string) error {
|
||||
// Ignore resourceGroupName and vmssName for simplicity.
|
||||
delete(c.VMs, instanceID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MockDisksClient is a mock implementation of disk client.
|
||||
type MockDisksClient struct {
|
||||
Disks map[string]*compute.Disk
|
||||
|
|
Loading…
Reference in New Issue