Skip to content

Commit

Permalink
Avoid caching the VMSS instances whose network profile is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer committed May 8, 2021
1 parent cc22cfa commit 2baad9c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func (ss *scaleSet) newVMSSVirtualMachinesCache(resourceGroupName, vmssName, cac
}

computerName := strings.ToLower(*vm.OsProfile.ComputerName)
if vm.NetworkProfile == nil || vm.NetworkProfile.NetworkInterfaces == nil {
klog.Warningf("skip caching vmssVM %s since its network profile hasn't initialized yet (probably still under creating)", computerName)
continue
}

vmssVMCacheEntry := &vmssVirtualMachinesEntry{
resourceGroup: resourceGroupName,
vmssName: vmssName,
Expand Down
37 changes: 37 additions & 0 deletions staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,16 +1374,25 @@ func TestGetAgentPoolScaleSets(t *testing.T) {
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000000")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000001")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000002")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
}
Expand Down Expand Up @@ -1442,6 +1451,20 @@ func TestGetVMSetNames(t *testing.T) {
},
expectedErr: fmt.Errorf("scale set (vmss-1) - not found"),
},
{
description: "GetVMSetNames should report an error if vm's network profile is nil",
service: &v1.Service{
ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{ServiceAnnotationLoadBalancerMode: "vmss"}},
},
nodes: []*v1.Node{
{
ObjectMeta: metav1.ObjectMeta{
Name: "vmss-vm-000003",
},
},
},
expectedErr: fmt.Errorf("instance not found"),
},
{
description: "GetVMSetNames should return the correct vmss names",
service: &v1.Service{
Expand Down Expand Up @@ -1470,16 +1493,30 @@ func TestGetVMSetNames(t *testing.T) {
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000000")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000001")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000002")},
NetworkProfile: &compute.NetworkProfile{
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
},
},
},
{
VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{
OsProfile: &compute.OSProfile{ComputerName: to.StringPtr("vmss-vm-000003")},
},
},
}
Expand Down

0 comments on commit 2baad9c

Please sign in to comment.