Can now reconcile
This commit is contained in:
@@ -1,37 +1,80 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kubernetes "k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
func ApplyLocalNodeMetadataIfPossible(context.Context, *NodeContext) error {
|
||||
klog.Info("apply_local_node_metadata_if_possible: TODO implement node labels/annotations")
|
||||
return nil
|
||||
func ApplyLocalNodeMetadataIfPossible(ctx context.Context, nctx *NodeContext) error {
|
||||
spec := nctx.Config.Spec
|
||||
|
||||
if len(spec.NodeAnnotations) == 0 && len(spec.NodeLabels) == 0 {
|
||||
return nil // nothing to do
|
||||
}
|
||||
|
||||
nodeName := strings.TrimSpace(spec.NodeName)
|
||||
if nodeName == "" {
|
||||
return fmt.Errorf("spec.nodeName is required")
|
||||
}
|
||||
|
||||
// Prefer admin kubeconfig (control-plane)
|
||||
kubeconfig := adminKubeconfigPath
|
||||
|
||||
if _, err := os.Stat(kubeconfig); err != nil {
|
||||
klog.V(2).Infof("admin kubeconfig not found, skipping node metadata apply")
|
||||
return nil
|
||||
}
|
||||
|
||||
restConfig, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build kubeconfig: %w", err)
|
||||
}
|
||||
|
||||
client, err := kubernetes.NewForConfig(restConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("create kubernetes client: %w", err)
|
||||
}
|
||||
|
||||
node, err := client.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("get node %q: %w", nodeName, err)
|
||||
}
|
||||
|
||||
if node.Labels == nil {
|
||||
node.Labels = make(map[string]string)
|
||||
}
|
||||
if node.Annotations == nil {
|
||||
node.Annotations = make(map[string]string)
|
||||
}
|
||||
|
||||
// Apply labels
|
||||
for k, v := range spec.NodeLabels {
|
||||
node.Labels[k] = v
|
||||
}
|
||||
|
||||
// Apply annotations
|
||||
for k, v := range spec.NodeAnnotations {
|
||||
node.Annotations[k] = v
|
||||
}
|
||||
|
||||
_, err = client.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("update node metadata: %w", err)
|
||||
}
|
||||
|
||||
klog.Infof("applied labels/annotations to node %q", nodeName)
|
||||
return nil
|
||||
}
|
||||
|
||||
func AllowSingleNodeScheduling(context.Context, *NodeContext) error {
|
||||
klog.Info("allow_single_node_scheduling: TODO implement control-plane taint removal")
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetHostnameIfNeeded(context.Context, *NodeContext) error {
|
||||
klog.Info("set_hostname_if_needed: TODO implement hostname and /etc/hostname reconciliation")
|
||||
return nil
|
||||
}
|
||||
|
||||
func PrintSummary(context.Context, *NodeContext) error {
|
||||
klog.Info("print_summary: TODO emit final summary")
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReconcileControlPlane(context.Context, *NodeContext) error {
|
||||
klog.Info("reconcile_control_plane: TODO implement existing CP reconciliation")
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReconcileNode(context.Context, *NodeContext) error {
|
||||
klog.Info("reconcile_node: TODO implement existing joined node reconciliation")
|
||||
return nil
|
||||
klog.Info("allow_single_node_scheduling: TODO implement control-plane taint removal")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user