Skip to content

Commit

Permalink
Add labels instance.hetzner.cloud/provided-by,instance.hetzner.cloud/…
Browse files Browse the repository at this point in the history
…is-root-server
  • Loading branch information
identw committed Nov 14, 2024
1 parent 46327b2 commit b08bc2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions hcloud/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,15 @@ func syncLabels(k8sClient *kubernetes.Clientset, server *hcloud.Server) {
func addTypeLabel(k8sClient *kubernetes.Clientset, name string, typeNode string) {
node, err := k8sClient.CoreV1().Nodes().Get(context.TODO(), name, metav1.GetOptions{})
if err == nil {
if _, ok := node.ObjectMeta.Labels[hcops.NameLabelType]; !ok {
node.ObjectMeta.Labels[hcops.NameLabelType] = typeNode
}
if node.ObjectMeta.Labels[hcops.NameLabelType] != typeNode {
node.ObjectMeta.Labels[hcops.NameLabelType] = typeNode
for k, v := range hcops.TypeLabels[typeNode] {
if _, ok := node.ObjectMeta.Labels[k]; !ok {
node.ObjectMeta.Labels[k] = v
}
if node.ObjectMeta.Labels[k] != v {
node.ObjectMeta.Labels[v] = v
}
}

k8sClient.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
}
}
14 changes: 14 additions & 0 deletions internal/hcops/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ var (
NameLabelType = "node.hetzner.com/type"
NameCloudNode = "cloud"
NameDedicatedNode = "dedicated"

TypeLabels = map[string]map[string]string{
"cloud": map[string]string{
"node.hetzner.com/type": "cloud",
"instance.hetzner.cloud/provided-by": "cloud",
"instance.hetzner.cloud/is-root-server": "false",
},
"dedicated": map[string]string{
"node.hetzner.com/type": "dedicated",
"instance.hetzner.cloud/provided-by": "robot",
"instance.hetzner.cloud/is-root-server": "true",
},
}

ExcludeServer = &hcloud.Server{
ID: 999999,
ServerType: &hcloud.ServerType{Name: "exclude"},
Expand Down

0 comments on commit b08bc2b

Please sign in to comment.