Skip to content

feat(opensearch): region adjustments and migration to new SDK structure#1474

Open
SerseusWasTaken wants to merge 3 commits into
mainfrom
feat/opensearch-sdk-migration
Open

feat(opensearch): region adjustments and migration to new SDK structure#1474
SerseusWasTaken wants to merge 3 commits into
mainfrom
feat/opensearch-sdk-migration

Conversation

@SerseusWasTaken

Copy link
Copy Markdown
Contributor

Description

Migrate opensearch to v2 SDK API

relates to STACKITCLI-372

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)

@SerseusWasTaken SerseusWasTaken requested a review from a team as a code owner July 13, 2026 13:26
func GetCredentialsUsername(ctx context.Context, apiClient OpenSearchClient, projectId, instanceId, credentialsId string) (string, error) {
resp, err := apiClient.GetCredentialsExecute(ctx, projectId, instanceId, credentialsId)
func GetCredentialsUsername(ctx context.Context, apiClient OpenSearchClient, projectId, region, instanceId, credentialsId string) (string, error) {
resp, err := apiClient.GetCredentials(ctx, projectId, instanceId, region, credentialsId).Execute()

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.

region must be added before instanceId

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.

Good catch!

}
}

type OpenSearchClient interface {

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.

I think we can remove this client and use the apiClient directly. Like we have done for other services

https://github.com/stackitcloud/stackit-cli/pull/1449/changes#diff-fbfa081e40e62c1d42769762ff3cbb0db379d43baed6ec03fcbe53a4b7f628b7L32

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.

will do


var (
testProjectId = uuid.NewString()
testRegion = "eu01"

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.

can you shift this to const area?

return req
}

func outputResult(p *print.Printer, outputFormat string, showPassword bool, instanceLabel string, resp *opensearch.CredentialsResponse) 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.

nitpick: not introduced by this PR so you can just skip it :) but I think instead of outputFormat and showPassword, we can parse here the model and then read the values in the function.

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.

Out of curiosity: what would be the upside to that? I think it's better to keep the arguments precise. Since the function only needs these two args from the model, i think passing the whole model here would make it less clear on what the function depends on from the model.
If the function changes in the future and more fields are needed from the model then i would see the argument. But i think two args is reasonable

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.

I am also fine with 2 args :) It is just to align with similar service implementations. We added some checks like this

if model.GlobalFlagModel == nil {

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.

Ah i see. In that case i'm going to adjust it

@GokceGK GokceGK changed the title opensearch sdk migration feat(opensearch): region adjustments and migration to new SDK structure Jul 14, 2026
@github-actions

Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/create 58.49% (+1.63%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/delete 37.50% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/describe 70.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/list 60.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/create 61.80% (+0.69%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/delete 26.83% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/describe 59.57% (+7.49%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/list 40.43% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/update 59.38% (+0.43%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/plans 55.77% (ø)
github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils 26.67% (+1.67%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/create/create.go 58.49% (+1.63%) 53 (+2) 31 (+2) 22 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/delete/delete.go 37.50% (ø) 40 15 25
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/describe/describe.go 70.00% (ø) 50 35 15
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/list/list.go 60.00% (ø) 50 30 20
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/create/create.go 61.80% (+0.69%) 89 (-1) 55 34 (-1) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/delete/delete.go 26.83% (ø) 41 11 30
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/describe/describe.go 59.57% (+7.49%) 47 (-1) 28 (+3) 19 (-4) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/list/list.go 40.43% (ø) 47 19 28
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/update/update.go 59.38% (+0.43%) 96 (+1) 57 (+1) 39 👍
github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/plans/plans.go 55.77% (ø) 52 29 23
github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client/client.go 0.00% (ø) 1 0 1
github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils/utils.go 26.67% (+1.67%) 30 (-2) 8 22 (-2) 👍

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/opensearch/credentials/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/delete/delete_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/create/create_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/delete/delete_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/describe/describe_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/update/update_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/plans/plans_test.go
  • github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils/utils_test.go

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