diff --git a/main.go b/main.go index b0c96bf..b9a05ea 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { "node.vexxhost.com/product": slug.Make(product.Name), } - if checkComputeNode() { + if CheckComputeNode(nodeName) { labels["node-role.openstack.org"] = "compute" } @@ -91,26 +91,15 @@ func main() { } } -// checkComputeNode checks if the current node is a compute node. -func checkComputeNode() bool { - - hostname, err := os.Hostname() - if err != nil { - log.Fatal(err.Error()) - } - // Now there is only one check logic for now using hostname - return CheckComputeSubstring(hostname) -} - -// checkComputeSubstring checks if the string includes compute substring. -func CheckComputeSubstring(label string) bool { +// checkComputeSubstring checks if the node name includes compute substring. +func CheckComputeNode(nodeName string) bool { compute_tag := []string{ "kvm", "compute", } for _, sub := range compute_tag { - if strings.Contains(label, sub) { + if strings.Contains(nodeName, sub) { return true } } diff --git a/units_test.go b/units_test.go index 85dce64..20f4c9c 100644 --- a/units_test.go +++ b/units_test.go @@ -6,28 +6,28 @@ import ( "github.com/stretchr/testify/assert" ) -func assertCheckComputeSubstring(t *testing.T, label string, expected bool) { - res := CheckComputeSubstring(label) +func assertCheckComputeNode(t *testing.T, label string, expected bool) { + res := CheckComputeNode(label) assert.Equal(t, expected, res) } func TestCheckComputeSubstringWithkvmHostname(t *testing.T) { hostname := string("kvm10.specterops.iad1.vexxhost.net") expected := bool(true) - assertCheckComputeSubstring(t, hostname, expected) + assertCheckComputeNode(t, hostname, expected) } -func TestCheckComputeSubstringWithcomputeHostname(t *testing.T) { +func TestCheckComputeNodeWithcomputeHostname(t *testing.T) { hostname := string("compute.specterops.iad1.vexxhost.net") expected := bool(true) - assertCheckComputeSubstring(t, hostname, expected) + assertCheckComputeNode(t, hostname, expected) } -func TestCheckComputeSubstringWithNoneComputeHostname(t *testing.T) { +func TestCheckComputeNodeWithNoneComputeHostname(t *testing.T) { hostname := string("ctl1.specterops.iad1.vexxhost.net") expected := bool(false) - assertCheckComputeSubstring(t, hostname, expected) + assertCheckComputeNode(t, hostname, expected) }