-
Notifications
You must be signed in to change notification settings - Fork 4
STAC-23211: Accept specific stackpack version during provisioning #154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c645c80
STAC-23211: Accept specific stackpack version during provisioning
aacevedoosorio 96ff995
STAC-23211: Implement downgrade stackpack command
aacevedoosorio b76a41e
STAC-23211: Fix lint
aacevedoosorio 070b9ad
STAC-23211: Bump openapi
aacevedoosorio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package stackpack | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/stackvista/stackstate-cli/generated/stackstate_api" | ||
| "github.com/stackvista/stackstate-cli/internal/common" | ||
| "github.com/stackvista/stackstate-cli/internal/di" | ||
| ) | ||
|
|
||
| type DowngradeArgs struct { | ||
| TypeName string | ||
| Version string | ||
| Wait bool | ||
| Timeout time.Duration | ||
| } | ||
|
|
||
| func StackpackDowngradeCommand(cli *di.Deps) *cobra.Command { | ||
| args := &DowngradeArgs{} | ||
| cmd := &cobra.Command{ | ||
| Use: "downgrade", | ||
| Short: "Downgrade a StackPack to an older version", | ||
| Long: "Downgrade all instances of a StackPack to an older version. " + | ||
| "Only supported for StackPacks 2.0 and the target version must be lower than the currently installed version. " + | ||
| "To move a StackPacks 1.0 instance to an older version, uninstall it and install the desired version instead.", | ||
| Example: `# downgrade a StackPack to an older version | ||
| sts stackpack downgrade --name kubernetes --stackpack-version 1.2.3 | ||
|
|
||
| # downgrade and wait for completion | ||
| sts stackpack downgrade --name kubernetes --stackpack-version 1.2.3 --wait`, | ||
| RunE: cli.CmdRunEWithApi(RunStackpackDowngradeCommand(args)), | ||
| } | ||
| common.AddRequiredNameFlagVar(cmd, &args.TypeName, "Name of the StackPack") | ||
| cmd.Flags().StringVar(&args.Version, StackpackVersionFlag, "", "Version to downgrade to") | ||
| cmd.MarkFlagRequired(StackpackVersionFlag) //nolint:errcheck | ||
| cmd.Flags().BoolVar(&args.Wait, "wait", false, "Wait for downgrade to complete") | ||
| cmd.Flags().DurationVar(&args.Timeout, "timeout", DefaultTimeout, "Timeout for waiting") | ||
| return cmd | ||
| } | ||
|
|
||
| func RunStackpackDowngradeCommand(args *DowngradeArgs) di.CmdWithApiFn { | ||
| return func( | ||
| cmd *cobra.Command, | ||
| cli *di.Deps, | ||
| api *stackstate_api.APIClient, | ||
| serverInfo *stackstate_api.ServerInfo, | ||
| ) common.CLIError { | ||
| _, resp, err := api.StackpackApi.DowngradeStackPack(cli.Context, args.TypeName). | ||
| Version(args.Version). | ||
| Execute() | ||
| if err != nil { | ||
| return common.NewResponseError(err, resp) | ||
| } | ||
|
|
||
| if args.Wait { | ||
| if cliErr := waitAndDisplayResult(cli, api, args.TypeName, args.Timeout, "downgrade"); cliErr != nil { | ||
| return cliErr | ||
| } | ||
| } else { | ||
| if cli.IsJson() { | ||
| cli.Printer.PrintJson(map[string]interface{}{ | ||
| "success": true, | ||
| "target-version": args.Version, | ||
| }) | ||
| } else { | ||
| cli.Printer.Success(fmt.Sprintf("Successfully triggered downgrade of %s to %s", args.TypeName, args.Version)) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package stackpack | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/stackvista/stackstate-cli/generated/stackstate_api" | ||
| "github.com/stackvista/stackstate-cli/internal/di" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var ( | ||
| downgradeVersion = "1.2.3" | ||
| ) | ||
|
|
||
| func setupStackPackDowngradeCmd(t *testing.T) (*di.MockDeps, *cobra.Command) { | ||
| cli := di.NewMockDeps(t) | ||
| cmd := StackpackDowngradeCommand(&cli.Deps) | ||
| cli.MockClient.ApiMocks.StackpackApi.DowngradeStackPackResponse.Result = successfulResponseResult | ||
| return &cli, cmd | ||
| } | ||
|
|
||
| func TestStackpackDowngradePrintToTable(t *testing.T) { | ||
| cli, cmd := setupStackPackDowngradeCmd(t) | ||
| di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "downgrade", "--name", "zabbix", | ||
| "--stackpack-version", downgradeVersion, | ||
| ) | ||
|
|
||
| assert.Equal(t, | ||
| []stackstate_api.DowngradeStackPackCall{{ | ||
| PstackPackName: "zabbix", | ||
| Pversion: &downgradeVersion, | ||
| }}, | ||
| *cli.MockClient.ApiMocks.StackpackApi.DowngradeStackPackCalls) | ||
| assert.True(t, cli.MockPrinter.HasNonJsonCalls) | ||
| assert.Equal(t, []string{"Successfully triggered downgrade of zabbix to 1.2.3"}, *cli.MockPrinter.SuccessCalls) | ||
| } | ||
|
|
||
| func TestStackpackDowngradePrintToJson(t *testing.T) { | ||
| cli, cmd := setupStackPackDowngradeCmd(t) | ||
| di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "downgrade", "--name", "zabbix", | ||
| "--stackpack-version", downgradeVersion, "-o", "json", | ||
| ) | ||
|
|
||
| assert.Equal(t, | ||
| []stackstate_api.DowngradeStackPackCall{{ | ||
| PstackPackName: "zabbix", | ||
| Pversion: &downgradeVersion, | ||
| }}, | ||
| *cli.MockClient.ApiMocks.StackpackApi.DowngradeStackPackCalls) | ||
|
|
||
| expectedJsonCalls := []map[string]interface{}{{ | ||
| "success": true, | ||
| "target-version": downgradeVersion, | ||
| }} | ||
| assert.Equal(t, expectedJsonCalls, *cli.MockPrinter.PrintJsonCalls) | ||
| } | ||
|
|
||
| func TestStackpackDowngradeRequiresVersion(t *testing.T) { | ||
| cli := di.NewMockDeps(t) | ||
| cmd := StackpackDowngradeCommand(&cli.Deps) | ||
|
|
||
| _, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, "downgrade", "--name", "zabbix") | ||
|
|
||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "stackpack-version") | ||
| } | ||
|
|
||
| func TestStackpackDowngradeHasWaitFlags(t *testing.T) { | ||
| cli := di.NewMockDeps(t) | ||
| cmd := StackpackDowngradeCommand(&cli.Deps) | ||
|
|
||
| waitFlag := cmd.Flags().Lookup("wait") | ||
| assert.NotNil(t, waitFlag, "wait flag should exist") | ||
| assert.Equal(t, "false", waitFlag.DefValue, "wait flag default should be false") | ||
|
|
||
| timeoutFlag := cmd.Flags().Lookup("timeout") | ||
| assert.NotNil(t, timeoutFlag, "timeout flag should exist") | ||
| assert.Equal(t, "1m0s", timeoutFlag.DefValue, "timeout flag default should be 1m0s") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.