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

feat: abort/warn if apimodel contains properties not supported by Azure Stack #2717

Merged
merged 1 commit into from
Feb 13, 2020
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
26 changes: 26 additions & 0 deletions pkg/api/vlabs/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (a *Properties) validate(isUpdate bool) error {
return e
}

if e := a.validateAzureStackSupport(); e != nil {
return e
}
return nil
}

Expand Down Expand Up @@ -1794,3 +1797,26 @@ func validateDependenciesLocation(dependenciesLocation DependenciesLocation, dep
}
return false
}

// validateAzureStackSupport logs a warning if apimodel contains preview features and returns an error if a property is not supported on Azure Stack clouds
func (a *Properties) validateAzureStackSupport() error {
if a.OrchestratorProfile.OrchestratorType == Kubernetes && a.IsAzureStackCloud() {
networkPlugin := a.OrchestratorProfile.KubernetesConfig.NetworkPlugin
if networkPlugin == "azure" || networkPlugin == "" {
log.Warnf("NetworkPlugin 'azure' is a private preview feature on Azure Stack clouds")
}
if networkPlugin != "azure" && networkPlugin != "kubenet" && networkPlugin != "" {
return errors.Errorf("kubernetesConfig.networkPlugin '%s' is not supported on Azure Stack clouds", networkPlugin)
}
if a.MasterProfile.AvailabilityProfile != AvailabilitySet {
return errors.Errorf("masterProfile.availabilityProfile should be set to '%s' on Azure Stack clouds", AvailabilitySet)
}
for _, agentPool := range a.AgentPoolProfiles {
pool := agentPool
if pool.AvailabilityProfile != AvailabilitySet {
return errors.Errorf("agentPoolProfiles[%s].availabilityProfile should be set to '%s' on Azure Stack clouds", pool.Name, AvailabilitySet)
}
}
}
return nil
}
75 changes: 75 additions & 0 deletions pkg/api/vlabs/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4440,3 +4440,78 @@ func TestValidateAgentPoolProfilesImageRef(t *testing.T) {
})
}
}

func TestValidateAzureStackSupport(t *testing.T) {
tests := []struct {
name string
networkPlugin string
masterAvailability string
agentAvailability string
expectedErr error
}{
{
name: "AzureStack supports the kubenet network plugin",
networkPlugin: "kubenet",
masterAvailability: AvailabilitySet,
agentAvailability: AvailabilitySet,
expectedErr: nil,
},
{
name: "AzureStack supports for the azure network plugin is in preview",
networkPlugin: "azure",
masterAvailability: AvailabilitySet,
agentAvailability: AvailabilitySet,
expectedErr: nil,
},
{
name: "AzureStack only supports kubenet and azure network plugins",
networkPlugin: NetworkPluginFlannel,
masterAvailability: AvailabilitySet,
agentAvailability: AvailabilitySet,
expectedErr: errors.New("kubernetesConfig.networkPlugin 'flannel' is not supported on Azure Stack clouds"),
},
{
name: "AzureStack does not support VMSS on the master pool",
networkPlugin: "",
masterAvailability: VirtualMachineScaleSets,
agentAvailability: VirtualMachineScaleSets,
expectedErr: errors.New("masterProfile.availabilityProfile should be set to 'AvailabilitySet' on Azure Stack clouds"),
},
{
name: "AzureStack does not support VMSS on the agent pools",
networkPlugin: "kubenet",
masterAvailability: AvailabilitySet,
agentAvailability: VirtualMachineScaleSets,
expectedErr: errors.New("agentPoolProfiles[agentpool].availabilityProfile should be set to 'AvailabilitySet' on Azure Stack clouds"),
},
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
cs := getK8sDefaultContainerService(false)
cs.Properties.CustomCloudProfile = &CustomCloudProfile{
PortalURL: "https://portal.westus.contoso.com",
}
cs.Properties.OrchestratorProfile.KubernetesConfig = &KubernetesConfig{}
if test.networkPlugin != "" {
cs.Properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = test.networkPlugin
}
if test.masterAvailability != "" {
cs.Properties.MasterProfile.AvailabilityProfile = test.masterAvailability
}
if test.agentAvailability != "" {
for _, agentPool := range cs.Properties.AgentPoolProfiles {
pool := agentPool
pool.AvailabilityProfile = test.agentAvailability
break
}
}
if err := cs.Validate(false); !helpers.EqualError(err, test.expectedErr) {
t.Logf("scenario %q", test.name)
t.Errorf("expected error: %v, got: %v", test.expectedErr, err)
}
})
}
}
1 change: 1 addition & 0 deletions pkg/engine/testdata/azurestack/kubernetes.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"distro": "ubuntu",
"osDiskSizeGB": 200,
"count": 3,
"availabilityProfile": "AvailabilitySet",
"vmSize": "Standard_D2_v2"
},
"agentPoolProfiles": [
Expand Down