From a14fa23e7ae896f53f9a13cb3b8d6f4354c54c72dd302161d980460581647ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Fri, 3 Apr 2026 03:26:39 +0800 Subject: [PATCH] Split action into kubectl --- clitools/pkg/node/kubectl.go | 33 +++++++++++++++++++++++++++++++++ clitools/pkg/node/kubelet.go | 25 ------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 clitools/pkg/node/kubectl.go diff --git a/clitools/pkg/node/kubectl.go b/clitools/pkg/node/kubectl.go new file mode 100644 index 0000000..6c25223 --- /dev/null +++ b/clitools/pkg/node/kubectl.go @@ -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 +} diff --git a/clitools/pkg/node/kubelet.go b/clitools/pkg/node/kubelet.go index 725f147..08334ae 100644 --- a/clitools/pkg/node/kubelet.go +++ b/clitools/pkg/node/kubelet.go @@ -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 -}