Skip to content

Commit 3815094

Browse files
authored
Merge pull request #50 from aws/fix-worker-zone-assignment-bug
Fix a bug in ZoneStatusMap.GetByName
2 parents 660d029 + 9c2cbb1 commit 3815094

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

api/v1beta1/cloudstackcluster_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (zones ZoneStatusMap) GetOne() *Zone {
6767
// GetByName fetches a zone by name if present in the map of zone statuses.
6868
// Needed as there's no short way to do this.
6969
func (zones ZoneStatusMap) GetByName(name string) *Zone {
70-
for zoneName, zone := range zones {
71-
if zoneName == name {
70+
for _, zone := range zones {
71+
if zone.Name == name {
7272
return &zone
7373
}
7474
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1_test
18+
19+
import (
20+
capcv1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
21+
"github.com/aws/cluster-api-provider-cloudstack/test/dummies"
22+
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/gomega"
24+
)
25+
26+
var _ = Describe("CloudStackCluster types", func() {
27+
28+
Context("When retrieving a zone from ZoneStatusMap using GetOne", func() {
29+
It("Should return nil if ZoneStatusMap is empty", func() {
30+
zones := capcv1.ZoneStatusMap{}
31+
Ω(zones.GetOne()).Should(BeNil())
32+
})
33+
34+
It("Should return a zone if ZoneStatusMap is not empty", func() {
35+
zones := capcv1.ZoneStatusMap{dummies.Zone1.ID: dummies.Zone1}
36+
Ω(zones.GetOne()).ShouldNot(BeNil())
37+
})
38+
})
39+
40+
Context("When retrieving a zone from ZoneStatusMap using GetByName", func() {
41+
It("Should return nil if ZoneStatusMap is empty", func() {
42+
zones := capcv1.ZoneStatusMap{}
43+
Ω(zones.GetByName(dummies.Zone1.Name)).Should(BeNil())
44+
})
45+
46+
It("Should return a zone if ZoneStatusMap has a zone having the name passed into GetByName", func() {
47+
zones := capcv1.ZoneStatusMap{dummies.Zone1.ID: dummies.Zone1}
48+
Ω(zones.GetByName(dummies.Zone1.Name)).ShouldNot(BeNil())
49+
})
50+
51+
It("Should return nil if ZoneStatusMap does not have a zone having the name passed into GetByName", func() {
52+
zones := capcv1.ZoneStatusMap{dummies.Zone2.ID: dummies.Zone2}
53+
Ω(zones.GetByName(dummies.Zone1.Name)).Should(BeNil())
54+
})
55+
})
56+
})

0 commit comments

Comments
 (0)