Skip to content

Commit

Permalink
roachprod: validate cloud providers
Browse files Browse the repository at this point in the history
Previously, when calling the `create` command, it was possible to pass the same
cloud twice by specifying `-c` or `--clouds` for the same provider more than
once. There was no early validation that caught this and the resulting error
after attempting to create the cluster was confusing.

This change adds validation that warns the user, early on, a duplicate provider
has been passed.

Epic: None
Release note: None
  • Loading branch information
herkolategan committed Sep 27, 2024
1 parent 45be842 commit 9b8175a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cmd/roachprod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,18 @@ func validateAndConfigure(cmd *cobra.Command, args []string) {
_ = cmd.Flags().Set("arch", string(arch))
}
}

// Validate cloud providers, if set.
providersSet := make(map[string]struct{})
for _, p := range createVMOpts.VMProviders {
if _, ok := vm.Providers[p]; !ok {
printErrAndExit(fmt.Errorf("unknown cloud provider %q", p))
}
if _, ok := providersSet[p]; ok {
printErrAndExit(fmt.Errorf("duplicate cloud provider specified %q", p))
}
providersSet[p] = struct{}{}
}
}

var updateCmd = &cobra.Command{
Expand Down

0 comments on commit 9b8175a

Please sign in to comment.