Skip to content
Permalink
Browse files
Merge pull request #731 from timoreimann/support-kubernetes-node-pool…
…-labels

Support kubernetes node pool labels
  • Loading branch information
hilary committed Feb 4, 2020
2 parents 884a996 + e4837c1 commit 4cb8a214925bb353e86d7beaf6743e2b77b71fb4
@@ -68,6 +68,8 @@ const (
ArgDropletIDs = "droplet-ids"
// ArgKernelID is a ekrnel id argument.
ArgKernelID = "kernel-id"
// ArgKubernetesLabel is a Kubernetes label argument.
ArgKubernetesLabel = "label"
// ArgImage is an image argument.
ArgImage = "image"
// ArgImageID is an image id argument.
@@ -131,18 +131,20 @@ func (nodePools *KubernetesNodePools) Cols() []string {
"Size",
"Count",
"Tags",
"Labels",
"Nodes",
}
}

func (nodePools *KubernetesNodePools) ColMap() map[string]string {
return map[string]string{
"ID": "ID",
"Name": "Name",
"Size": "Size",
"Count": "Count",
"Tags": "Tags",
"Nodes": "Nodes",
"ID": "ID",
"Name": "Name",
"Size": "Size",
"Count": "Count",
"Tags": "Tags",
"Labels": "Labels",
"Nodes": "Nodes",
}
}

@@ -157,12 +159,13 @@ func (nodePools *KubernetesNodePools) KV() []map[string]interface{} {
}

o := map[string]interface{}{
"ID": nodePools.ID,
"Name": nodePools.Name,
"Size": nodePools.Size,
"Count": nodePools.Count,
"Tags": tags,
"Nodes": nodes,
"ID": nodePools.ID,
"Name": nodePools.Name,
"Size": nodePools.Size,
"Count": nodePools.Count,
"Tags": tags,
"Labels": nodePools.Labels,
"Nodes": nodes,
}
out = append(out, o)
}
@@ -234,6 +234,17 @@ func AddStringSliceFlag(cmd *Command, name, shorthand string, def []string, desc
}
}

// AddStringMapStringFlag adds a map of strings by strings flag to a command.
func AddStringMapStringFlag(cmd *Command, name, shorthand string, def map[string]string, desc string, opts ...flagOpt) {
fn := flagName(cmd, name)
cmd.Flags().StringToStringP(name, shorthand, def, desc)
viper.BindPFlag(fn, cmd.Flags().Lookup(name))

for _, o := range opts {
o(cmd, name, fn)
}
}

func flagName(cmd *Command, name string) string {
if cmd.Parent() != nil {
return fmt.Sprintf("%s.%s.%s", cmd.Parent().Name(), cmd.Name(), name)
@@ -235,11 +235,12 @@ func kubernetesCluster() *Command {
"number of nodes in the default node pool (incompatible with --"+doctl.ArgClusterNodePool+")")
AddStringSliceFlag(cmdKubeClusterCreate, doctl.ArgClusterNodePool, "", nil,
`cluster node pools, can be repeated to create multiple node pools at once (incompatible with --`+doctl.ArgSizeSlug+` and --`+doctl.ArgNodePoolCount+`)
format is in the form "name=your-name;size=size_slug;count=5;tag=tag1;tag=tag2" where:
format is in the form "name=your-name;size=size_slug;count=5;tag=tag1;tag=tag2;label=key1=value1;label=key2=label2" where:
- name: name of the node pool, must be unique in the cluster
- size: size for the nodes in the node pool, possible values: see "doctl k8s options sizes".
- count: number of nodes in the node pool.
- tag: tags to apply to the node pool, repeat to add multiple tags at once.
- tag: tag to apply to the node pool; repeat to add multiple tags at once.
- label: label in key=value notation; repeat to add multiple labels at once.
- auto-scale: whether to enable auto-scaling on the node pool.
- min-nodes: maximum number of nodes that can be auto-scaled to.
- max-nodes: minimum number of nodes that can be auto-scaled to.`)
@@ -338,7 +339,9 @@ func kubernetesNodePools() *Command {
AddIntFlag(cmdKubeNodePoolCreate, doctl.ArgNodePoolCount, "", 0,
"count of nodes in the node pool", requiredOpt())
AddStringSliceFlag(cmdKubeNodePoolCreate, doctl.ArgTag, "", nil,
"tags to apply to the node pool, repeat to add multiple tags at once")
"tag to apply to the node pool, repeat to add multiple tags at once. Omitted tags will be removed from the node pool if the flag is specified.")
AddStringSliceFlag(cmdKubeNodePoolCreate, doctl.ArgKubernetesLabel, "", nil,
"label in key=value notation to apply to the node pool, repeat to add multiple labels at once. Omitted labels will be removed from the node pool if the flag is specified.")
AddBoolFlag(cmdKubeNodePoolCreate, doctl.ArgNodePoolAutoScale, "", false,
"enable auto-scaling on the node pool")
AddIntFlag(cmdKubeNodePoolCreate, doctl.ArgNodePoolMinNodes, "", 0,
@@ -353,7 +356,9 @@ func kubernetesNodePools() *Command {
AddIntFlag(cmdKubeNodePoolUpdate, doctl.ArgNodePoolCount, "", 0,
"count of nodes in the node pool")
AddStringSliceFlag(cmdKubeNodePoolUpdate, doctl.ArgTag, "", nil,
"tags to apply to the node pool, repeat to add multiple tags at once")
"tag to apply to the node pool, repeat to add multiple tags at once. Omitted tags will be removed from the node pool if the flag is specified.")
AddStringSliceFlag(cmdKubeNodePoolUpdate, doctl.ArgKubernetesLabel, "", nil,
"label in key=value notation to apply to the node pool, repeat to add multiple labels at once. Omitted labels will be removed from the node pool if the flag is specified.")
AddBoolFlag(cmdKubeNodePoolUpdate, doctl.ArgNodePoolAutoScale, "", false,
"enable auto-scaling on the node pool")
AddIntFlag(cmdKubeNodePoolUpdate, doctl.ArgNodePoolMinNodes, "", 0,
@@ -1268,9 +1273,10 @@ func parseNodePoolString(nodePool, defaultName, defaultSize string, defaultCount
kvSeparator = "="
)
out := &godo.KubernetesNodePoolCreateRequest{
Name: defaultName,
Size: defaultSize,
Count: defaultCount,
Name: defaultName,
Size: defaultSize,
Count: defaultCount,
Labels: map[string]string{},
}
for _, arg := range strings.Split(nodePool, argSeparator) {
kvs := strings.SplitN(arg, kvSeparator, 2)
@@ -1292,6 +1298,14 @@ func parseNodePoolString(nodePool, defaultName, defaultSize string, defaultCount
out.Count = int(count)
case "tag":
out.Tags = append(out.Tags, value)
case "label":
labelParts := strings.SplitN(value, "=", 2)
if len(labelParts) < 2 {
return nil, fmt.Errorf("a node pool label component must be of the form `label-key=label-value`, got %q", value)
}
labelKey := labelParts[0]
labelValue := labelParts[1]
out.Labels[labelKey] = labelValue
case "auto-scale":
autoScale, err := strconv.ParseBool(value)
if err != nil {
@@ -1345,6 +1359,12 @@ func buildNodePoolCreateRequestFromArgs(c *CmdConfig, r *godo.KubernetesNodePool
}
r.Tags = tags

labels, err := c.Doit.GetStringMapString(c.NS, doctl.ArgKubernetesLabel)
if err != nil {
return err
}
r.Labels = labels

autoScale, err := c.Doit.GetBool(c.NS, doctl.ArgNodePoolAutoScale)
if err != nil {
return err
@@ -1385,6 +1405,12 @@ func buildNodePoolUpdateRequestFromArgs(c *CmdConfig, r *godo.KubernetesNodePool
}
r.Tags = tags

labels, err := c.Doit.GetStringMapString(c.NS, doctl.ArgKubernetesLabel)
if err != nil {
return err
}
r.Labels = labels

autoScale, err := c.Doit.GetBoolPtr(c.NS, doctl.ArgNodePoolAutoScale)
if err != nil {
return err

0 comments on commit 4cb8a21

Please sign in to comment.