From 637285f5fa53b6e5c979951fdae4b2846911b908 Mon Sep 17 00:00:00 2001 From: Cecile Robert-Michon Date: Wed, 5 Dec 2018 15:09:21 -0800 Subject: [PATCH] [BUG] orchestratorVersion should not get changed for ACS scale apiVersion 2017-07-01 (#4346) --- pkg/api/apiloader.go | 2 +- pkg/api/apiloader_test.go | 9 +++++++++ pkg/api/convertertoapi.go | 15 +++++++++------ pkg/api/convertertoapi_test.go | 8 ++++---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/api/apiloader.go b/pkg/api/apiloader.go index c474849bfb..e1def86380 100644 --- a/pkg/api/apiloader.go +++ b/pkg/api/apiloader.go @@ -177,7 +177,7 @@ func (a *Apiloader) LoadContainerService( if e := containerService.Properties.Validate(isUpdate); validate && e != nil { return nil, e } - unversioned := ConvertV20170701ContainerService(containerService) + unversioned := ConvertV20170701ContainerService(containerService, isUpdate) if curOrchVersion != "" && (containerService.Properties.OrchestratorProfile == nil || containerService.Properties.OrchestratorProfile.OrchestratorVersion == "") { diff --git a/pkg/api/apiloader_test.go b/pkg/api/apiloader_test.go index cf4c2b4e61..6a8a941966 100644 --- a/pkg/api/apiloader_test.go +++ b/pkg/api/apiloader_test.go @@ -93,6 +93,15 @@ func TestLoadContainerServiceFromFile(t *testing.T) { t.Errorf("Failed to set orcherstator version to windows default when it is not set in the json API v20170131, got %s but expected %s", containerService.Properties.OrchestratorProfile.OrchestratorVersion, common.GetDefaultKubernetesVersion(true)) } + // Test ACS scale scenario + existingContainerService.Properties.OrchestratorProfile.OrchestratorVersion = "1.8.12" + containerService, _, err = apiloader.LoadContainerServiceFromFile("../acsengine/testdata/v20170701/kubernetes.json", true, true, existingContainerService) + if err != nil { + t.Error(err.Error()) + } + if containerService.Properties.OrchestratorProfile.OrchestratorVersion != "1.8.12" { + t.Errorf("Failed to set orcherstator version when it is set in the json, expected 1.8.12 but got %s", containerService.Properties.OrchestratorProfile.OrchestratorVersion) + } } func TestLoadContainerServiceForAgentPoolOnlyCluster(t *testing.T) { diff --git a/pkg/api/convertertoapi.go b/pkg/api/convertertoapi.go index 55300bc030..83cae4fad6 100644 --- a/pkg/api/convertertoapi.go +++ b/pkg/api/convertertoapi.go @@ -79,7 +79,7 @@ func ConvertV20170131ContainerService(v20170131 *v20170131.ContainerService) *Co } // ConvertV20170701ContainerService converts a v20170701 ContainerService to an unversioned ContainerService -func ConvertV20170701ContainerService(v20170701 *v20170701.ContainerService) *ContainerService { +func ConvertV20170701ContainerService(v20170701 *v20170701.ContainerService, isUpdate bool) *ContainerService { c := &ContainerService{} c.ID = v20170701.ID c.Location = helpers.NormalizeAzureRegion(v20170701.Location) @@ -94,7 +94,7 @@ func ConvertV20170701ContainerService(v20170701 *v20170701.ContainerService) *Co } c.Type = v20170701.Type c.Properties = &Properties{} - convertV20170701Properties(v20170701.Properties, c.Properties) + convertV20170701Properties(v20170701.Properties, c.Properties, isUpdate) return c } @@ -300,12 +300,12 @@ func convertV20170131Properties(v20170131 *v20170131.Properties, api *Properties } } -func convertV20170701Properties(v20170701 *v20170701.Properties, api *Properties) { +func convertV20170701Properties(v20170701 *v20170701.Properties, api *Properties, isUpdate bool) { api.ProvisioningState = ProvisioningState(v20170701.ProvisioningState) if v20170701.OrchestratorProfile != nil { api.OrchestratorProfile = &OrchestratorProfile{} - convertV20170701OrchestratorProfile(v20170701.OrchestratorProfile, api.OrchestratorProfile, v20170701.HasWindows()) + convertV20170701OrchestratorProfile(v20170701.OrchestratorProfile, api.OrchestratorProfile, isUpdate, v20170701.HasWindows()) } if v20170701.MasterProfile != nil { api.MasterProfile = &MasterProfile{} @@ -564,7 +564,7 @@ func convertV20170131OrchestratorProfile(v20170131 *v20170131.OrchestratorProfil } } -func convertV20170701OrchestratorProfile(v20170701cs *v20170701.OrchestratorProfile, api *OrchestratorProfile, hasWindows bool) { +func convertV20170701OrchestratorProfile(v20170701cs *v20170701.OrchestratorProfile, api *OrchestratorProfile, isUpdate, hasWindows bool) { if v20170701cs.OrchestratorType == v20170701.DockerCE { api.OrchestratorType = SwarmMode } else { @@ -573,7 +573,10 @@ func convertV20170701OrchestratorProfile(v20170701cs *v20170701.OrchestratorProf switch api.OrchestratorType { case Kubernetes: - api.OrchestratorVersion = common.GetSupportedKubernetesVersion(v20170701cs.OrchestratorVersion, hasWindows) + api.OrchestratorVersion = common.RationalizeReleaseAndVersion(Kubernetes, "", v20170701cs.OrchestratorVersion, isUpdate, hasWindows) + if api.OrchestratorVersion == "" { + api.OrchestratorVersion = common.GetDefaultKubernetesVersion(hasWindows) + } case DCOS: switch v20170701cs.OrchestratorVersion { case common.DCOSVersion1Dot10Dot0, common.DCOSVersion1Dot9Dot0, common.DCOSVersion1Dot8Dot8: diff --git a/pkg/api/convertertoapi_test.go b/pkg/api/convertertoapi_test.go index 4bd2c2baba..13ec48f0a8 100644 --- a/pkg/api/convertertoapi_test.go +++ b/pkg/api/convertertoapi_test.go @@ -88,7 +88,7 @@ func TestOrchestratorVersion(t *testing.T) { }, }, } - cs := ConvertV20170701ContainerService(v20170701cs) + cs := ConvertV20170701ContainerService(v20170701cs, false) if cs.Properties.OrchestratorProfile.OrchestratorVersion != common.GetDefaultKubernetesVersion(false) { t.Fatalf("incorrect OrchestratorVersion '%s'", cs.Properties.OrchestratorProfile.OrchestratorVersion) } @@ -97,12 +97,12 @@ func TestOrchestratorVersion(t *testing.T) { Properties: &v20170701.Properties{ OrchestratorProfile: &v20170701.OrchestratorProfile{ OrchestratorType: v20170701.Kubernetes, - OrchestratorVersion: "1.7.15", + OrchestratorVersion: "1.7.14", }, }, } - cs = ConvertV20170701ContainerService(v20170701cs) - if cs.Properties.OrchestratorProfile.OrchestratorVersion != "1.7.15" { + cs = ConvertV20170701ContainerService(v20170701cs, true) + if cs.Properties.OrchestratorProfile.OrchestratorVersion != "1.7.14" { t.Fatalf("incorrect OrchestratorVersion '%s'", cs.Properties.OrchestratorProfile.OrchestratorVersion) } // test vlabs