Skip to content

fix(kubernetes): reject extra names in kubernetes create - #609

Merged
fulviodenza merged 3 commits into
civo:masterfrom
Aubaid12:fix/398-kubernetes-create-single-name
Nov 2, 2026
Merged

fulviodenza merged 3 commits into
civo:masterfrom
Aubaid12:fix/398-kubernetes-create-single-name

Conversation

@Aubaid12

Copy link
Copy Markdown
Contributor

Part of #398

Problem

civo kubernetes create has no limit on positional args, so civo kubernetes create test2 test3 test4 creates a single cluster called test2 and silently drops the other names.

Fix

  • Added Args: cobra.MaximumNArgs(1). The name is still optional (a random one is generated when it's missing), but passing more than one now fails before any API call.
  • Changed Use to create [CLUSTER_NAME] so the usage line shows the optional name, the same way instance create does.
$ civo kubernetes create test2 test3 test4
Error: accepts at most 1 arg(s), received 3
Usage:
  civo kubernetes create [CLUSTER_NAME] [flags]

The issue mentioned either creating them all or failing. I went with failing, since size, nodes, network and firewall apply per cluster and creating several clusters from one call would be easy to do by accident. Same approach as #602.

This does change behaviour for anything that passed stray args before, for example an unquoted name with a space (civo k8s create my cluster used to create my). It errors now instead.

Tests

  • Table-driven TestKubernetesCreateArgs in cmd/kubernetes/kubernetes_create_test.go (no name, one name, extra names)
  • Checked against a local stub API: with three names, master sends one create request for test2. With this change there are no API calls, and flags mixed between names (create a --nodes 2 b) are rejected too. One name and no name send the same requests as before.
  • go test ./... and golangci-lint pass locally

Some other create commands have the same gap. instance create has no Args check, and a few that use MinimumNArgs(1) (e.g. volume create) also ignore extra names. I can look at those in a separate PR if you want.

Aubaid12 and others added 3 commits October 20, 2026 05:48
kubernetes create had no Args check, so 'civo kubernetes create a b c' created a single cluster named a and ignored the rest. Limit it to at most one name; the name stays optional.

Part of civo#398

@fulviodenza fulviodenza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Reviewed: cobra.MaximumNArgs(1) still allows zero args, so the random cluster name path is unchanged, and the pattern matches the existing objectstore credential secret command. The test exercises the real command's arg validation. I updated the branch from master so CI ran against current dependencies (the earlier govulncheck failure was x/net on the stale base), and Lint, Security and Test are now green.

Small follow-up for later, not blocking: kubernetesCreateCmdExample still shows civo kubernetes create CLUSTER_NAME [flags], which reads as required now that Use says [CLUSTER_NAME].

@fulviodenza
fulviodenza merged commit c3ea6de into civo:master Nov 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants