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

Commit

Permalink
updating api model to make sure not setting autoscalePool doesn't alw…
Browse files Browse the repository at this point in the history
…ays set it false, and adding unit test
  • Loading branch information
JackQuincy committed Jul 11, 2018
1 parent 5a128e7 commit 9040946
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
47 changes: 47 additions & 0 deletions pkg/api/agentPoolOnlyApi/v20180331/apiloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
})
})
})
2 changes: 1 addition & 1 deletion pkg/api/agentPoolOnlyApi/v20180331/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/agentPoolOnlyApi/vlabs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9040946

Please sign in to comment.