|
|
|
@ -23,6 +23,7 @@ package node |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/spf13/cobra" |
|
|
|
@ -73,6 +74,8 @@ func NewCmdNodeCreate() *cobra.Command { |
|
|
|
|
cmd.Flags().BoolVar(&createNodeOpts.Wait, "wait", false, "Wait for the node(s) to be ready before returning.") |
|
|
|
|
cmd.Flags().DurationVar(&createNodeOpts.Timeout, "timeout", 0*time.Second, "Maximum waiting time for '--wait' before canceling/returning.") |
|
|
|
|
|
|
|
|
|
cmd.Flags().StringSliceP("k3s-node-label", "", []string{}, "Specify k3s node labels in format \"foo=bar\"") |
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
|
return cmd |
|
|
|
|
} |
|
|
|
@ -124,6 +127,21 @@ func parseCreateNodeCmd(cmd *cobra.Command, args []string) ([]*k3d.Node, *k3d.Cl |
|
|
|
|
log.Errorf("Provided memory limit value is invalid") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
k3sNodeLabelsFlag, err := cmd.Flags().GetStringSlice("k3s-node-label") |
|
|
|
|
if err != nil { |
|
|
|
|
log.Errorln("No node-label specified") |
|
|
|
|
log.Fatalln(err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
k3sNodeLabels := make(map[string]string, len(k3sNodeLabelsFlag)) |
|
|
|
|
for _, label := range k3sNodeLabelsFlag { |
|
|
|
|
labelSplitted := strings.Split(label, "=") |
|
|
|
|
if len(labelSplitted) != 2 { |
|
|
|
|
log.Fatalf("unknown label format format: %s, use format \"foo=bar\"", label) |
|
|
|
|
} |
|
|
|
|
k3sNodeLabels[labelSplitted[0]] = labelSplitted[1] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// generate list of nodes
|
|
|
|
|
nodes := []*k3d.Node{} |
|
|
|
|
for i := 0; i < replicas; i++ { |
|
|
|
@ -134,6 +152,7 @@ func parseCreateNodeCmd(cmd *cobra.Command, args []string) ([]*k3d.Node, *k3d.Cl |
|
|
|
|
Labels: map[string]string{ |
|
|
|
|
k3d.LabelRole: roleStr, |
|
|
|
|
}, |
|
|
|
|
K3sNodeLabels: k3sNodeLabels, |
|
|
|
|
Restart: true, |
|
|
|
|
Memory: memory, |
|
|
|
|
} |
|
|
|
|