Skip to content

Commit c4917a4

Browse files
STAC-23211: Accept specific stackpack version during provisioning
1 parent c8454ac commit c4917a4

8 files changed

Lines changed: 89 additions & 19 deletions

File tree

‎cmd/stackpack/stackpack_install.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type InstallArgs struct {
1717
Name string
1818
UnlockedStrategy string
19+
Version string
1920
Params map[string]string
2021
Wait bool
2122
Timeout time.Duration
@@ -33,7 +34,10 @@ func StackpackInstallCommand(cli *di.Deps) *cobra.Command {
3334
sts stackpack install --name example -p "full_name=First Last" -p URL=https://stackstate.com
3435
3536
# install and wait for completion
36-
sts stackpack install --name kubernetes -p cluster_name=production --wait`,
37+
sts stackpack install --name kubernetes -p cluster_name=production --wait
38+
39+
# install a specific (older) version, e.g. to downgrade
40+
sts stackpack install --name example --stackpack-version 1.2.3 -p "full_name=First Last"`,
3741
RunE: cli.CmdRunEWithApi(RunStackpackInstallCommand(args)),
3842
}
3943
common.AddRequiredNameFlagVar(cmd, &args.Name, "Name of the StackPack")
@@ -44,6 +48,7 @@ sts stackpack install --name kubernetes -p cluster_name=production --wait`,
4448
"Strategy use to upgrade StackPack instance"+
4549
fmt.Sprintf(" (must be { %s })", strings.Join(UnlockedStrategyChoices, " | ")),
4650
)
51+
cmd.Flags().StringVar(&args.Version, StackpackVersionFlag, "", "Install a specific version of the StackPack (for downgrade). The StackPack must not already be installed at a different version.")
4752
cmd.Flags().StringToStringVarP(&args.Params, ParameterFlag, "p", args.Params, "List of parameters of the form \"key=value\"")
4853
cmd.Flags().BoolVar(&args.Wait, "wait", false, "Wait for installation to complete")
4954
cmd.Flags().DurationVar(&args.Timeout, "timeout", DefaultTimeout, "Timeout for waiting")
@@ -57,7 +62,11 @@ func RunStackpackInstallCommand(args *InstallArgs) di.CmdWithApiFn {
5762
api *stackstate_api.APIClient,
5863
serverInfo *stackstate_api.ServerInfo,
5964
) common.CLIError {
60-
instance, resp, err := api.StackpackApi.ProvisionDetails(cli.Context, args.Name).RequestBody(args.Params).Unlocked(args.UnlockedStrategy).Execute()
65+
apiRequest := api.StackpackApi.ProvisionDetails(cli.Context, args.Name).RequestBody(args.Params).Unlocked(args.UnlockedStrategy)
66+
if args.Version != "" {
67+
apiRequest = apiRequest.Version(args.Version)
68+
}
69+
instance, resp, err := apiRequest.Execute()
6170
if err != nil {
6271
return common.NewResponseError(err, resp)
6372
}

‎cmd/stackpack/stackpack_install_test.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,34 @@ func TestStackpackInstallNoParameters(t *testing.T) {
112112
)
113113
}
114114

115+
func TestStackpackInstallWithVersion(t *testing.T) {
116+
cli, cmd := setupStackPackInstallCmd(t)
117+
118+
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "install", "--name", "zabbix",
119+
"--stackpack-version", "3.2.0",
120+
)
121+
122+
strategyFlag := FailStrategy
123+
versionFlag := "3.2.0"
124+
assert.Equal(t,
125+
stackstate_api.ProvisionDetailsCall{
126+
PstackPackName: "zabbix",
127+
Punlocked: &strategyFlag,
128+
Pversion: &versionFlag,
129+
PrequestBody: &map[string]string{},
130+
},
131+
(*cli.MockClient.ApiMocks.StackpackApi.ProvisionDetailsCalls)[0],
132+
)
133+
}
134+
135+
func TestStackpackInstallWithoutVersion(t *testing.T) {
136+
cli, cmd := setupStackPackInstallCmd(t)
137+
138+
di.ExecuteCommandWithContextUnsafe(&cli.Deps, cmd, "install", "--name", "zabbix")
139+
140+
assert.Nil(t, (*cli.MockClient.ApiMocks.StackpackApi.ProvisionDetailsCalls)[0].Pversion)
141+
}
142+
115143
func TestStackpackInstallPrintsToJson(t *testing.T) {
116144
cli, cmd := setupStackPackInstallCmd(t)
117145

‎generated/stackstate_api/api/openapi.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,14 @@ paths:
413413
required: true
414414
schema:
415415
type: string
416+
- description: "Optional version string (e.g. '1.2.3'). If not provided, the\
417+
\ latest version is used. When provisioning, the StackPack cannot already\
418+
\ be installed at a different version."
419+
in: query
420+
name: version
421+
required: false
422+
schema:
423+
type: string
416424
requestBody:
417425
content:
418426
application/json:
@@ -14857,7 +14865,7 @@ components:
1485714865
properties:
1485814866
_type:
1485914867
enum:
14860-
- ErrorPresentationComponentLink
14868+
- ErrorComponentPresentationLink
1486114869
type: string
1486214870
linkId:
1486314871
description: Identity key for this link.
@@ -20781,7 +20789,6 @@ components:
2078120789
$ref: '#/components/schemas/PresentationHighlightMetricsSection'
2078220790
type: array
2078320791
required:
20784-
- fields
2078520792
- title
2078620793
type: object
2078720794
PresentationHighlightField:

‎generated/stackstate_api/api_stackpack.go‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎generated/stackstate_api/docs/PresentationHighlight.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**Title** | **string** | |
8-
**Fields** | [**[]PresentationHighlightField**](PresentationHighlightField.md) | |
8+
**Fields** | Pointer to [**[]PresentationHighlightField**](PresentationHighlightField.md) | | [optional]
99
**Provisioning** | Pointer to [**PresentationHighlightProvisioning**](PresentationHighlightProvisioning.md) | | [optional]
1010
**RelatedResources** | Pointer to [**[]PresentationRelatedResource**](PresentationRelatedResource.md) | | [optional]
1111
**Links** | Pointer to [**[]PresentationLink**](PresentationLink.md) | | [optional]
@@ -16,7 +16,7 @@ Name | Type | Description | Notes
1616

1717
### NewPresentationHighlight
1818

19-
`func NewPresentationHighlight(title string, fields []PresentationHighlightField, ) *PresentationHighlight`
19+
`func NewPresentationHighlight(title string, ) *PresentationHighlight`
2020

2121
NewPresentationHighlight instantiates a new PresentationHighlight object
2222
This constructor will assign default values to properties that have it defined,
@@ -70,6 +70,11 @@ and a boolean to check if the value has been set.
7070

7171
SetFields sets Fields field to given value.
7272

73+
### HasFields
74+
75+
`func (o *PresentationHighlight) HasFields() bool`
76+
77+
HasFields returns a boolean if a field has been set.
7378

7479
### GetProvisioning
7580

‎generated/stackstate_api/docs/StackpackApi.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Name | Type | Description | Notes
9292

9393
## ProvisionDetails
9494

95-
> ProvisionResponse ProvisionDetails(ctx, stackPackName).Unlocked(unlocked).RequestBody(requestBody).Execute()
95+
> ProvisionResponse ProvisionDetails(ctx, stackPackName).Unlocked(unlocked).Version(version).RequestBody(requestBody).Execute()
9696
9797
Provision API
9898

@@ -113,11 +113,12 @@ import (
113113
func main() {
114114
stackPackName := "stackPackName_example" // string |
115115
unlocked := "unlocked_example" // string |
116+
version := "version_example" // string | Optional version string (e.g. '1.2.3'). If not provided, the latest version is used. When provisioning, the StackPack cannot already be installed at a different version. (optional)
116117
requestBody := map[string]string{"key": "Inner_example"} // map[string]string | (optional)
117118

118119
configuration := openapiclient.NewConfiguration()
119120
apiClient := openapiclient.NewAPIClient(configuration)
120-
resp, r, err := apiClient.StackpackApi.ProvisionDetails(context.Background(), stackPackName).Unlocked(unlocked).RequestBody(requestBody).Execute()
121+
resp, r, err := apiClient.StackpackApi.ProvisionDetails(context.Background(), stackPackName).Unlocked(unlocked).Version(version).RequestBody(requestBody).Execute()
121122
if err != nil {
122123
fmt.Fprintf(os.Stderr, "Error when calling `StackpackApi.ProvisionDetails``: %v\n", err)
123124
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
@@ -144,6 +145,7 @@ Name | Type | Description | Notes
144145
------------- | ------------- | ------------- | -------------
145146

146147
**unlocked** | **string** | |
148+
**version** | **string** | Optional version string (e.g. '1.2.3'). If not provided, the latest version is used. When provisioning, the StackPack cannot already be installed at a different version. |
147149
**requestBody** | **map[string]string** | |
148150

149151
### Return type

‎generated/stackstate_api/model_presentation_highlight.go‎

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎stackstate_openapi/openapi_version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9c9f7edc3fc4bf1b8f62092b80f6ed50fcd8be2e
1+
3889f3a46f6a2405349b35221fb60aad09eafe14

0 commit comments

Comments
 (0)