Skip to content

Commit

Permalink
Merge branch 'master' into feature/ignoreDrainFailure
Browse files Browse the repository at this point in the history
Signed-off-by: sshah31 <[email protected]>
Signed-off-by: shailshah9 <[email protected]>
  • Loading branch information
shailshah9 committed Nov 8, 2021
2 parents 00e12d4 + edf7b7b commit 3f3e0ab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/reaper/nodereaper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,17 @@ func getNodeAgeMinutes(n *v1.Node) int {
}

func getNodeRegion(n *v1.Node) string {
providerID := n.Spec.ProviderID
splitProviderID := strings.Split(providerID, "/")
regionFullName := splitProviderID[len(splitProviderID)-2]
regionName := regionFullName[:len(regionFullName)-1]
var regionName = ""
labels := n.GetLabels()
if labels != nil {
regionName = labels["topology.kubernetes.io/region"]
}
if regionName == "" {
providerID := n.Spec.ProviderID
splitProviderID := strings.Split(providerID, "/")
regionFullName := splitProviderID[len(splitProviderID)-2]
regionName = regionFullName[:len(regionFullName)-1]
}
return regionName
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/reaper/nodereaper/nodereaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,30 @@ func TestProviderIDParser(t *testing.T) {
}
}

func TestRegionDetection(t *testing.T) {
// TestDescription: Region value in annotation should take priority over providerId
reaper := newFakeReaperContext()
reaper.AsgValidation = false
reaper.DryRun = true

node := v1.Node{
Spec: v1.NodeSpec{
ProviderID: "aws:///us-west-2a/i-1234567890abcdef0",
},
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{
"topology.kubernetes.io/region": "us-east-2",
}},
}

providerRegion := getNodeRegion(&node)
expectedRegion := "us-east-2"

if providerRegion != expectedRegion {
t.Fatalf("expected Region: %v, got: %v", expectedRegion, providerRegion)
}
}


func TestSkipLabelReaper(t *testing.T) {
reaper := newFakeReaperContext()
reaper.ReapUnknown = true
Expand Down

0 comments on commit 3f3e0ab

Please sign in to comment.