Allow a default k8s version for loading agentpool-only clusters
The defaultKubernetesVersion argument will be used if
Properties.KubernetesVersion was empty.
@@ -44,7 +44,7 @@ func (a *Apiloader) DeserializeContainerService(contents []byte, validate, isUpd
if service == nil || err != nil {
if isAgentPoolOnlyClusterJSON(contents) {
log.Info("No masterProfile: interpreting API model as agent pool only")
- service, err := a.LoadContainerServiceForAgentPoolOnlyCluster(contents, version, validate, isUpdate)
+ service, err := a.LoadContainerServiceForAgentPoolOnlyCluster(contents, version, validate, isUpdate, "")
if service == nil || err != nil {
log.Infof("Error returned by LoadContainerServiceForAgentPoolOnlyCluster: %+v", err)
}
@@ -184,7 +184,7 @@ func (a *Apiloader) LoadContainerService(
}
// LoadContainerServiceForAgentPoolOnlyCluster loads an ACS Cluster API Model, validates it, and returns the unversioned representation
-func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(contents []byte, version string, validate, isUpdate bool) (*ContainerService, error) {
+func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(contents []byte, version string, validate, isUpdate bool, defaultKubernetesVersion string) (*ContainerService, error) {
switch version {
case v20170831.APIVersion:
managedCluster := &v20170831.ManagedCluster{}
@@ -195,6 +195,13 @@ func (a *Apiloader) LoadContainerServiceForAgentPoolOnlyCluster(contents []byte,
if len(managedCluster.Properties.KubernetesVersion) > 0 && !common.AllKubernetesSupportedVersions[managedCluster.Properties.KubernetesVersion] {
return nil, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", managedCluster.Properties.KubernetesVersion)
}
+ // use defaultKubernetesVersion arg if no version was supplied in the request contents
+ if managedCluster.Properties.KubernetesVersion == "" && defaultKubernetesVersion != "" {
+ if !common.AllKubernetesSupportedVersions[defaultKubernetesVersion] {
+ return nil, a.Translator.Errorf("The selected orchestrator version '%s' is not supported", defaultKubernetesVersion)
+ }
+ managedCluster.Properties.KubernetesVersion = defaultKubernetesVersion
+ }
if e := managedCluster.Properties.Validate(); validate && e != nil {
return nil, e
}
