Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#554 from nilo19/cleanup/move-consts
Browse files Browse the repository at this point in the history
chore: move consts in azure_vmss.go to consts.go
  • Loading branch information
k8s-ci-robot authored Mar 12, 2021
2 parents 4dcb591 + bd9b6cd commit 2b8548e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
9 changes: 9 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ const (

// StrRawVersion is the raw version string
StrRawVersion string = "raw"

// VirtualMachineScaleSetsDeallocating indicates VMSS instances are in Deallocating state.
VirtualMachineScaleSetsDeallocating = "Deallocating"
// VmssMachineIDTemplate is the vmss manchine ID template
VmssMachineIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s"
// VMSetCIDRIPV4TagKey specifies the node ipv4 CIDR mask of the instances on the VMSS or VMAS
VMSetCIDRIPV4TagKey = "kubernetesNodeCIDRMaskIPV4"
// VMSetCIDRIPV6TagKey specifies the node ipv6 CIDR mask of the instances on the VMSS or VMAS
VMSetCIDRIPV6TagKey = "kubernetesNodeCIDRMaskIPV6"
)

// azure cloud config
Expand Down
17 changes: 9 additions & 8 deletions pkg/nodeipam/ipam/cloud_cidr_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/client-go/kubernetes/fake"

"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/vmssclient/mockvmssclient"
"sigs.k8s.io/cloud-provider-azure/pkg/consts"
azureprovider "sigs.k8s.io/cloud-provider-azure/pkg/provider"
"sigs.k8s.io/cloud-provider-azure/pkg/util/controller/testutil"
)
Expand Down Expand Up @@ -189,26 +190,26 @@ func TestUpdateNodeSubnetMaskSizes(t *testing.T) {
description: "updateNodeSubnetMaskSizes should put the correct mask sizes on the map",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
azureprovider.VMSetCIDRIPV4TagKey: to.StringPtr("25"),
azureprovider.VMSetCIDRIPV6TagKey: to.StringPtr("65"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("25"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("65"),
},
expectedNodeNameSubnetMaskSizesMap: map[string][]int{"vmss-0": {25, 65}},
},
{
description: "updateNodeSubnetMaskSizes should put the default mask sizes on the map if the providerID is invalid",
providerID: "invalid",
tags: map[string]*string{
azureprovider.VMSetCIDRIPV4TagKey: to.StringPtr("24"),
azureprovider.VMSetCIDRIPV6TagKey: to.StringPtr("64"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("24"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("64"),
},
expectedNodeNameSubnetMaskSizesMap: map[string][]int{"vmss-0": {24, 64}},
},
{
description: "updateNodeSubnetMaskSizes should report an error if the ipv4 mask is smaller than the cluster mask",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
azureprovider.VMSetCIDRIPV4TagKey: to.StringPtr("15"),
azureprovider.VMSetCIDRIPV6TagKey: to.StringPtr("65"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("15"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("65"),
},
expectedNodeNameSubnetMaskSizesMap: map[string][]int{},
expectedErr: fmt.Errorf("updateNodeSubnetMaskSizes: invalid ipv4 mask size %d of node %s because it is out of the range of the cluster CIDR with the mask size %d", 15, "vmss-0", 16),
Expand All @@ -217,8 +218,8 @@ func TestUpdateNodeSubnetMaskSizes(t *testing.T) {
description: "updateNodeSubnetMaskSizes should report an error if the ipv6 mask is smaller than the cluster mask",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
azureprovider.VMSetCIDRIPV4TagKey: to.StringPtr("25"),
azureprovider.VMSetCIDRIPV6TagKey: to.StringPtr("45"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("25"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("45"),
},
expectedNodeNameSubnetMaskSizesMap: map[string][]int{},
expectedErr: fmt.Errorf("updateNodeSubnetMaskSizes: invalid ipv6 mask size %d of node %s because it is out of the range of the cluster CIDR with the mask size %d", 45, "vmss-0", 48),
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (az *Cloud) CreateOrUpdateVMSS(resourceGroupName string, VMScaleSetName str
klog.Errorf("CreateOrUpdateVMSS: error getting vmss(%s): %v", VMScaleSetName, rerr)
return rerr
}
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, virtualMachineScaleSetsDeallocating) {
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, consts.VirtualMachineScaleSetsDeallocating) {
klog.V(3).Infof("CreateOrUpdateVMSS: found vmss %s being deleted, skipping", VMScaleSetName)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func TestCreateOrUpdateVMSS(t *testing.T) {
{
vmss: compute.VirtualMachineScaleSet{
VirtualMachineScaleSetProperties: &compute.VirtualMachineScaleSetProperties{
ProvisioningState: to.StringPtr(virtualMachineScaleSetsDeallocating),
ProvisioningState: to.StringPtr(consts.VirtualMachineScaleSetsDeallocating),
},
},
},
Expand Down
23 changes: 6 additions & 17 deletions pkg/provider/azure_vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
utilnet "k8s.io/utils/net"

azcache "sigs.k8s.io/cloud-provider-azure/pkg/cache"
"sigs.k8s.io/cloud-provider-azure/pkg/consts"
"sigs.k8s.io/cloud-provider-azure/pkg/metrics"
)

Expand All @@ -50,18 +51,6 @@ var (
vmssVMProviderIDRE = regexp.MustCompile(`azure:///subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines/(?:\d+)`)
)

const (
// virtualMachineScaleSetsDeallocating indicates VMSS instances are in Deallocating state.
virtualMachineScaleSetsDeallocating = "Deallocating"

vmssMachineIDTemplate = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s"

// VMSetCIDRIPV4TagKey specifies the node ipv4 CIDR mask of the instances on the VMSS or VMAS
VMSetCIDRIPV4TagKey = "kubernetesNodeCIDRMaskIPV4"
// VMSetCIDRIPV6TagKey specifies the node ipv6 CIDR mask of the instances on the VMSS or VMAS
VMSetCIDRIPV6TagKey = "kubernetesNodeCIDRMaskIPV6"
)

// vmssMetaInfo contains the metadata for a VMSS.
type vmssMetaInfo struct {
vmssName string
Expand Down Expand Up @@ -562,7 +551,7 @@ func (ss *ScaleSet) getPrimaryInterfaceID(machine compute.VirtualMachineScaleSet
// getVmssMachineID returns the full identifier of a vmss virtual machine.
func (az *Cloud) getVmssMachineID(subscriptionID, resourceGroup, scaleSetName, instanceID string) string {
return fmt.Sprintf(
vmssMachineIDTemplate,
consts.VmssMachineIDTemplate,
subscriptionID,
strings.ToLower(resourceGroup),
scaleSetName,
Expand Down Expand Up @@ -1098,7 +1087,7 @@ func (ss *ScaleSet) ensureVMSSInPool(service *v1.Service, nodes []*v1.Node, back

// When vmss is being deleted, CreateOrUpdate API would report "the vmss is being deleted" error.
// Since it is being deleted, we shouldn't send more CreateOrUpdate requests for it.
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, virtualMachineScaleSetsDeallocating) {
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, consts.VirtualMachineScaleSetsDeallocating) {
klog.V(3).Infof("ensureVMSSInPool: found vmss %s being deleted, skipping", vmssName)
continue
}
Expand Down Expand Up @@ -1447,7 +1436,7 @@ func (ss *ScaleSet) ensureBackendPoolDeletedFromVMSS(service *v1.Service, backen

// When vmss is being deleted, CreateOrUpdate API would report "the vmss is being deleted" error.
// Since it is being deleted, we shouldn't send more CreateOrUpdate requests for it.
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, virtualMachineScaleSetsDeallocating) {
if vmss.ProvisioningState != nil && strings.EqualFold(*vmss.ProvisioningState, consts.VirtualMachineScaleSetsDeallocating) {
klog.V(3).Infof("ensureVMSSInPool: found vmss %s being deleted, skipping", vmssName)
continue
}
Expand Down Expand Up @@ -1655,13 +1644,13 @@ func (ss *ScaleSet) GetNodeCIDRMasksByProviderID(providerID string) (int, int, e
}

var ipv4Mask, ipv6Mask int
if v4, ok := vmss.Tags[VMSetCIDRIPV4TagKey]; ok && v4 != nil {
if v4, ok := vmss.Tags[consts.VMSetCIDRIPV4TagKey]; ok && v4 != nil {
ipv4Mask, err = strconv.Atoi(to.String(v4))
if err != nil {
klog.Errorf(" GetNodeCIDRMasksByProviderID: error when paring the value of the ipv4 mask size %s: %v", to.String(v4), err)
}
}
if v6, ok := vmss.Tags[VMSetCIDRIPV6TagKey]; ok && v6 != nil {
if v6, ok := vmss.Tags[consts.VMSetCIDRIPV6TagKey]; ok && v6 != nil {
ipv6Mask, err = strconv.Atoi(to.String(v6))
if err != nil {
klog.Errorf(" GetNodeCIDRMasksByProviderID: error when paring the value of the ipv6 mask size%s: %v", to.String(v6), err)
Expand Down
16 changes: 8 additions & 8 deletions pkg/provider/azure_vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ func TestGetVmssMachineID(t *testing.T) {

subscriptionID, resourceGroup, scaleSetName, instanceID := "sub", "RG", "vmss", "id"
VMSSMachineID := ss.cloud.getVmssMachineID(subscriptionID, resourceGroup, scaleSetName, instanceID)
expectedVMSSMachineID := fmt.Sprintf(vmssMachineIDTemplate, subscriptionID, strings.ToLower(resourceGroup), scaleSetName, instanceID)
expectedVMSSMachineID := fmt.Sprintf(consts.VmssMachineIDTemplate, subscriptionID, strings.ToLower(resourceGroup), scaleSetName, instanceID)
assert.Equal(t, expectedVMSSMachineID, VMSSMachineID, "GetVmssMachineID should return the correct VMSS machine ID")
}

Expand Down Expand Up @@ -1977,7 +1977,7 @@ func TestEnsureVMSSInPool(t *testing.T) {

expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, test.setIPv6Config)
if test.isVMSSDeallocating {
expectedVMSS.ProvisioningState = to.StringPtr(virtualMachineScaleSetsDeallocating)
expectedVMSS.ProvisioningState = to.StringPtr(consts.VirtualMachineScaleSetsDeallocating)
}
if test.isVMSSNilNICConfig {
expectedVMSS.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations = nil
Expand Down Expand Up @@ -2251,7 +2251,7 @@ func TestEnsureBackendPoolDeletedFromVMSS(t *testing.T) {

expectedVMSS := buildTestVMSSWithLB(testVMSSName, "vmss-vm-", []string{testLBBackendpoolID0}, false)
if test.isVMSSDeallocating {
expectedVMSS.ProvisioningState = to.StringPtr(virtualMachineScaleSetsDeallocating)
expectedVMSS.ProvisioningState = to.StringPtr(consts.VirtualMachineScaleSetsDeallocating)
}
if test.isVMSSNilNICConfig {
expectedVMSS.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations = nil
Expand Down Expand Up @@ -2464,8 +2464,8 @@ func TestGetNodeCIDRMasksByProviderID(t *testing.T) {
description: "GetNodeCIDRMaksByProviderID should return the correct mask sizes",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
VMSetCIDRIPV4TagKey: to.StringPtr("24"),
VMSetCIDRIPV6TagKey: to.StringPtr("64"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("24"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("64"),
},
expectedIPV4MaskSize: 24,
expectedIPV6MaskSize: 64,
Expand All @@ -2474,16 +2474,16 @@ func TestGetNodeCIDRMasksByProviderID(t *testing.T) {
description: "GetNodeCIDRMaksByProviderID should return the correct mask sizes even if some of the tags are not specified",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
VMSetCIDRIPV4TagKey: to.StringPtr("24"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("24"),
},
expectedIPV4MaskSize: 24,
},
{
description: "GetNodeCIDRMaksByProviderID should fail even if some of the tag is invalid",
providerID: "azure:///subscriptions/sub/resourceGroups/rg1/providers/Microsoft.Compute/virtualMachineScaleSets/vmss/virtualMachines/0",
tags: map[string]*string{
VMSetCIDRIPV4TagKey: to.StringPtr("abc"),
VMSetCIDRIPV6TagKey: to.StringPtr("64"),
consts.VMSetCIDRIPV4TagKey: to.StringPtr("abc"),
consts.VMSetCIDRIPV6TagKey: to.StringPtr("64"),
},
expectedIPV6MaskSize: 64,
},
Expand Down

0 comments on commit 2b8548e

Please sign in to comment.