-
Notifications
You must be signed in to change notification settings - Fork 2
Add provider validation to deployment commands #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ package cmd | |
| import ( | ||
| "github.com/ProxySQL/dbdeployer/common" | ||
| "github.com/ProxySQL/dbdeployer/globals" | ||
| "github.com/ProxySQL/dbdeployer/providers" | ||
| "github.com/ProxySQL/dbdeployer/sandbox" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
@@ -28,6 +29,15 @@ func multipleSandbox(cmd *cobra.Command, args []string) { | |
| flags := cmd.Flags() | ||
| sd, err := fillSandboxDefinition(cmd, args, false) | ||
| common.ErrCheckExitf(err, 1, "error filling sandbox definition") | ||
| // Validate version with provider | ||
| // TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql" | ||
| p, provErr := providers.DefaultRegistry.Get("mysql") | ||
| if provErr != nil { | ||
| common.Exitf(1, "provider error: %s", provErr) | ||
| } | ||
| if provErr = p.ValidateVersion(sd.Version); provErr != nil { | ||
| common.Exitf(1, "version validation failed: %s", provErr) | ||
| } | ||
|
Comment on lines
+32
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This provider validation logic is duplicated in
Comment on lines
+32
to
+40
|
||
| nodes, _ := flags.GetInt(globals.NodesLabel) | ||
| sd.SBType = "multiple" | ||
| origin := args[0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ package cmd | |||||
| import ( | ||||||
| "github.com/ProxySQL/dbdeployer/common" | ||||||
| "github.com/ProxySQL/dbdeployer/globals" | ||||||
| "github.com/ProxySQL/dbdeployer/providers" | ||||||
| "github.com/ProxySQL/dbdeployer/sandbox" | ||||||
| "github.com/spf13/cobra" | ||||||
| ) | ||||||
|
|
@@ -28,6 +29,15 @@ func replicationSandbox(cmd *cobra.Command, args []string) { | |||||
| common.CheckOrigin(args) | ||||||
| sd, err := fillSandboxDefinition(cmd, args, false) | ||||||
| common.ErrCheckExitf(err, 1, "error filling sandbox definition : %s", err) | ||||||
| // Validate version with provider | ||||||
| // TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql" | ||||||
| p, provErr := providers.DefaultRegistry.Get("mysql") | ||||||
| if provErr != nil { | ||||||
| common.Exitf(1, "provider error: %s", provErr) | ||||||
| } | ||||||
| if provErr = p.ValidateVersion(sd.Version); provErr != nil { | ||||||
| common.Exitf(1, "version validation failed: %s", provErr) | ||||||
|
||||||
| common.Exitf(1, "version validation failed: %s", provErr) | |
| common.Exitf(1, "version validation failed for provider %s, version %s: %s", "mysql", sd.Version, provErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provider validation logic is duplicated in cmd/multiple.go and cmd/single.go. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a common helper function. For example, you could create a validateProvider(sd sandbox.SandboxDef) function in cmd/single.go (alongside fillSandboxDefinition) and call it from all three command files.
Copilot
AI
Mar 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provider lookup + version validation logic is duplicated across multiple deployment commands (single/replication/multiple). Consider extracting this into a shared helper (e.g., validateProviderVersion(sd) in cmd) to reduce drift and make Phase 2b (provider-from-flavor) a smaller change.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |||||||||||||||||||||||||||
| "github.com/ProxySQL/dbdeployer/common" | ||||||||||||||||||||||||||||
| "github.com/ProxySQL/dbdeployer/defaults" | ||||||||||||||||||||||||||||
| "github.com/ProxySQL/dbdeployer/globals" | ||||||||||||||||||||||||||||
| "github.com/ProxySQL/dbdeployer/providers" | ||||||||||||||||||||||||||||
| "github.com/ProxySQL/dbdeployer/sandbox" | ||||||||||||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||||||||||||
| "github.com/spf13/cobra" | ||||||||||||||||||||||||||||
|
|
@@ -445,6 +446,15 @@ func singleSandbox(cmd *cobra.Command, args []string) { | |||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| common.Exitf(1, "error while filling the sandbox definition: %+v", err) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // Validate version with provider | ||||||||||||||||||||||||||||
| // TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql" | ||||||||||||||||||||||||||||
| p, provErr := providers.DefaultRegistry.Get("mysql") | ||||||||||||||||||||||||||||
| if provErr != nil { | ||||||||||||||||||||||||||||
| common.Exitf(1, "provider error: %s", provErr) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| if provErr = p.ValidateVersion(sd.Version); provErr != nil { | ||||||||||||||||||||||||||||
| common.Exitf(1, "version validation failed: %s", provErr) | ||||||||||||||||||||||||||||
|
Comment on lines
+451
to
+456
|
||||||||||||||||||||||||||||
| p, provErr := providers.DefaultRegistry.Get("mysql") | |
| if provErr != nil { | |
| common.Exitf(1, "provider error: %s", provErr) | |
| } | |
| if provErr = p.ValidateVersion(sd.Version); provErr != nil { | |
| common.Exitf(1, "version validation failed: %s", provErr) | |
| providerName := "mysql" | |
| p, provErr := providers.DefaultRegistry.Get(providerName) | |
| if provErr != nil { | |
| common.Exitf(1, "provider error: %s", provErr) | |
| } | |
| if provErr = p.ValidateVersion(sd.Version); provErr != nil { | |
| common.Exitf(1, "version validation failed for provider %q and version %q: %s", providerName, sd.Version, provErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provider validation logic is duplicated in cmd/multiple.go and cmd/replication.go. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a common helper function. For example, you could create a validateProvider(sd sandbox.SandboxDef) function in this file (alongside fillSandboxDefinition) and call it from all three command files.
Copilot
AI
Mar 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provider lookup + version validation logic is duplicated across multiple deployment commands (single/replication/multiple). Consider extracting this into a shared helper (e.g., validateProviderVersion(sd) in cmd) to reduce drift and make Phase 2b (provider-from-flavor) a smaller change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failure message
version validation faileddoesn’t include which provider and version were being validated. Including both (e.g., provider name and sd.Version) would make CLI failures actionable, especially once multiple providers are supported.