Added some ctl boilerplate

This commit is contained in:
2026-03-27 18:34:53 +08:00
parent bf85462e34
commit 87aa1d4b0b
30 changed files with 1813 additions and 19 deletions

View File

@@ -0,0 +1,34 @@
package initcmd
import (
"context"
"undecided.project/monok8s/pkg/bootstrap"
"undecided.project/monok8s/pkg/config"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
)
func NewCmdInit(_ *genericclioptions.ConfigFlags) *cobra.Command {
var configPath string
cmd := &cobra.Command{
Use: "init",
Short: "Equivalent of apply-node-config + bootstrap-cluster",
RunE: func(cmd *cobra.Command, _ []string) error {
path, err := (config.Loader{}).ResolvePath(configPath)
if err != nil {
return err
}
cfg, err := (config.Loader{}).Load(path)
if err != nil {
return err
}
klog.InfoS("starting init", "config", path, "node", cfg.Spec.NodeName)
return bootstrap.NewRunner(cfg).Init(cmd.Context())
},
}
cmd.Flags().StringVarP(&configPath, "config", "c", "", "path to MonoKSConfig yaml")
_ = context.Background()
return cmd
}