Add compute node labeling
Change-Id: I64c9b42070e013e23949c5165b471af71036e411
This commit is contained in:
parent
fe023d0fd2
commit
3f16ae5ab8
25
main.go
25
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/avast/retry-go"
|
"github.com/avast/retry-go"
|
||||||
@ -63,6 +64,10 @@ func main() {
|
|||||||
"node.vexxhost.com/product": slug.Make(product.Name),
|
"node.vexxhost.com/product": slug.Make(product.Name),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !checkComputeNode() {
|
||||||
|
labels["node-role.openstack.org"] = "compute"
|
||||||
|
}
|
||||||
|
|
||||||
var node *v1.Node
|
var node *v1.Node
|
||||||
err = retry.Do(
|
err = retry.Do(
|
||||||
func() error {
|
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 {
|
func addLabelToNode(clientset *kubernetes.Clientset, node *v1.Node, key string, value string) error {
|
||||||
log.Info("Applying node label",
|
log.Info("Applying node label",
|
||||||
zap.String(key, value),
|
zap.String(key, value),
|
||||||
|
Loading…
Reference in New Issue
Block a user