Skip to content

Commit

Permalink
fix: validate "basic" LB and fix related unit tests (Azure#3690)
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma authored and penggu committed Oct 28, 2020
1 parent 7a69b7c commit 7470ab9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/api/vlabs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (a *Properties) validateAgentPoolProfiles(isUpdate bool) error {
if agentPoolProfile.AvailabilityProfile == AvailabilitySet {
return errors.Errorf("You have enabled VMSS node public IP in agent pool %s, but you did not specify VMSS", agentPoolProfile.Name)
}
if a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku != BasicLoadBalancerSku {
if !strings.EqualFold(a.OrchestratorProfile.KubernetesConfig.LoadBalancerSku, BasicLoadBalancerSku) {
return errors.Errorf("You have enabled VMSS node public IP in agent pool %s, but you did not specify Basic Load Balancer SKU", agentPoolProfile.Name)
}
}
Expand Down
43 changes: 35 additions & 8 deletions pkg/api/vlabs/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3392,13 +3392,14 @@ func ExampleProperties_validateZones() {

func TestProperties_ValidateLoadBalancer(t *testing.T) {
tests := []struct {
name string
orchestratorRelease string
loadBalancerSku string
masterProfile *MasterProfile
agentProfiles []*AgentPoolProfile
expectedErr bool
expectedErrStr string
name string
orchestratorRelease string
loadBalancerSku string
masterProfile *MasterProfile
agentProfiles []*AgentPoolProfile
excludeMasterFromStandardLB bool
expectedErr bool
expectedErrStr string
}{
{
name: "lowercase basic LB",
Expand All @@ -3410,6 +3411,15 @@ func TestProperties_ValidateLoadBalancer(t *testing.T) {
VMSize: "Standard_DS2_v2",
AvailabilityProfile: VirtualMachineScaleSets,
},
agentProfiles: []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_DS2_v2",
Count: 4,
AvailabilityProfile: VirtualMachineScaleSets,
EnableVMSSNodePublicIP: to.BoolPtr(true),
},
},
},
{
name: "Basic LB",
Expand All @@ -3433,6 +3443,19 @@ func TestProperties_ValidateLoadBalancer(t *testing.T) {
AvailabilityProfile: VirtualMachineScaleSets,
},
},
{
name: "Standard LB without master excluded",
orchestratorRelease: "1.15",
loadBalancerSku: StandardLoadBalancerSku,
masterProfile: &MasterProfile{
Count: 3,
DNSPrefix: "foo",
VMSize: "Standard_DS2_v2",
AvailabilityProfile: VirtualMachineScaleSets,
},
expectedErr: true,
expectedErrStr: "standard loadBalancerSku should exclude master nodes. Please set KubernetesConfig \"ExcludeMasterFromStandardLB\" to \"true\"",
},
{
name: "Standard LB",
orchestratorRelease: "1.15",
Expand All @@ -3443,6 +3466,7 @@ func TestProperties_ValidateLoadBalancer(t *testing.T) {
VMSize: "Standard_DS2_v2",
AvailabilityProfile: VirtualMachineScaleSets,
},
excludeMasterFromStandardLB: true,
},
{
name: "empty string LB value",
Expand Down Expand Up @@ -3479,7 +3503,8 @@ func TestProperties_ValidateLoadBalancer(t *testing.T) {
cs.Properties.AgentPoolProfiles = test.agentProfiles
cs.Properties.OrchestratorProfile.OrchestratorRelease = test.orchestratorRelease
cs.Properties.OrchestratorProfile.KubernetesConfig = &KubernetesConfig{
LoadBalancerSku: test.loadBalancerSku,
LoadBalancerSku: test.loadBalancerSku,
ExcludeMasterFromStandardLB: to.BoolPtr(test.excludeMasterFromStandardLB),
}

err := cs.Validate(false)
Expand All @@ -3491,6 +3516,8 @@ func TestProperties_ValidateLoadBalancer(t *testing.T) {
t.Errorf("expected error with message : %s, but got : %s", test.expectedErrStr, err.Error())
}
}
} else if err != nil {
t.Error(err)
}
})
}
Expand Down

0 comments on commit 7470ab9

Please sign in to comment.