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

Commit

Permalink
Add validation when PodCidr is set in the Azure CNI case. (#3562)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunSun17 authored and jackfrancis committed Jul 26, 2018
1 parent ed2b959 commit 1321003
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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

0 comments on commit 1321003

Please sign in to comment.