Added kubeadm init
This commit is contained in:
@@ -20,14 +20,27 @@ func NewCmdInit(_ *genericclioptions.ConfigFlags) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "init [list|STEPSEL]",
|
||||
Short: "Start the bootstrap process for this node",
|
||||
Example: strings.TrimSpace(`
|
||||
Long: `Run the node bootstrap process.
|
||||
|
||||
STEPSEL allows running specific steps instead of the full sequence.
|
||||
It supports:
|
||||
|
||||
3 Run step 3
|
||||
1-3 Run steps 1 through 3
|
||||
-3 Run steps from start through 3
|
||||
3- Run steps from 3 to the end
|
||||
1,3,5 Run specific steps
|
||||
9-10,15 Combine ranges and individual steps
|
||||
`,
|
||||
Example: `
|
||||
ctl init
|
||||
ctl init list
|
||||
ctl init 1-3
|
||||
ctl init -3
|
||||
ctl init 3-
|
||||
ctl init 1,3,5
|
||||
`),
|
||||
ctl init 9-10,15
|
||||
`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
path, err := (config.Loader{}).ResolvePath(configPath)
|
||||
@@ -68,6 +81,7 @@ func NewCmdInit(_ *genericclioptions.ConfigFlags) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
klog.InfoS("Running selected init steps", "steps", sel.Indices)
|
||||
return runner.InitSelected(cmd.Context(), sel)
|
||||
},
|
||||
}
|
||||
@@ -87,26 +101,27 @@ func parseStepSelection(raw string, max int) (bootstrap.StepSelection, error) {
|
||||
|
||||
selected := map[int]struct{}{}
|
||||
|
||||
parts := strings.Split(raw, ",")
|
||||
for _, part := range parts {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
for _, item := range strings.Split(raw, ",") {
|
||||
item = strings.TrimSpace(item)
|
||||
if item == "" {
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid empty selector in %q", raw)
|
||||
}
|
||||
|
||||
if strings.Contains(part, "-") {
|
||||
if strings.Count(part, "-") != 1 {
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid range %q", part)
|
||||
// Range or open-ended range
|
||||
if strings.Contains(item, "-") {
|
||||
if strings.Count(item, "-") != 1 {
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid range %q", item)
|
||||
}
|
||||
|
||||
bounds := strings.SplitN(part, "-", 2)
|
||||
left := strings.TrimSpace(bounds[0])
|
||||
right := strings.TrimSpace(bounds[1])
|
||||
parts := strings.SplitN(item, "-", 2)
|
||||
left := strings.TrimSpace(parts[0])
|
||||
right := strings.TrimSpace(parts[1])
|
||||
|
||||
var start, end int
|
||||
|
||||
switch {
|
||||
case left == "" && right == "":
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid range %q", part)
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid range %q", item)
|
||||
|
||||
case left == "":
|
||||
n, err := parseStepNumber(right, max)
|
||||
@@ -131,33 +146,33 @@ func parseStepSelection(raw string, max int) (bootstrap.StepSelection, error) {
|
||||
if err != nil {
|
||||
return bootstrap.StepSelection{}, err
|
||||
}
|
||||
if a > b {
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid descending range %q", item)
|
||||
}
|
||||
start, end = a, b
|
||||
}
|
||||
|
||||
if start > end {
|
||||
return bootstrap.StepSelection{}, fmt.Errorf("invalid descending range %q", part)
|
||||
}
|
||||
|
||||
for i := start; i <= end; i++ {
|
||||
selected[i] = struct{}{}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
n, err := parseStepNumber(part, max)
|
||||
// Single step
|
||||
n, err := parseStepNumber(item, max)
|
||||
if err != nil {
|
||||
return bootstrap.StepSelection{}, err
|
||||
}
|
||||
selected[n] = struct{}{}
|
||||
}
|
||||
|
||||
out := make([]int, 0, len(selected))
|
||||
indices := make([]int, 0, len(selected))
|
||||
for n := range selected {
|
||||
out = append(out, n)
|
||||
indices = append(indices, n)
|
||||
}
|
||||
sort.Ints(out)
|
||||
sort.Ints(indices)
|
||||
|
||||
return bootstrap.StepSelection{Indices: out}, nil
|
||||
return bootstrap.StepSelection{Indices: indices}, nil
|
||||
}
|
||||
|
||||
func parseStepNumber(raw string, max int) (int, error) {
|
||||
|
||||
Reference in New Issue
Block a user