diff --git a/pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go b/pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go index a725d4a0d0..eb6c704a2d 100644 --- a/pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go +++ b/pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go @@ -4,6 +4,7 @@ import ( "github.com/Azure/acs-engine/pkg/api" "github.com/Azure/acs-engine/pkg/api/agentPoolOnlyApi/v20180331" "github.com/Azure/acs-engine/pkg/api/common" + "github.com/Azure/acs-engine/pkg/helpers" "github.com/Azure/acs-engine/pkg/i18n" . "github.com/Azure/acs-engine/pkg/test" "github.com/leonelquinteros/gotext" @@ -380,4 +381,50 @@ var _ = Describe("v20180331 test suite", func() { Expect(len(cs2.Properties.AgentPoolProfiles)).To(Equal(1)) }) }) + + Context("when autoscale properties are set they make it into the unversioned model", func() { + It("should migrate fields properly", func() { + model := v20180331.ManagedCluster{ + Name: "myaks", + Properties: &v20180331.Properties{ + DNSPrefix: "myaks", + KubernetesVersion: k8sVersions[0], + AgentPoolProfiles: []*v20180331.AgentPoolProfile{ + { + Name: "agentpool1", + Count: 3, + MinCount: helpers.PointerToInt(3), + MaxCount: helpers.PointerToInt(10), + AutoscalePool: helpers.PointerToBool(true), + VMSize: "Standard_DS2_v2", + OSDiskSizeGB: 0, + StorageProfile: "ManagedDisk", + }, + }, + ServicePrincipalProfile: &v20180331.ServicePrincipalProfile{ + ClientID: "clientID", + Secret: "clientSecret", + }, + }, + } + + modelString, _ := json.Marshal(model) + cs, sshAutoGenerated, err := apiloader.LoadContainerServiceForAgentPoolOnlyCluster([]byte(modelString), "2018-03-31", false, false, defaultK8sVersion, nil) + Expect(err).To(BeNil()) + Expect(sshAutoGenerated).To(BeTrue()) + Expect(cs.Properties.MasterProfile).To(BeNil()) + Expect(cs.Properties.LinuxProfile).NotTo(BeNil()) + Expect(cs.Properties.OrchestratorProfile).NotTo(BeNil()) + Expect(cs.Properties.OrchestratorProfile.OrchestratorVersion).To(Equal(k8sVersions[0])) + Expect(cs.Properties.HostedMasterProfile).NotTo(BeNil()) + Expect(cs.Properties.HostedMasterProfile.DNSPrefix).To(Equal(model.Properties.DNSPrefix)) + Expect(cs.Properties.AgentPoolProfiles).NotTo(BeNil()) + Expect(len(cs.Properties.AgentPoolProfiles)).To(Equal(1)) + Expect(cs.Properties.AgentPoolProfiles[0].Name).To(Equal(model.Properties.AgentPoolProfiles[0].Name)) + Expect(cs.Properties.AgentPoolProfiles[0].Count).To(Equal(model.Properties.AgentPoolProfiles[0].Count)) + Expect(*cs.Properties.AgentPoolProfiles[0].MaxCount).To(Equal(10)) + Expect(*cs.Properties.AgentPoolProfiles[0].MinCount).To(Equal(3)) + Expect(*cs.Properties.AgentPoolProfiles[0].AutoscalePool).To(Equal(true)) + }) + }) }) diff --git a/pkg/api/agentPoolOnlyApi/v20180331/types.go b/pkg/api/agentPoolOnlyApi/v20180331/types.go index cc9fd3c783..9fe70f07cf 100644 --- a/pkg/api/agentPoolOnlyApi/v20180331/types.go +++ b/pkg/api/agentPoolOnlyApi/v20180331/types.go @@ -185,7 +185,7 @@ type AgentPoolProfile struct { MaxPods *int `json:"maxPods,omitempty"` MaxCount *int `json:"maxCount,omitempty"` MinCount *int `json:"minCount,omitempty"` - AutoscalePool bool `json:"autoscalePool,omitempty"` + AutoscalePool *bool `json:"autoscalePool,omitempty"` // OSType is the operating system type for agents // Set as nullable to support backward compat because diff --git a/pkg/api/agentPoolOnlyApi/vlabs/types.go b/pkg/api/agentPoolOnlyApi/vlabs/types.go index c4d7d449f2..2411d95a23 100644 --- a/pkg/api/agentPoolOnlyApi/vlabs/types.go +++ b/pkg/api/agentPoolOnlyApi/vlabs/types.go @@ -131,7 +131,7 @@ type AgentPoolProfile struct { VnetSubnetID string `json:"vnetSubnetID,omitempty"` MaxCount *int `json:"maxCount,omitempty"` MinCount *int `json:"minCount,omitempty"` - AutoscalePool bool `json:"autoscalePool,omitempty"` + AutoscalePool *bool `json:"autoscalePool,omitempty"` // OSType is the operating system type for agents // Set as nullable to support backward compat because diff --git a/pkg/api/types.go b/pkg/api/types.go index 6bdd6f4c50..5506eafb16 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -451,7 +451,7 @@ type AgentPoolProfile struct { ImageRef *ImageReference `json:"imageReference,omitempty"` MaxCount *int `json:"maxCount,omitempty"` MinCount *int `json:"minCount,omitempty"` - AutoscalePool bool `json:"autoscalePool,omitempty"` + AutoscalePool *bool `json:"autoscalePool,omitempty"` } // AgentPoolProfileRole represents an agent role diff --git a/pkg/helpers/helpers.go b/pkg/helpers/helpers.go index 8a20064e90..d9e3132f4d 100644 --- a/pkg/helpers/helpers.go +++ b/pkg/helpers/helpers.go @@ -63,6 +63,12 @@ func PointerToBool(b bool) *bool { return &p } +// PointerToInt returns a pointer to a int +func PointerToInt(i int) *int { + p := i + return &p +} + // CreateSSH creates an SSH key pair. func CreateSSH(rg io.Reader, s *i18n.Translator) (privateKey *rsa.PrivateKey, publicKeyString string, err error) { privateKey, err = rsa.GenerateKey(rg, SSHKeySize)