Drafting ctl controller
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -464,9 +465,57 @@ func buildNodeRegistration(spec monov1alpha1.MonoKSConfigSpec) NodeRegistrationO
|
||||
)
|
||||
}
|
||||
|
||||
labels := effectiveNodeLabels(spec)
|
||||
if nodeLabels := buildNodeLabelsArg(labels); nodeLabels != "" {
|
||||
nr.KubeletExtraArgs = append(nr.KubeletExtraArgs,
|
||||
KubeadmArg{Name: "node-labels", Value: nodeLabels},
|
||||
)
|
||||
}
|
||||
|
||||
return nr
|
||||
}
|
||||
|
||||
func effectiveNodeLabels(spec monov1alpha1.MonoKSConfigSpec) map[string]string {
|
||||
if len(spec.NodeLabels) == 0 && !spec.EnableControlAgent {
|
||||
return nil
|
||||
}
|
||||
|
||||
labels := make(map[string]string, len(spec.NodeLabels)+1)
|
||||
for k, v := range spec.NodeLabels {
|
||||
labels[k] = v
|
||||
}
|
||||
|
||||
if spec.EnableControlAgent {
|
||||
labels[monov1alpha1.ControlAgentKey] = "true"
|
||||
}
|
||||
|
||||
return labels
|
||||
}
|
||||
|
||||
func buildNodeLabelsArg(labels map[string]string) string {
|
||||
if len(labels) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
keys := make([]string, 0, len(labels))
|
||||
for k := range labels {
|
||||
k = strings.TrimSpace(k)
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
parts := make([]string, 0, len(keys))
|
||||
for _, k := range keys {
|
||||
v := strings.TrimSpace(labels[k])
|
||||
parts = append(parts, k+"="+v)
|
||||
}
|
||||
|
||||
return strings.Join(parts, ",")
|
||||
}
|
||||
|
||||
func maybeAddBootstrapTaint(nr *NodeRegistrationOptions, role string) {
|
||||
if strings.TrimSpace(role) != "worker" {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user