Skip to content

Commit

Permalink
Avoid adding faultDomain to ZoneSet (kanisterio#619)
Browse files Browse the repository at this point in the history
* Avoid adding faultDomain to ZoneSet

* add unit test

* lint fix

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
SupriyaKasten and mergify[bot] authored Mar 11, 2020
1 parent dbb45c8 commit 598960e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pkg/blockstorage/zone/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ func NodeZonesAndRegion(ctx context.Context, cli kubernetes.Interface) (map[stri
regionSet := make(map[string]struct{})
for _, n := range ns {
zone := kubevolume.GetZoneFromNode(n)
if zone != "" {
// make sure it is not a faultDomain
// For Example: all non-zonal cluster nodes in azure get addigned a faultDomain(0/1)
// for "failure-domain.beta.kubernetes.io/zone" label
if len(zone) > 1 {
zoneSet[zone] = struct{}{}
}
region := kubevolume.GetRegionFromNode(n)
Expand Down
30 changes: 26 additions & 4 deletions pkg/blockstorage/zone/zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,39 @@ func (s ZoneSuite) TestNodeZoneAndRegionAD(c *C) {
},
},
}
// error nodes
// non-zonal node (FaultDomain)
node4 := &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node4",
Labels: map[string]string{kubevolume.PVRegionLabelName: "us-west2", kubevolume.PVZoneLabelName: "us-west2-4"},
Labels: map[string]string{kubevolume.PVRegionLabelName: "westus", kubevolume.PVZoneLabelName: "0"},
},
Status: v1.NodeStatus{
Conditions: []v1.NodeCondition{
v1.NodeCondition{
Status: "False",
Status: "True",
Type: "Ready",
},
},
},
}
// error nodes
node5 := &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node5",
Labels: map[string]string{kubevolume.PVRegionLabelName: "us-west2", kubevolume.PVZoneLabelName: "us-west2-4"},
},
Status: v1.NodeStatus{
Conditions: []v1.NodeCondition{
v1.NodeCondition{
Status: "False",
Type: "Ready",
},
},
},
}
node6 := &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node6",
Labels: map[string]string{kubevolume.PVRegionLabelName: "us-west2", kubevolume.PVZoneLabelName: "us-west2-5"},
},
Spec: v1.NodeSpec{
Expand All @@ -305,8 +320,15 @@ func (s ZoneSuite) TestNodeZoneAndRegionAD(c *C) {
c.Assert(reflect.DeepEqual(z, expectedZone), Equals, true)
c.Assert(r, Equals, "westus2")

// non-zonal cluster test
cli = fake.NewSimpleClientset(node4)
z, r, err = NodeZonesAndRegion(ctx, cli)
c.Assert(err, IsNil)
c.Assert(len(z) == 0, Equals, true)
c.Assert(r, Equals, "westus")

// error case
cli = fake.NewSimpleClientset(node4, node5)
cli = fake.NewSimpleClientset(node5, node6)
_, _, err = NodeZonesAndRegion(ctx, cli)
c.Assert(err, NotNil)
}
Expand Down

0 comments on commit 598960e

Please sign in to comment.