Skip to content

Commit d4b29c4

Browse files
authored
Merge pull request #161 from StackVista/STAC-24987-release-stackpacks-2
Stac 24987 release stackpacks 2
2 parents b25f052 + 57d38ed commit d4b29c4

10 files changed

Lines changed: 112 additions & 173 deletions

‎cmd/otelcomponentmapping/otelcomponentmapping_delete.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func OtelComponentMappingDeleteCommand(deps *di.Deps) *cobra.Command {
1818
cmd := &cobra.Command{
1919
Use: "delete",
2020
Short: "Delete an OTel Component Mapping by identifier (URN)",
21-
Long: "Delete an OTel Component Mapping by identifier (URN)",
21+
Long: "Delete an OTel Component Mapping by identifier (URN).",
2222
Example: `# delete a component mapping by identifier
2323
sts otel-component-mapping delete --identifier urn:stackpack:stackpack-name:shared:otel-component-mapping:service`,
2424
RunE: deps.CmdRunEWithApi(RunDeleteComponentMappingCommand(args)),

‎cmd/stackpack.go‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package cmd
22

33
import (
4-
"os"
5-
64
"github.com/spf13/cobra"
75
"github.com/stackvista/stackstate-cli/cmd/stackpack"
86
"github.com/stackvista/stackstate-cli/internal/di"
97
)
108

11-
const (
12-
experimentalStackpackEnvVar = "STS_EXPERIMENTAL_STACKPACKS"
13-
)
14-
159
func StackPackCommand(cli *di.Deps) *cobra.Command {
1610
cmd := &cobra.Command{
1711
Use: "stackpack",
@@ -31,14 +25,10 @@ func StackPackCommand(cli *di.Deps) *cobra.Command {
3125
cmd.AddCommand(stackpack.StackpackListVersionsCommand(cli))
3226
cmd.AddCommand(stackpack.StackpackDeleteVersionCommand(cli))
3327
cmd.AddCommand(stackpack.StackpackDeleteVersionsCommand(cli))
34-
35-
// The not-production-ready commands
36-
if os.Getenv(experimentalStackpackEnvVar) != "" {
37-
cmd.AddCommand(stackpack.StackpackScaffoldCommand(cli))
38-
cmd.AddCommand(stackpack.StackpackPackageCommand(cli))
39-
cmd.AddCommand(stackpack.StackpackTestDeployCommand(cli))
40-
cmd.AddCommand(stackpack.StackpackValidateCommand(cli))
41-
}
28+
cmd.AddCommand(stackpack.StackpackScaffoldCommand(cli))
29+
cmd.AddCommand(stackpack.StackpackPackageCommand(cli))
30+
cmd.AddCommand(stackpack.StackpackTestDeployCommand(cli))
31+
cmd.AddCommand(stackpack.StackpackValidateCommand(cli))
4232

4333
return cmd
4434
}

‎cmd/stackpack/stackpack_package.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ sts stackpack package --force`,
109109
RunE: cli.CmdRunE(RunStackpackPackageCommand(args)),
110110
}
111111

112-
cmd.Flags().StringVarP(&args.StackpackDir, "stackpack-directory", "d", "", "Path to stackpack directory (defaults to current directory)")
113-
cmd.Flags().StringVarP(&args.ArchiveFile, "archive-file", "f", "", "Path to the .sts file to create (defaults to <stackpack_name>-<version>.sts in current directory)")
112+
cmd.Flags().StringVarP(&args.StackpackDir, "directory", "d", "", "Path to stackpack directory (defaults to current directory)")
113+
cmd.Flags().StringVarP(&args.ArchiveFile, "file", "f", "", "Path to the .sts file to create (defaults to <stackpack_name>-<version>.sts in current directory)")
114114
cmd.Flags().BoolVar(&args.Force, "force", false, "Overwrite existing .sts file without prompting")
115115

116116
return cmd

cmd/stackpack/stackpack_test_deploy_cmd.go renamed to cmd/stackpack/stackpack_test_deploy.go

Lines changed: 80 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/stackvista/stackstate-cli/generated/stackstate_api"
1616
"github.com/stackvista/stackstate-cli/internal/common"
1717
"github.com/stackvista/stackstate-cli/internal/di"
18+
"github.com/stackvista/stackstate-cli/internal/printer"
1819
)
1920

2021
const (
@@ -59,7 +60,7 @@ sts stackpack test-deploy -d ./my-stackpack --yes`,
5960
RunE: cli.CmdRunEWithApi(RunStackpackTestDeployCommand(args)),
6061
}
6162

62-
cmd.Flags().StringVarP(&args.StackpackDir, "stackpack-directory", "d", "", "Path to stackpack directory (defaults to current directory)")
63+
cmd.Flags().StringVarP(&args.StackpackDir, "directory", "d", "", "Path to stackpack directory (defaults to current directory)")
6364
cmd.Flags().StringToStringVarP(&args.Params, ParameterFlag, "p", args.Params, "List of parameters of the form \"key=value\"")
6465
cmd.Flags().BoolVarP(&args.Yes, "yes", "y", false, "Skip confirmation prompt before upload")
6566

@@ -76,11 +77,6 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
7677
api *stackstate_api.APIClient,
7778
serverInfo *stackstate_api.ServerInfo,
7879
) common.CLIError {
79-
// Warn if JSON output is requested - not meaningful for test-deploy command
80-
if cli.IsJson() {
81-
cli.Printer.PrintLn("Warning: JSON output format is not meaningful for the test-deploy command, proceeding with text output")
82-
}
83-
8480
// Set default stackpack directory
8581
if args.StackpackDir == "" {
8682
currentDir, err := os.Getwd()
@@ -98,20 +94,20 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
9894
return common.NewRuntimeError(fmt.Errorf("failed to parse %s: %w", stackpackConfigFile, err))
9995
}
10096

101-
cli.Printer.Success("Starting stackpack test-deploy sequence...")
102-
cli.Printer.PrintLn(fmt.Sprintf(" Stackpack: %s (current version: %s)", originalInfo.Name, originalInfo.Version))
103-
cli.Printer.PrintLn("")
97+
printSuccess(cli, "Starting stackpack test-deploy sequence...")
98+
printMsg(cli, fmt.Sprintf(" Stackpack: %s (current version: %s)", originalInfo.Name, originalInfo.Version))
99+
printMsg(cli, "")
104100

105101
// Step 1: Check installed version and determine base version for snapshot
106-
cli.Printer.PrintLn("Step 1/5: Checking installed version...")
102+
printMsg(cli, "Step 1/5: Checking installed version...")
107103
installedVersion, err := getInstalledStackpackVersion(cli, api, originalInfo.Name)
108104
if err != nil {
109105
return common.NewRuntimeError(fmt.Errorf("failed to check installed stackpack version: %w", err))
110106
}
111107

112108
baseVersionForSnapshot := originalInfo.Version
113109
if installedVersion != "" {
114-
cli.Printer.PrintLn(fmt.Sprintf(" Found installed version: %s", installedVersion))
110+
printMsg(cli, fmt.Sprintf(" Found installed version: %s", installedVersion))
115111

116112
// Compare base versions (strip cli-test suffix from installed version for comparison)
117113
installedBaseVersion := installedVersion
@@ -129,15 +125,15 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
129125
baseComparison := compareVersions(installedBaseVersion, originalInfo.Version)
130126
if baseComparison > 0 || (baseComparison == 0 && strings.Contains(installedVersion, "-cli-test.")) {
131127
baseVersionForSnapshot = installedVersion
132-
cli.Printer.PrintLn(fmt.Sprintf(" Using installed version as base: %s", baseVersionForSnapshot))
128+
printMsg(cli, fmt.Sprintf(" Using installed version as base: %s", baseVersionForSnapshot))
133129
} else if baseComparison < 0 {
134-
cli.Printer.PrintLn(fmt.Sprintf(" Using local version as base (higher than installed): %s", baseVersionForSnapshot))
130+
printMsg(cli, fmt.Sprintf(" Using local version as base (higher than installed): %s", baseVersionForSnapshot))
135131
}
136132
}
137133

138134
// Step 2: Create temporary directory and copy stackpack
139-
cli.Printer.PrintLn("")
140-
cli.Printer.PrintLn("Step 2/5: Creating temporary copy for testing...")
135+
printMsg(cli, "")
136+
printMsg(cli, "Step 2/5: Creating temporary copy for testing...")
141137

142138
tempDir, err := os.MkdirTemp("", "stackpack-test-*")
143139
if err != nil {
@@ -147,30 +143,30 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
147143
// Ensure cleanup of temporary directory
148144
defer func() {
149145
if removeErr := os.RemoveAll(tempDir); removeErr != nil {
150-
cli.Printer.PrintLn(fmt.Sprintf("Warning: Failed to cleanup temporary directory: %v", removeErr))
146+
printMsg(cli, fmt.Sprintf("Warning: Failed to cleanup temporary directory: %v", removeErr))
151147
}
152148
}()
153149

154150
tempStackpackDir := filepath.Join(tempDir, "stackpack")
155151
if err := copyDirectory(args.StackpackDir, tempStackpackDir); err != nil {
156152
return common.NewRuntimeError(fmt.Errorf("failed to copy stackpack to temporary directory: %w", err))
157153
}
158-
cli.Printer.Success("Temporary copy created")
154+
printSuccess(cli, "Temporary copy created")
159155

160156
// Step 3: Update version in temporary copy
161-
cli.Printer.PrintLn("")
162-
cli.Printer.PrintLn("Step 3/5: Bumping version for testing...")
157+
printMsg(cli, "")
158+
printMsg(cli, "Step 3/5: Bumping version for testing...")
163159

164160
tempConfigPath := filepath.Join(tempStackpackDir, stackpackConfigFile)
165161
newVersion, err := bumpSnapshotVersionWithBase(tempConfigPath, baseVersionForSnapshot)
166162
if err != nil {
167163
return common.NewRuntimeError(fmt.Errorf("failed to bump version: %w", err))
168164
}
169-
cli.Printer.Success(fmt.Sprintf("Version bumped to: %s", newVersion))
165+
printSuccess(cli, fmt.Sprintf("Version bumped to: %s", newVersion))
170166

171167
// Step 4: Package stackpack from temporary directory
172-
cli.Printer.PrintLn("")
173-
cli.Printer.PrintLn("Step 4/5: Packaging stackpack...")
168+
printMsg(cli, "")
169+
printMsg(cli, "Step 4/5: Packaging stackpack...")
174170
packageArgs := &PackageArgs{
175171
StackpackDir: tempStackpackDir, // Use temporary directory
176172
Force: true, // Always overwrite for testing
@@ -183,27 +179,27 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
183179
if err := runPackageStep(cli, packageArgs); err != nil {
184180
return err
185181
}
186-
cli.Printer.Success("Stackpack packaged successfully")
182+
printSuccess(cli, "Stackpack packaged successfully")
187183

188184
// Step 5: Confirm upload (if needed) and execute upload/install workflow
189-
if !args.Yes {
190-
cli.Printer.PrintLn("")
185+
if !args.Yes && !cli.IsJson() {
186+
printMsg(cli, "")
191187
if !confirmUpload(cli, packageArgs.ArchiveFile) {
192188
return common.NewRuntimeError(fmt.Errorf("upload cancelled by user"))
193189
}
194190
}
195191

196192
// Upload stackpack
197-
cli.Printer.PrintLn("")
198-
cli.Printer.PrintLn("Step 5/5: Uploading and installing/upgrading stackpack...")
193+
printMsg(cli, "")
194+
printMsg(cli, "Step 5/5: Uploading and installing/upgrading stackpack...")
199195
uploadArgs := &UploadArgs{
200196
FilePath: packageArgs.ArchiveFile,
201197
}
202198

203199
if err := runUploadStep(cli, api, serverInfo, uploadArgs); err != nil {
204200
return err
205201
}
206-
cli.Printer.Success("Stackpack uploaded successfully")
202+
printSuccess(cli, "Stackpack uploaded successfully")
207203

208204
// Install or upgrade stackpack based on installation status
209205
if installedVersion != "" {
@@ -217,7 +213,7 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
217213
if err := runUpgradeStep(cli, api, serverInfo, upgradeArgs); err != nil {
218214
return err
219215
}
220-
cli.Printer.Success("Stackpack upgraded successfully")
216+
printSuccess(cli, "Stackpack upgraded successfully")
221217
} else {
222218
installArgs := &InstallArgs{
223219
Name: originalInfo.Name,
@@ -230,15 +226,20 @@ func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
230226
if err := runInstallStep(cli, api, serverInfo, installArgs); err != nil {
231227
return err
232228
}
233-
cli.Printer.Success("Stackpack installed successfully")
229+
printSuccess(cli, "Stackpack installed successfully")
234230
}
235231

236-
cli.Printer.PrintLn("")
237-
cli.Printer.Success("🎉 Test-deploy sequence completed successfully!")
232+
printMsg(cli, "")
233+
printSuccess(cli, "🎉 Test-deploy sequence completed successfully!")
238234

239235
// Clean up .sts file
240236
if err := os.Remove(packageArgs.ArchiveFile); err != nil {
241-
cli.Printer.PrintLn(fmt.Sprintf("Note: Could not clean up .sts file %s: %v", packageArgs.ArchiveFile, err))
237+
printMsg(cli, fmt.Sprintf("Note: Could not clean up .sts file %s: %v", packageArgs.ArchiveFile, err))
238+
} else if cli.IsJson() {
239+
cli.Printer.PrintJson(map[string]interface{}{
240+
"stackpack": originalInfo.Name,
241+
"version": newVersion,
242+
})
242243
}
243244

244245
return nil
@@ -315,8 +316,8 @@ func confirmUpload(cli *di.Deps, zipFile string) bool {
315316
serverURL = cli.CurrentContext.URL
316317
}
317318

318-
cli.Printer.PrintLn(fmt.Sprintf("⚠️ This will upload '%s' to SUSE Observability server:", filepath.Base(zipFile)))
319-
cli.Printer.PrintLn(fmt.Sprintf(" Server: %s", serverURL))
319+
printMsg(cli, fmt.Sprintf("⚠️ This will upload '%s' to SUSE Observability server:", filepath.Base(zipFile)))
320+
printMsg(cli, fmt.Sprintf(" Server: %s", serverURL))
320321
fmt.Print(" Continue? (y/N): ")
321322

322323
reader := bufio.NewReader(os.Stdin)
@@ -332,33 +333,50 @@ func confirmUpload(cli *di.Deps, zipFile string) bool {
332333
// runPackageStep executes the package command logic
333334
func runPackageStep(cli *di.Deps, args *PackageArgs) common.CLIError {
334335
// Reuse the existing package command logic
335-
packageCmd := &cobra.Command{}
336-
packageFn := RunStackpackPackageCommand(args)
337-
return packageFn(cli, packageCmd)
336+
return runCmd(cli, func(ctx *di.Deps) common.CLIError {
337+
packageCmd := &cobra.Command{}
338+
packageFn := RunStackpackPackageCommand(args)
339+
return packageFn(ctx, packageCmd)
340+
})
338341
}
339342

340343
// runUploadStep executes the upload command logic
341344
func runUploadStep(cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo, args *UploadArgs) common.CLIError {
342-
// Reuse the existing upload command logic
343-
uploadCmd := &cobra.Command{}
344-
uploadFn := RunStackpackUploadCommand(args)
345-
return uploadFn(uploadCmd, cli, api, serverInfo)
345+
return runCmd(cli, func(ctx *di.Deps) common.CLIError {
346+
// Reuse the existing upload command logic
347+
uploadCmd := &cobra.Command{}
348+
uploadFn := RunStackpackUploadCommand(args)
349+
return uploadFn(uploadCmd, ctx, api, serverInfo)
350+
})
346351
}
347352

348353
// runInstallStep executes the install command logic
349354
func runInstallStep(cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo, args *InstallArgs) common.CLIError {
350-
// Reuse the existing install command logic
351-
installCmd := &cobra.Command{}
352-
installFn := RunStackpackInstallCommand(args)
353-
return installFn(installCmd, cli, api, serverInfo)
355+
return runCmd(cli, func(ctx *di.Deps) common.CLIError {
356+
// Reuse the existing install command logic
357+
installCmd := &cobra.Command{}
358+
installFn := RunStackpackInstallCommand(args)
359+
return installFn(installCmd, ctx, api, serverInfo)
360+
})
354361
}
355362

356363
// runUpgradeStep executes the upgrade command logic
357364
func runUpgradeStep(cli *di.Deps, api *stackstate_api.APIClient, serverInfo *stackstate_api.ServerInfo, args *UpgradeArgs) common.CLIError {
358-
// Reuse the existing upgrade command logic
359-
upgradeCmd := &cobra.Command{}
360-
upgradeFn := RunStackpackUpgradeCommand(args)
361-
return upgradeFn(upgradeCmd, cli, api, serverInfo)
365+
return runCmd(cli, func(ctx *di.Deps) common.CLIError {
366+
// Reuse the existing upgrade command logic
367+
upgradeCmd := &cobra.Command{}
368+
upgradeFn := RunStackpackUpgradeCommand(args)
369+
return upgradeFn(upgradeCmd, ctx, api, serverInfo)
370+
})
371+
}
372+
373+
func runCmd(cli *di.Deps, f func(ctx *di.Deps) common.CLIError) common.CLIError {
374+
oldPr := cli.Printer
375+
pr := printer.NewMockPrinter(nil)
376+
cli.Printer = &pr
377+
err := f(cli)
378+
cli.Printer = oldPr
379+
return err
362380
}
363381

364382
// getInstalledStackpackVersion checks if a stackpack is installed and returns its version
@@ -489,3 +507,15 @@ func updateVersionInYaml(configPath, newVersion string) error {
489507

490508
return nil
491509
}
510+
511+
func printMsg(cli *di.Deps, msg string) {
512+
if !cli.IsJson() {
513+
cli.Printer.PrintLn(msg)
514+
}
515+
}
516+
517+
func printSuccess(cli *di.Deps, msg string) {
518+
if !cli.IsJson() {
519+
cli.Printer.Success(msg)
520+
}
521+
}

cmd/stackpack/stackpack_test_deploy_cmd_test.go renamed to cmd/stackpack/stackpack_test_deploy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestStackpackTestDeployCommand_FlagsAndStructure(t *testing.T) {
3333
// Test flags exist
3434
flags := cmd.Flags()
3535

36-
stackpackDirFlag := flags.Lookup("stackpack-directory")
36+
stackpackDirFlag := flags.Lookup("directory")
3737
require.NotNil(t, stackpackDirFlag)
3838
assert.Equal(t, "d", stackpackDirFlag.Shorthand)
3939

‎cmd/stackpack/stackpack_validate.go‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,17 @@ This command validates a stackpack by uploading it to the server.
3333
- If a directory is provided, it is automatically packaged into a .sts file before uploading
3434
- If a .sts file is provided, it is uploaded directly
3535
36-
Exactly one of --stackpack-directory or --stackpack-file must be specified.
37-
38-
This command is experimental and requires STS_EXPERIMENTAL_STACKPACKS environment variable to be set.`,
36+
Exactly one of --directory or --file must be specified.`,
3937
Example: `# Validate a stackpack directory (automatically packaged)
40-
sts stackpack validate --stackpack-directory ./my-stackpack
38+
sts stackpack validate --directory ./my-stackpack
4139
4240
# Validate a pre-packaged .sts file
43-
sts stackpack validate --stackpack-file ./my-stackpack.sts`,
41+
sts stackpack validate --file ./my-stackpack.sts`,
4442
RunE: cli.CmdRunEWithApi(RunStackpackValidateCommand(args)),
4543
}
4644

47-
cmd.Flags().StringVarP(&args.StackpackDir, "stackpack-directory", "d", "", "Path to stackpack directory")
48-
cmd.Flags().StringVarP(&args.StackpackFile, "stackpack-file", "f", "", "Path to .sts file")
45+
cmd.Flags().StringVarP(&args.StackpackDir, "directory", "d", "", "Path to stackpack directory")
46+
cmd.Flags().StringVarP(&args.StackpackFile, "file", "f", "", "Path to .sts file")
4947

5048
return cmd
5149
}
@@ -61,7 +59,7 @@ func RunStackpackValidateCommand(args *ValidateArgs) di.CmdWithApiFn {
6159
// Validate exactly one of directory or file is set
6260
if (args.StackpackDir == "" && args.StackpackFile == "") ||
6361
(args.StackpackDir != "" && args.StackpackFile != "") {
64-
return common.NewCLIArgParseError(fmt.Errorf("exactly one of --stackpack-directory or --stackpack-file must be specified"))
62+
return common.NewCLIArgParseError(fmt.Errorf("exactly one of --directory or --file must be specified"))
6563
}
6664

6765
// Prepare file to validate - if directory is provided, package it first

0 commit comments

Comments
 (0)