Add compute node labeling

Change-Id: I64c9b42070e013e23949c5165b471af71036e411
This commit is contained in:
okozachenko 2020-07-17 21:29:49 +03:00
parent fe023d0fd2
commit 3f16ae5ab8
1 changed files with 25 additions and 0 deletions

25
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"os"
"strings"
"time"
"github.com/avast/retry-go"
@ -63,6 +64,10 @@ func main() {
"node.vexxhost.com/product": slug.Make(product.Name),
}
if !checkComputeNode() {
labels["node-role.openstack.org"] = "compute"
}
var node *v1.Node
err = retry.Do(
func() error {
@ -86,6 +91,26 @@ func main() {
}
}
// checkComputeNode checks if the current node is a compute node.
func checkComputeNode() bool {
compute_tag := []string{
"kvm",
"compute",
}
hostname, err := os.Hostname()
if err != nil {
log.Fatal(err.Error())
}
for _, sub := range compute_tag {
if strings.Contains(hostname, sub) {
return true
}
}
return false
}
func addLabelToNode(clientset *kubernetes.Clientset, node *v1.Node, key string, value string) error {
log.Info("Applying node label",
zap.String(key, value),