Skip to content

Commit

Permalink
Merge pull request #297 from mjura/main-check-duplication
Browse files Browse the repository at this point in the history
Check for duplicate names for NodePools
  • Loading branch information
mjura authored Oct 26, 2023
2 parents 4b1dc2f + 9da2841 commit 75c3dde
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions controller/aks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,16 @@ func (h *Handler) validateConfig(config *aksv1.AKSClusterConfig) error {
return fmt.Errorf(cannotBeNilError, "dnsPrefix", config.Spec.ClusterName)
}

nodeP := map[string]bool{}
systemMode := false
for _, np := range config.Spec.NodePools {
if np.Name == nil {
return fmt.Errorf(cannotBeNilError, "NodePool.Name", config.Spec.ClusterName)
}
if nodeP[*np.Name] {
return fmt.Errorf("NodePool names must be unique within the [%s] cluster to avoid duplication", config.Spec.ClusterName)
}
nodeP[*np.Name] = true
if np.Name == nil {
return fmt.Errorf(cannotBeNilError, "NodePool.Name", config.Spec.ClusterName)
}
Expand Down
18 changes: 17 additions & 1 deletion controller/aks-cluster-config-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var _ = Describe("validateConfig", func() {
DNSPrefix: to.StringPtr("test"),
NodePools: []aksv1.AKSNodePool{
{
Name: to.StringPtr("test"),
Name: to.StringPtr("test1"),
Count: to.Int32Ptr(1),
MaxPods: to.Int32Ptr(1),
VMSize: "test",
Expand All @@ -242,6 +242,16 @@ var _ = Describe("validateConfig", func() {
Mode: "System",
OsType: "test",
},
{
Name: to.StringPtr("test2"),
Count: to.Int32Ptr(1),
MaxPods: to.Int32Ptr(1),
VMSize: "test",
OsDiskSizeGB: to.Int32Ptr(1),
OsDiskType: "test",
Mode: "User",
OsType: "test",
},
},
NetworkPlugin: to.StringPtr(string(containerservice.Azure)),
NetworkPolicy: to.StringPtr(string(containerservice.NetworkPolicyAzure)),
Expand Down Expand Up @@ -352,6 +362,12 @@ var _ = Describe("validateConfig", func() {
Expect(handler.validateConfig(aksConfig)).NotTo(Succeed())
})

It("should fail to validate aks config if node pool name is duplicated", func() {
aksConfig.Spec.NodePools[0].Name = to.StringPtr("test")
aksConfig.Spec.NodePools[1].Name = to.StringPtr("test")
Expect(handler.validateConfig(aksConfig)).NotTo(Succeed())
})

It("should fail to validate aks config if node pool count is empty", func() {
aksConfig.Spec.NodePools[0].Count = nil
Expect(handler.validateConfig(aksConfig)).NotTo(Succeed())
Expand Down

0 comments on commit 75c3dde

Please sign in to comment.