From 06dd814b4fcbf86d22f99c2ee75a286c23c2a785 Mon Sep 17 00:00:00 2001 From: Matt Boersma Date: Wed, 28 Feb 2018 14:50:14 -0700 Subject: [PATCH] Allow a default k8s version for loading agentpool-only clusters (#2357) The defaultKubernetesVersion argument will be used if Properties.KubernetesVersion was empty. --- pkg/api/apiloader.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/api/apiloader.go b/pkg/api/apiloader.go index 9ad14c19ef..1e3d8e3712 100644 --- a/pkg/api/apiloader.go +++ b/pkg/api/apiloader.go @@ -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 }