From 3f16ae5ab877940d7f6eca27f1a73a2037d14737 Mon Sep 17 00:00:00 2001 From: okozachenko Date: Fri, 17 Jul 2020 21:29:49 +0300 Subject: [PATCH] Add compute node labeling Change-Id: I64c9b42070e013e23949c5165b471af71036e411 --- main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/main.go b/main.go index a25e333..54150a6 100644 --- a/main.go +++ b/main.go @@ -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),