Skip to content

feat(mongodbflex): refactor implementation - #1586

Open
GokceGK wants to merge 5 commits into
mainfrom
feat/STACKITCLI-441-refactor-mongodbflex
Open

GokceGK wants to merge 5 commits into
mainfrom
feat/STACKITCLI-441-refactor-mongodbflex

Conversation

@GokceGK

@GokceGK GokceGK commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Description

relates to STACKITCLI-441

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)

@GokceGK
GokceGK requested a review from a team as a code owner September 7, 2026 07:52
ACL: []string{"0.0.0.0/0"},
BackupSchedule: "0 0/6 * * *",
FlavorId: testFlavorId,
BackupSchedule: utils.Ptr("0 0/6 * * *"),

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.

new () can be used instead of utils.Ptr()
(can be replaced everywhere)

listFlavorsResp: &mongodbflex.ListFlavorsResponse{
Flavors: []mongodbflex.InstanceFlavor{
{
Id: utils.Ptr(testFlavorId),

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.

e.g. here as well

return req, fmt.Errorf("get MongoDB Flex instance: %w", err)
var currentFlavor *mongodbflex.InstanceFlavor
for _, f := range flavors.Flavors {
if f.Id == currentInstance.Item.Flavor.Id {

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.

pointer comparison

}
model.FlavorId, err = getFlavorId(ctx, model, apiClient.DefaultAPI)
if err != nil {
return 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.

This return should be kept, right?
If flavorId was not set and the flavorId cannot be obtained via cpu and ram then we cannot proceed here

if err != nil {
return fmt.Errorf("get MongoDB Flex flavors: %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.

truncate for limit missing

if err != nil {
return fmt.Errorf("get MongoDB Flex storages: %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.

truncate for limit missing

Comment thread internal/cmd/mongodbflex/options/options.go Outdated

table := tables.NewTable()
table.SetTitle("Versions")
table.SetHeader("VERSION")

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: found during testing the table only has "VERSION".

So it looks like the following:
Versions
VERSION
8.0
7.0

Just an idea: We could remove the duplicate information?

@github-actions

Copy link
Copy Markdown

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions Bot added the Stale label Sep 24, 2026
@GokceGK GokceGK removed the Stale label Sep 28, 2026
@GokceGK
GokceGK force-pushed the feat/STACKITCLI-441-refactor-mongodbflex branch from fd3fc6c to 0679364 Compare September 30, 2026 06:15
if err != nil {
return req, err
for _, flavor := range flavors.Flavors {
if *flavor.Cpu == *model.CPU && *flavor.Memory == *model.RAM {

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.

Potential nil pointer dereference when API does not specify CPU or memory

return req, fmt.Errorf("get MongoDB Flex instance: %w", err)
var currentFlavor *mongodbflex.InstanceFlavor
for _, f := range flavors.Flavors {
if *f.Id == *currentInstance.Item.Flavor.Id {

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.

Here also potential nil pointer dereference. Probably won't happen in practice, but since the fields are optional in the API i think we should treat them as potentially nullable

Comment on lines +212 to +215
currentInstance, err := apiClient.GetInstance(ctx, model.ProjectId, model.InstanceId, model.Region).Execute()
if err != nil {
return req, fmt.Errorf("get MongoDB Flex instance: %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.

We can move the GetInstance call inside the if blocks below, since we only need to call it when the user only specifies either CPU or RAM

Comment thread internal/cmd/mongodbflex/instance/update/update.go Outdated
Comment on lines +50 to +55
versions, err := buildRequest(ctx, model, apiClient.DefaultAPI).Execute()
if err != nil {
return fmt.Errorf("get MongoDB Flex versions: %w", err)
}

return outputResult(params.Printer, model.OutputFormat, versions.Versions)

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.

--limit support missing? Or is it not required here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think --limit is not needed in here. we only have 2 versions. In other db services, version list also does not have limit

GokceGK and others added 5 commits September 30, 2026 16:20
Co-authored-by: Alexander Dahmen <alexander.dahmen@inovex.de>
Co-authored-by: Jonas Schlecht <73650029+SerseusWasTaken@users.noreply.github.com>
@GokceGK
GokceGK force-pushed the feat/STACKITCLI-441-refactor-mongodbflex branch from 1fbf61d to dcbe4c5 Compare September 30, 2026 14:20
@github-actions

Copy link
Copy Markdown

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

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/config/set 91.28% (+0.18%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset 35.04% (-0.04%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/flavor 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/flavor/list 61.54% (+61.54%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/create 46.28% (-13.72%) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/describe 60.78% (+5.56%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/list 57.45% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/update 62.40% (-1.94%) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/options 61.05% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/storage 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/storage/list 56.52% (+56.52%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/create 58.82% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/list 60.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/update 45.65% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/version 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/version/list 43.33% (+43.33%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options 57.95% (ø)
github.com/stackitcloud/stackit-cli/internal/pkg/config 70.53% (+0.10%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils 79.25% (-4.54%) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/utils 57.25% (+4.31%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/flavor/flavor.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/flavor/list/list.go 61.54% (+61.54%) 39 (+39) 24 (+24) 15 (+15) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/create/create.go 46.28% (-13.72%) 121 (+21) 56 (-4) 65 (+25) 💀
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/describe/describe.go 60.78% (+5.56%) 51 (-16) 31 (-6) 20 (-10) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/update/update.go 62.40% (-1.94%) 125 (-4) 78 (-5) 47 (+1) 👎
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/mongodbflex.go 0.00% (ø) 10 (+3) 0 10 (+3)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/options/options.go 61.05% (ø) 95 58 37
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/storage/list/list.go 56.52% (+56.52%) 46 (+46) 26 (+26) 20 (+20) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/storage/storage.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/version/list/list.go 43.33% (+43.33%) 30 (+30) 13 (+13) 17 (+17) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/version/version.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options/options.go 57.95% (ø) 88 51 37
github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils/utils.go 79.25% (-4.54%) 53 (-21) 42 (-20) 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/mongodbflex/flavor/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/options/options_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/storage/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/version/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils/utils_test.go

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants