63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package node
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"k8s.io/klog/v2"
|
|
system "undecided.project/monok8s/pkg/system"
|
|
)
|
|
|
|
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(ctx context.Context, n *NodeContext) error {
|
|
return system.EnsureServiceRunning(ctx, n.SystemRunner, "crio")
|
|
}
|