Added some ctl boilerplate
This commit is contained in:
15
clitools/pkg/node/context.go
Normal file
15
clitools/pkg/node/context.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
monov1alpha1 "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
|
||||
"undecided.project/monok8s/pkg/system"
|
||||
)
|
||||
|
||||
type NodeContext struct {
|
||||
Config *monov1alpha1.MonoKSConfig
|
||||
System *system.Runner
|
||||
}
|
||||
|
||||
type Step func(context.Context, *NodeContext) error
|
||||
22
clitools/pkg/node/crio.go
Normal file
22
clitools/pkg/node/crio.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func InstallCNIIfRequested(context.Context, *NodeContext) error {
|
||||
klog.Info("install_cni_if_requested: TODO implement bridge/none CNI toggling")
|
||||
return nil
|
||||
}
|
||||
|
||||
func StartCRIO(context.Context, *NodeContext) error {
|
||||
klog.Info("start_crio: TODO implement rc-service crio start")
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckCRIORunning(context.Context, *NodeContext) error {
|
||||
klog.Info("check_crio_running: TODO implement crictl readiness checks")
|
||||
return nil
|
||||
}
|
||||
36
clitools/pkg/node/kubeadm.go
Normal file
36
clitools/pkg/node/kubeadm.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func WaitForExistingClusterIfNeeded(context.Context, *NodeContext) error {
|
||||
klog.Info("wait_for_existing_cluster_if_needed: TODO implement kubelet/admin.conf waits")
|
||||
return nil
|
||||
}
|
||||
func CheckRequiredImages(context.Context, *NodeContext) error {
|
||||
klog.Info("check_required_images: TODO implement kubeadm image list + crictl image presence")
|
||||
return nil
|
||||
}
|
||||
func GenerateKubeadmConfig(context.Context, *NodeContext) error {
|
||||
klog.Info("generate_kubeadm_config: TODO render kubeadm v1beta4 config from MonoKSConfig")
|
||||
return nil
|
||||
}
|
||||
func RunKubeadmInit(context.Context, *NodeContext) error {
|
||||
klog.Info("run_kubeadm_init: TODO implement kubeadm init --config <file>")
|
||||
return nil
|
||||
}
|
||||
func RunKubeadmUpgradeApply(context.Context, *NodeContext) error {
|
||||
klog.Info("run_kubeadm_upgrade_apply: TODO implement kubeadm upgrade apply")
|
||||
return nil
|
||||
}
|
||||
func RunKubeadmJoin(context.Context, *NodeContext) error {
|
||||
klog.Info("run_kubeadm_join: TODO implement kubeadm join")
|
||||
return nil
|
||||
}
|
||||
func RunKubeadmUpgradeNode(context.Context, *NodeContext) error {
|
||||
klog.Info("run_kubeadm_upgrade_node: TODO implement kubeadm upgrade node")
|
||||
return nil
|
||||
}
|
||||
12
clitools/pkg/node/kubelet.go
Normal file
12
clitools/pkg/node/kubelet.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func RestartKubelet(context.Context, *NodeContext) error {
|
||||
klog.Info("restart_kubelet: TODO implement rc-service kubelet restart")
|
||||
return nil
|
||||
}
|
||||
37
clitools/pkg/node/metadata.go
Normal file
37
clitools/pkg/node/metadata.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func ApplyLocalNodeMetadataIfPossible(context.Context, *NodeContext) error {
|
||||
klog.Info("apply_local_node_metadata_if_possible: TODO implement node labels/annotations")
|
||||
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
|
||||
}
|
||||
91
clitools/pkg/node/network.go
Normal file
91
clitools/pkg/node/network.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
system "undecided.project/monok8s/pkg/system"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
type NetworkConfig struct {
|
||||
MgmtIface string
|
||||
MgmtAddress string
|
||||
MgmtGateway string
|
||||
}
|
||||
|
||||
func ConfigureMgmtInterface(cfg NetworkConfig) Step {
|
||||
return func(ctx context.Context, nctx *NodeContext) error {
|
||||
if strings.TrimSpace(cfg.MgmtIface) == "" {
|
||||
return fmt.Errorf("mgmt interface is required")
|
||||
}
|
||||
if strings.TrimSpace(cfg.MgmtAddress) == "" {
|
||||
return fmt.Errorf("mgmt address is required")
|
||||
}
|
||||
ip, ipNet, err := net.ParseCIDR(cfg.MgmtAddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid mgmt address %q: %w", cfg.MgmtAddress, err)
|
||||
}
|
||||
wantIP := ip.String()
|
||||
if gw := strings.TrimSpace(cfg.MgmtGateway); gw != "" && net.ParseIP(gw) == nil {
|
||||
return fmt.Errorf("invalid mgmt gateway %q", gw)
|
||||
}
|
||||
|
||||
if _, err := nctx.System.Run(ctx, "ip", "link", "show", "dev", cfg.MgmtIface); err != nil {
|
||||
return fmt.Errorf("interface not found: %s: %w", cfg.MgmtIface, err)
|
||||
}
|
||||
if _, err := nctx.System.Run(ctx, "ip", "link", "set", "dev", cfg.MgmtIface, "up"); err != nil {
|
||||
return fmt.Errorf("failed to bring up interface %s: %w", cfg.MgmtIface, err)
|
||||
}
|
||||
|
||||
hasAddr, err := interfaceHasIPv4(ctx, nctx, cfg.MgmtIface, wantIP)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed checking existing address on %s: %w", cfg.MgmtIface, err)
|
||||
}
|
||||
if hasAddr {
|
||||
klog.Infof("address already present on %s: %s", cfg.MgmtIface, cfg.MgmtAddress)
|
||||
} else {
|
||||
if _, err := nctx.System.Run(ctx, "ip", "addr", "add", ipNet.String(), "dev", cfg.MgmtIface); err != nil {
|
||||
return fmt.Errorf("failed assigning %s to %s: %w", ipNet.String(), cfg.MgmtIface, err)
|
||||
}
|
||||
}
|
||||
|
||||
if gw := strings.TrimSpace(cfg.MgmtGateway); gw != "" {
|
||||
if _, err := nctx.System.Run(ctx, "ip", "route", "replace", "default", "via", gw, "dev", cfg.MgmtIface); err != nil {
|
||||
return fmt.Errorf("failed setting default route via %s dev %s: %w", gw, cfg.MgmtIface, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func EnsureIPForward(ctx context.Context, n *NodeContext) error {
|
||||
return system.EnsureSysctl(ctx, n.System, "net.ipv4.ip_forward", "1")
|
||||
}
|
||||
|
||||
func ConfigureDNS(context.Context, *NodeContext) error {
|
||||
klog.Info("configure_dns: TODO implement resolv.conf rendering")
|
||||
return nil
|
||||
}
|
||||
|
||||
func interfaceHasIPv4(ctx context.Context, nctx *NodeContext, iface, wantIP string) (bool, error) {
|
||||
res, err := nctx.System.Run(ctx, "ip", "-o", "-4", "addr", "show", "dev", iface)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, line := range strings.Split(res.Stdout, "\n") {
|
||||
fields := strings.Fields(strings.TrimSpace(line))
|
||||
for i := 0; i < len(fields)-1; i++ {
|
||||
if fields[i] != "inet" {
|
||||
continue
|
||||
}
|
||||
ip, _, err := net.ParseCIDR(fields[i+1])
|
||||
if err == nil && ip.String() == wantIP {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
27
clitools/pkg/node/prereqs.go
Normal file
27
clitools/pkg/node/prereqs.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func CheckPrereqs(context.Context, *NodeContext) error {
|
||||
klog.Info("check_prereqs: TODO implement command discovery and runtime validation")
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateNetworkRequirements(context.Context, *NodeContext) error {
|
||||
klog.Info("validate_network_requirements: TODO implement local IP and API reachability checks")
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckUpgradePrereqs(context.Context, *NodeContext) error {
|
||||
klog.Info("check_upgrade_prereqs: TODO implement kubeadm version / skew checks")
|
||||
return nil
|
||||
}
|
||||
|
||||
func DecideBootstrapAction(_ context.Context, nctx *NodeContext) error {
|
||||
klog.InfoS("decide_bootstrap_action", "bootstrapMode", nctx.Config.Spec.BootstrapMode, "joinKind", nctx.Config.Spec.JoinKind)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user