Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion cli/cmd/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ https://docs.replicated.com/vendor/testing-how-to#limitations`,
cmd.Flags().StringVar(&r.args.createClusterKubernetesDistribution, "distribution", "", "Kubernetes distribution of the cluster to provision")
cmd.Flags().StringVar(&r.args.createClusterKubernetesVersion, "version", "", "Kubernetes version to provision (format is distribution dependent)")
cmd.Flags().IntVar(&r.args.createClusterNodeCount, "nodes", int(1), "Node count")
cmd.Flags().StringVar(&r.args.createClusterMinNodeCount, "min-nodes", "", "Minimum Node count (non-negative number) (only for EKS, AKS and GKE clusters).")
cmd.Flags().StringVar(&r.args.createClusterMaxNodeCount, "max-nodes", "", "Maximum Node count (non-negative number) (only for EKS, AKS and GKE clusters).")
cmd.Flags().Int64Var(&r.args.createClusterDiskGiB, "disk", int64(50), "Disk Size (GiB) to request per node")
cmd.Flags().StringVar(&r.args.createClusterTTL, "ttl", "", "Cluster TTL (duration, max 48h)")
cmd.Flags().DurationVar(&r.args.createClusterWaitDuration, "wait", time.Second*0, "Wait duration for cluster to be ready (leave empty to not wait)")
cmd.Flags().StringVar(&r.args.createClusterInstanceType, "instance-type", "", "The type of instance to use (e.g. m6i.large)")
cmd.Flags().StringArrayVar(&r.args.createClusterNodeGroups, "nodegroup", []string{}, "Node group to create (name=?,instance-type=?,nodes=?,disk=? format, can be specified multiple times)")
cmd.Flags().StringArrayVar(&r.args.createClusterNodeGroups, "nodegroup", []string{}, "Node group to create (name=?,instance-type=?,nodes=?,min-nodes=?,max-nodes=?,disk=? format, can be specified multiple times)")

cmd.Flags().StringArrayVar(&r.args.createClusterTags, "tag", []string{}, "Tag to apply to the cluster (key=value format, can be specified multiple times)")

Expand Down Expand Up @@ -79,6 +81,26 @@ func (r *runners) createCluster(_ *cobra.Command, args []string) error {
Tags: tags,
DryRun: r.args.createClusterDryRun,
}
if r.args.createClusterMinNodeCount != "" {
minNodes, err := strconv.Atoi(r.args.createClusterMinNodeCount)
if err != nil {
return errors.Wrapf(err, "failed to parse min-nodes value: %s", r.args.createClusterMinNodeCount)
}
if minNodes < 0 {
return errors.Errorf("min-nodes must be a non-negative number: %s", r.args.createClusterMinNodeCount)
}
opts.MinNodeCount = &minNodes
}
if r.args.createClusterMaxNodeCount != "" {
maxNodes, err := strconv.Atoi(r.args.createClusterMaxNodeCount)
if err != nil {
return errors.Wrapf(err, "failed to parse max-nodes value: %s", r.args.createClusterMaxNodeCount)
}
if maxNodes < 0 {
return errors.Errorf("max-nodes must be a non-negative number: %s", r.args.createClusterMaxNodeCount)
}
opts.MaxNodeCount = &maxNodes
}
cl, err := r.createAndWaitForCluster(opts)
if err != nil {
if errors.Cause(err) == ErrWaitDurationExceeded {
Expand Down Expand Up @@ -177,6 +199,24 @@ func parseNodeGroups(nodeGroups []string) ([]kotsclient.NodeGroup, error) {
return nil, errors.Wrapf(err, "failed to parse nodes value: %s", parsedFieldValue)
}
ng.Nodes = nodes
case "min-nodes":
minNodes, err := strconv.Atoi(parsedFieldValue)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse min-nodes value: %s", parsedFieldValue)
}
if minNodes < 0 {
return nil, errors.Errorf("min-nodes must be a non-negative number: %s", parsedFieldValue)
}
ng.MinNodes = &minNodes
case "max-nodes":
maxNodes, err := strconv.Atoi(parsedFieldValue)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse max-nodes value: %s", parsedFieldValue)
}
if maxNodes < 0 {
return nil, errors.Errorf("max-nodes must be a non-negative number: %s", parsedFieldValue)
}
ng.MaxNodes = &maxNodes
case "disk":
diskSize, err := strconv.Atoi(parsedFieldValue)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ type runnerArgs struct {
createClusterKubernetesDistribution string
createClusterKubernetesVersion string
createClusterNodeCount int
createClusterMinNodeCount string
createClusterMaxNodeCount string
createClusterDiskGiB int64
createClusterDryRun bool
createClusterTTL string
Expand Down
8 changes: 8 additions & 0 deletions pkg/kotsclient/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type CreateClusterRequest struct {
KubernetesDistribution string `json:"kubernetes_distribution"`
KubernetesVersion string `json:"kubernetes_version"`
NodeCount int `json:"node_count"`
MinNodeCount *int `json:"min_node_count"`
MaxNodeCount *int `json:"max_node_count"`
DiskGiB int64 `json:"disk_gib"`
TTL string `json:"ttl"`
NodeGroups []NodeGroup `json:"node_groups"`
Expand All @@ -33,6 +35,8 @@ type CreateClusterOpts struct {
KubernetesDistribution string
KubernetesVersion string
NodeCount int
MinNodeCount *int
MaxNodeCount *int
DiskGiB int64
TTL string
InstanceType string
Expand All @@ -45,6 +49,8 @@ type NodeGroup struct {
Name string `json:"name"`
InstanceType string `json:"instance_type"`
Nodes int `json:"node_count"`
MinNodes *int `json:"min_node_count"`
MaxNodes *int `json:"max_node_count"`
Disk int `json:"disk_gib"`
}

Expand Down Expand Up @@ -72,6 +78,8 @@ func (c *VendorV3Client) CreateCluster(opts CreateClusterOpts) (*types.Cluster,
KubernetesDistribution: opts.KubernetesDistribution,
KubernetesVersion: opts.KubernetesVersion,
NodeCount: opts.NodeCount,
MinNodeCount: opts.MinNodeCount,
MaxNodeCount: opts.MaxNodeCount,
DiskGiB: opts.DiskGiB,
TTL: opts.TTL,
InstanceType: opts.InstanceType,
Expand Down