Split action into kubectl

This commit is contained in:
2026-04-03 03:26:39 +08:00
parent 53f9f9376a
commit a14fa23e7a
2 changed files with 33 additions and 25 deletions

View File

@@ -0,0 +1,33 @@
package node
import (
"context"
"time"
"k8s.io/klog/v2"
system "example.com/monok8s/pkg/system"
)
const (
crdsPath = "/usr/lib/monok8s/crds/"
)
func ApplyCRDs(ctx context.Context, nctx *NodeContext) error {
if nctx.Config.Spec.ClusterRole != "control-plane" {
return nil
}
_, err := nctx.SystemRunner.RunWithOptions(
ctx,
"kubectl",
[]string{"--kubeconfig", adminKubeconfigPath, "apply", "-f", crdsPath},
system.RunOptions{
Timeout: 10 * time.Minute,
OnStdoutLine: func(line string) { klog.Infof("[kubectl] %s", line) },
OnStderrLine: func(line string) { klog.Infof("[kubectl] %s", line) },
},
)
return err
}

View File

@@ -8,15 +8,9 @@ import (
"strings"
"time"
"k8s.io/klog/v2"
system "example.com/monok8s/pkg/system"
)
const (
crdsPath = "/usr/lib/monok8s/crds/"
)
func StartKubelet(ctx context.Context, n *NodeContext) error {
return system.EnsureServiceRunning(ctx, n.SystemRunner, "kubelet")
}
@@ -53,22 +47,3 @@ func waitForKubeletHealthy(ctx context.Context, timeout time.Duration) error {
}
}
}
func ApplyCRDs(ctx context.Context, nctx *NodeContext) error {
if nctx.Config.Spec.ClusterRole != "control-plane" {
return nil
}
_, err := nctx.SystemRunner.RunWithOptions(
ctx,
"kubectl",
[]string{"apply", "-f", crdsPath},
system.RunOptions{
Timeout: 10 * time.Minute,
OnStdoutLine: func(line string) { klog.Infof("[kubectl] %s", line) },
OnStderrLine: func(line string) { klog.Infof("[kubectl] %s", line) },
},
)
return err
}