Matches ctl version to upstream

This commit is contained in:
2026-03-28 20:28:22 +08:00
parent 848daefffe
commit ecceff225f
25 changed files with 591 additions and 159 deletions

View File

@@ -2,21 +2,61 @@ package node
import (
"context"
"fmt"
"os"
"strings"
"k8s.io/klog/v2"
system "undecided.project/monok8s/pkg/system"
)
func InstallCNIIfRequested(context.Context, *NodeContext) error {
klog.Info("install_cni_if_requested: TODO implement bridge/none CNI toggling")
func ConfigureDefaultCNI(ctx context.Context, n *NodeContext) error {
_ = ctx
const (
cniDir = "/etc/cni/net.d"
enabledPath = cniDir + "/10-crio-bridge.conflist"
disabledPath = cniDir + "/10-crio-bridge.conflist.disabled"
)
plugin := strings.TrimSpace(n.Config.Spec.CNIPlugin)
switch plugin {
case "none":
// Fail hard if we cannot ensure the default bridge CNI is disabled.
if _, err := os.Stat(enabledPath); err == nil {
if err := os.Rename(enabledPath, disabledPath); err != nil {
return fmt.Errorf("disable default CRI-O bridge CNI: %w", err)
}
} else if !os.IsNotExist(err) {
return fmt.Errorf("stat %s: %w", enabledPath, err)
}
klog.Infof("Default CRI-O bridge CNI disabled")
return nil
case "bridge":
fallthrough
case "default":
// Fail soft. User can still install or provide their own CNI.
if _, err := os.Stat(disabledPath); err == nil {
if err := os.Rename(disabledPath, enabledPath); err != nil {
klog.Warningf("failed enabling default CRI-O bridge CNI: %v", err)
return nil
}
} else if !os.IsNotExist(err) {
klog.Warningf("failed stating %s while enabling default CRI-O bridge CNI: %v", disabledPath, err)
return nil
}
klog.Infof("Default CRI-O bridge CNI enabled")
return nil
}
klog.Infof("unsupported CNIPlugin: %q", plugin)
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
func StartCRIO(ctx context.Context, n *NodeContext) error {
return system.EnsureServiceRunning(ctx, n.SystemRunner, "crio")
}