Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Add validation when PodCidr is set in the Azure CNI case. #3562

Merged
merged 1 commit into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/api/agentPoolOnlyApi/v20180331/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "github.com/pkg/errors"
// ErrorInvalidNetworkProfile error
var ErrorInvalidNetworkProfile = errors.New("ServiceCidr, DNSServiceIP, DockerBridgeCidr should all be empty or neither should be empty")

// ErrorPodCidrNotSetableInAzureCNI error
var ErrorPodCidrNotSetableInAzureCNI = errors.New("PodCidr should not be set when network plugin is set to Azure")

// ErrorInvalidNetworkPlugin error
var ErrorInvalidNetworkPlugin = errors.New("Network plugin should be either Azure or Kubenet")

Expand Down
5 changes: 5 additions & 0 deletions pkg/api/agentPoolOnlyApi/v20180331/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func validateVNET(a *Properties) error {
} else {
return ErrorInvalidNetworkProfile
}

// PodCidr should not be set for Azure CNI
if n.NetworkPlugin == Azure && n.PodCidr != "" {
return ErrorPodCidrNotSetableInAzureCNI
}
default:
return ErrorInvalidNetworkPlugin
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/api/agentPoolOnlyApi/v20180331/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ func TestValidateVNET(t *testing.T) {
t.Errorf("Failed to test validate VNET: expected %s but got %s", ErrorInvalidNetworkProfile, err.Error())
}

// network profile has NetworkPlugin set to azure and PodCidr set, should fail
n = &NetworkProfile{
NetworkPlugin: NetworkPlugin("azure"),
PodCidr: "a.b.c.d",
}

p = []*AgentPoolProfile{
{
VnetSubnetID: vnetSubnetID1,
MaxPods: &maxPods1,
},
{
VnetSubnetID: vnetSubnetID2,
MaxPods: &maxPods2,
},
}

a = &Properties{
NetworkProfile: n,
AgentPoolProfiles: p,
}

if err := validateVNET(a); err != ErrorPodCidrNotSetableInAzureCNI {
if err == nil {
t.Errorf("Failed to test validate VNET: expected %s but got no error", ErrorPodCidrNotSetableInAzureCNI)
}
t.Errorf("Failed to test validate VNET: expected %s but got %s", ErrorPodCidrNotSetableInAzureCNI, err.Error())
}

// NetworkPlugin is not azure or kubenet
n = &NetworkProfile{
NetworkPlugin: NetworkPlugin("none"),
Expand Down