Skip to content

feat(postgresflex): migrate to v3 API - #1505

Open
rubenhoenle wants to merge 3 commits into
mainfrom
feat/postgresflex-v3-api
Open

feat(postgresflex): migrate to v3 API#1505
rubenhoenle wants to merge 3 commits into
mainfrom
feat/postgresflex-v3-api

Conversation

@rubenhoenle

Copy link
Copy Markdown
Member

Description

relates to STACKITCLI-415

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@rubenhoenle
rubenhoenle marked this pull request as ready for review July 29, 2026 13:31
@rubenhoenle
rubenhoenle requested a review from a team as a code owner July 29, 2026 13:31
@rubenhoenle
rubenhoenle force-pushed the feat/postgresflex-v3-api branch from 477d84b to 1a8fed5 Compare July 29, 2026 13:31
@github-actions

Copy link
Copy Markdown

Merging this branch changes the coverage (11 decrease, 7 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/describe 67.44% (-0.64%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/list 58.49% (-1.89%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/update-schedule 36.84% (-3.16%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/describe 78.85% (+78.85%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/list 64.52% (+64.52%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/clone 42.86% (-16.88%) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/create 46.56% (-13.44%) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/delete 33.33% (+1.39%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/describe 72.92% (-6.77%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/list 58.33% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/update 66.39% (+1.28%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options 57.95% (-0.29%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/create 54.55% (-4.64%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/delete 39.53% (+2.03%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/describe 68.18% (-0.87%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/list 60.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/reset-password 48.98% (-1.02%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/update 45.83% (+1.39%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/version 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/version/list 64.52% (+64.52%) 🌟
github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils 78.00% (-4.09%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/backup.go 0.00% (ø) 6 0 6
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/describe/describe.go 67.44% (-0.64%) 43 (-4) 29 (-3) 14 (-1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/list/list.go 58.49% (-1.89%) 53 31 (-1) 22 (+1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go 36.84% (-3.16%) 38 (+3) 14 24 (+3) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/describe/describe.go 78.85% (+78.85%) 52 (+52) 41 (+41) 11 (+11) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/flavor.go 0.00% (ø) 5 (+5) 0 5 (+5)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/list/list.go 64.52% (+64.52%) 31 (+31) 20 (+20) 11 (+11) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/clone/clone.go 42.86% (-16.88%) 70 (-7) 30 (-16) 40 (+9) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/create/create.go 46.56% (-13.44%) 131 (+31) 61 (+1) 70 (+30) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/delete/delete.go 33.33% (+1.39%) 45 (-27) 15 (-8) 30 (-19) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/describe/describe.go 72.92% (-6.77%) 48 (-16) 35 (-16) 13 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/list/list.go 58.33% (ø) 48 28 20
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/update/update.go 66.39% (+1.28%) 122 (-7) 81 (-3) 41 (-4) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options/options.go 57.95% (-0.29%) 88 (-3) 51 (-2) 37 (-1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/postgresflex.go 0.00% (ø) 9 (+2) 0 9 (+2)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/create/create.go 54.55% (-4.64%) 44 (-5) 24 (-5) 20 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/delete/delete.go 39.53% (+2.03%) 43 (+3) 17 (+2) 26 (+1) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/describe/describe.go 68.18% (-0.87%) 44 (+2) 30 (+1) 14 (+1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/list/list.go 60.00% (ø) 50 30 20
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/reset-password/reset_password.go 48.98% (-1.02%) 49 (+1) 24 25 (+1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/update/update.go 45.83% (+1.39%) 48 (+3) 22 (+2) 26 (+1) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/version/list/list.go 64.52% (+64.52%) 31 (+31) 20 (+20) 11 (+11) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/version/version.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client/client.go 0.00% (ø) 2 (+1) 0 2 (+1)
github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils/utils.go 78.00% (-4.09%) 50 (-17) 39 (-16) 11 (-1) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/flavor/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/clone/clone_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/delete/delete_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options/options_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/delete/delete_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/reset-password/reset_password_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/version/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils/utils_test.go

Comment on lines +344 to 345
Acl: model.ACL,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a new additional property accessScope. AFAIK this is needed for the private endpoints feature

Comment on lines +93 to +96
backupId, err := strconv.ParseInt(backupIdStr, 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid backup id format, must be an integer: %w", err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you can also pass a validate function in the call of args.SingleArg(backupIdArg, <function>) and check there if the input is valid.
But it's anyways required to parse here the string to int, so the validate function wouldn't have a big benefit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to just close the comment, if you don't want to add the validate function

table.SetHeader("ID", "CREATED AT", "EXPIRES AT", "BACKUP SIZE")
for i := range backups {
backup := backups[i]
table.SetHeader("ID", "CREATED AT", "RETAINED UNTIL", "BACKUP SIZE")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
table.SetHeader("ID", "CREATED AT", "RETAINED UNTIL", "BACKUP SIZE")
table.SetHeader("ID", "COMPLETED AT", "RETAINED UNTIL", "BACKUP SIZE")

cmd.Flags().String(recoveryTimestampFlag, "", "Recovery timestamp for the instance, in a date-time with the layout format YYYY-MM-DDTHH:mm:ss±HH:mm, e.g. 2006-01-02T15:04:05-07:00")
cmd.Flags().String(storageClassFlag, "", "Storage class. If not specified, storage class from the existing instance will be used.")
cmd.Flags().Int64(storageSizeFlag, 0, "Storage size (in GB). If not specified, storage size from the existing instance will be used.")
cmd.Flags().String(storageClassFlag, "", "Storage class. If not specified, storage class from the existing instance will be used. This flag will be required after 2027-01-31.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test the endpoint here, but based on the API Docs only storageSize is required, but not storageClass. Do we need to make this required in the future or what will happen if isn't just not set?

cmd.MarkFlagsRequiredTogether(encryptionKekKeyIdFlag, encryptionKekKeyringIdFlag, encryptionKekKeyVersionFlag, encryptionServiceAccountFlag)

// remove after 2027-01-31
err = cmd.Flags().MarkDeprecated("type", fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = cmd.Flags().MarkDeprecated("type", fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))
err = cmd.Flags().MarkDeprecated(typeFlag.Name(), fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))

cobra.CheckErr(err)

// remove after 2027-01-31
err = cmd.Flags().MarkDeprecated("type", fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = cmd.Flags().MarkDeprecated("type", fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))
err = cmd.Flags().MarkDeprecated(typeFlag.Name(), fmt.Sprintf("Will be removed after 2027-01-31. Use the --%s flag instead.", flavorIdFlag))

func ValidateStorage(storageClass *string, storageSize *int64, storages *postgresflex.ListStoragesResponse, flavorId string) error {
if storages == nil {
return fmt.Errorf("nil storages")
/*func ValidateStorage(storageClass *string, storageSize *int64, flavors []postgresflex.ListFlavors, flavorId string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover

return &f.Id, nil
}
availableFlavors = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", availableFlavors, *f.Cpu, *f.Cpu)
availableFlavors = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", availableFlavors, f.Cpu, f.Cpu)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
availableFlavors = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", availableFlavors, f.Cpu, f.Cpu)
availableFlavors = fmt.Sprintf("%s\n- %d CPU, %d GB RAM", availableFlavors, f.Cpu, f.Memory)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

availableFlavors isn't used at all, so this can be removed

Comment on lines +118 to 121
var waitResp *postgresflex.GetInstanceResponse

// Wait for async operation, if async mode not enabled
if !model.Async {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the update command is executed with the flag --async, the waitResp remains nil and results in an error output

backups := resp.Backups

// Truncate output
if model.Limit != nil && len(backups) > int(*model.Limit) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The used endpoint supports setting a page size. I think at this point we can just set the page size with the limit. Then we don't need to truncate the output manually and fetch the right amount of results

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies to the other list endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants