Skip to content

Commit

Permalink
Fix flux install command so it returns an error when unexpected argum…
Browse files Browse the repository at this point in the history
…ents are passed
  • Loading branch information
VinGarcia committed Nov 15, 2023
1 parent 0fcda45 commit 1d3e349
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/flux/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -52,7 +53,7 @@ If a previous version is installed, then an in-place upgrade will be performed.`
flux install --toleration-keys=node.kubernetes.io/dedicated-to-flux
# Dry-run install
flux install --export | kubectl apply --dry-run=client -f-
flux install --export | kubectl apply --dry-run=client -f-
# Write install manifests to file
flux install --export > flux-system.yaml`,
Expand Down Expand Up @@ -114,6 +115,10 @@ func NewInstallFlags() installFlags {
}

func installCmdRun(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf(`flux install received unexpected positional arguments: "%s"`, strings.Join(args, `", "`))
}

ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel()

Expand Down
5 changes: 5 additions & 0 deletions cmd/flux/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestInstall(t *testing.T) {
args: "install --namespace='@#[]'",
assert: assertError("namespace must be a valid DNS label: \"@#[]\""),
},
{
name: "invalid namespace",
args: "install unexpected pos arg --namespace=example",
assert: assertError("flux install received unexpected positional arguments: \"unexpected\", \"pos\", \"arg\""),
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 1d3e349

Please sign in to comment.