Skip to content

Commit

Permalink
use node-label flag instead
Browse files Browse the repository at this point in the history
Signed-off-by: Dentrax <[email protected]>
Signed-off-by: Batuhan Apaydın <[email protected]>
  • Loading branch information
Dentrax authored and developer-guy committed May 7, 2021
1 parent 40dcfa9 commit 32c8bfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
18 changes: 9 additions & 9 deletions cmd/node/nodeCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ 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("labels", "l", []string{}, "Specify node labels in format \"foo=bar\"")
cmd.Flags().StringSliceP("k3s-node-label", "", []string{}, "Specify k3s node labels in format \"foo=bar\"")

// done
return cmd
Expand Down Expand Up @@ -127,19 +127,19 @@ func parseCreateNodeCmd(cmd *cobra.Command, args []string) ([]*k3d.Node, *k3d.Cl
log.Errorf("Provided memory limit value is invalid")
}

labels, err := cmd.Flags().GetStringSlice("labels")
k3sNodeLabelsFlag, err := cmd.Flags().GetStringSlice("k3s-node-label")
if err != nil {
log.Errorln("No labels specified")
log.Errorln("No node-label specified")
log.Fatalln(err)
}

extraLabels := make(map[string]string, len(labels))
for _, label := range labels {
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)
}
extraLabels[labelSplitted[0]] = labelSplitted[1]
k3sNodeLabels[labelSplitted[0]] = labelSplitted[1]
}

// generate list of nodes
Expand All @@ -152,9 +152,9 @@ func parseCreateNodeCmd(cmd *cobra.Command, args []string) ([]*k3d.Node, *k3d.Cl
Labels: map[string]string{
k3d.LabelRole: roleStr,
},
ExtraLabels: extraLabels,
Restart: true,
Memory: memory,
K3sNodeLabels: k3sNodeLabels,
Restart: true,
Memory: memory,
}
nodes = append(nodes, node)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func patchAgentSpec(node *k3d.Node) error {
node.Cmd = []string{"agent"}
}

for k, v := range node.ExtraLabels {
for k, v := range node.K3sNodeLabels {
node.Args = append(node.Args, "--node-label", fmt.Sprintf("%s=%s", k, v))
}

Expand Down
40 changes: 20 additions & 20 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,26 @@ type NodeIP struct {

// Node describes a k3d node
type Node struct {
Name string `yaml:"name" json:"name,omitempty"`
Role Role `yaml:"role" json:"role,omitempty"`
Image string `yaml:"image" json:"image,omitempty"`
Volumes []string `yaml:"volumes" json:"volumes,omitempty"`
Env []string `yaml:"env" json:"env,omitempty"`
Cmd []string // filled automatically based on role
Args []string `yaml:"extraArgs" json:"extraArgs,omitempty"`
Ports nat.PortMap `yaml:"portMappings" json:"portMappings,omitempty"`
Restart bool `yaml:"restart" json:"restart,omitempty"`
Created string `yaml:"created" json:"created,omitempty"`
Labels map[string]string // filled automatically
ExtraLabels map[string]string `yaml:"extraLabels" json:"extraLabels,omitempty"`
Networks []string // filled automatically
ExtraHosts []string // filled automatically
ServerOpts ServerOpts `yaml:"serverOpts" json:"serverOpts,omitempty"`
AgentOpts AgentOpts `yaml:"agentOpts" json:"agentOpts,omitempty"`
GPURequest string // filled automatically
Memory string // filled automatically
State NodeState // filled automatically
IP NodeIP // filled automatically
Name string `yaml:"name" json:"name,omitempty"`
Role Role `yaml:"role" json:"role,omitempty"`
Image string `yaml:"image" json:"image,omitempty"`
Volumes []string `yaml:"volumes" json:"volumes,omitempty"`
Env []string `yaml:"env" json:"env,omitempty"`
Cmd []string // filled automatically based on role
Args []string `yaml:"extraArgs" json:"extraArgs,omitempty"`
Ports nat.PortMap `yaml:"portMappings" json:"portMappings,omitempty"`
Restart bool `yaml:"restart" json:"restart,omitempty"`
Created string `yaml:"created" json:"created,omitempty"`
Labels map[string]string // filled automatically
K3sNodeLabels map[string]string `yaml:"k3sNodeLabels" json:"k3sNodeLabels,omitempty"`
Networks []string // filled automatically
ExtraHosts []string // filled automatically
ServerOpts ServerOpts `yaml:"serverOpts" json:"serverOpts,omitempty"`
AgentOpts AgentOpts `yaml:"agentOpts" json:"agentOpts,omitempty"`
GPURequest string // filled automatically
Memory string // filled automatically
State NodeState // filled automatically
IP NodeIP // filled automatically
}

// ServerOpts describes some additional server role specific opts
Expand Down

0 comments on commit 32c8bfb

Please sign in to comment.