Skip to content

feat(postgresql): Region adjustment #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/stackitcloud/stackit-sdk-go/services/iaas v0.21.1
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.18.0
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.0
github.com/stackitcloud/stackit-sdk-go/services/runcommand v0.3.0
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ github.com/stackitcloud/stackit-sdk-go/services/observability v0.3.0 h1:Hn4BwKCz
github.com/stackitcloud/stackit-sdk-go/services/observability v0.3.0/go.mod h1:PxfwA6YFtxwOajB4iTp1Eq7G02qUC3HdQPJvHGjQ1hk=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0 h1:y83IhdbQv8EHovWPTqeulGgyZKJ39AQW1klo0g7a7og=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0/go.mod h1:Gk3hWaQDCJGgaixjGkUmoIr74VNWwdAakiUrvizpOWQ=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0 h1:cwdmiwbSml70kE9xV9C25t9WggDT98NdSfWD9w/r4wU=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0/go.mod h1:wNPezvzJUgUj+C50EqyMAj5PSkhawT+2Zsdh01WQpAM=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1 h1:vUi9//CyfS6UMv0hftYMamimjJLco5lxT/KW9y4QPqM=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1/go.mod h1:7TqfCUZRW7sjv8qOrLV5IvS6jqvY9Uxka165zdjYwD4=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.21.0 h1:zEJXwsuasmYH8dONZrCsZzcann/+6HZDKUPhN3mOmY0=
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.21.0/go.mod h1:SaL9BCTeWcEmU9JiKgNihEXKnFKDTn91L9ehgvauWuM=
github.com/stackitcloud/stackit-sdk-go/services/redis v0.21.0 h1:UDIRWwiZ2/2ukmn60wPo83PUSuWPaXqbuRzkRTjRQNQ=
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/postgresflex/backup/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiGetBackupRequest {
req := apiClient.GetBackup(ctx, model.ProjectId, model.InstanceId, model.BackupId)
req := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.InstanceId, model.BackupId)
return req
}

Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/postgresflex/backup/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testBackupId = "backupID"
var testRegion = "eu01"

func fixtureArgValues(mods ...func(argValues []string)) []string {
argValues := []string{
Expand All @@ -36,8 +35,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
instanceIdFlag: testInstanceId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
instanceIdFlag: testInstanceId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -49,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: testInstanceId,
Expand All @@ -61,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *postgresflex.ApiGetBackupRequest)) postgresflex.ApiGetBackupRequest {
request := testClient.GetBackup(testCtx, testProjectId, testInstanceId, testBackupId)
request := testClient.GetBackup(testCtx, testProjectId, testRegion, testInstanceId, testBackupId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -105,23 +106,23 @@ func TestParseInput(t *testing.T) {
description: "project id missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/postgresflex/backup/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return err
}

instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId)
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, *model.InstanceId)
if err != nil {
p.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = *model.InstanceId
Expand Down Expand Up @@ -129,7 +129,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest {
req := apiClient.ListBackups(ctx, model.ProjectId, *model.InstanceId)
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
return req
}

Expand Down
19 changes: 10 additions & 9 deletions internal/cmd/postgresflex/backup/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testRegion = "eu01"

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
instanceIdFlag: testInstanceId,
limitFlag: "10",
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
instanceIdFlag: testInstanceId,
limitFlag: "10",
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: utils.Ptr(testInstanceId),
Expand All @@ -51,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
}

func fixtureRequest(mods ...func(request *postgresflex.ApiListBackupsRequest)) postgresflex.ApiListBackupsRequest {
request := testClient.ListBackups(testCtx, testProjectId, testInstanceId)
request := testClient.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
for _, mod := range mods {
mod(&request)
}
Expand Down Expand Up @@ -79,21 +80,21 @@ func TestParseInput(t *testing.T) {
{
description: "project id missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return err
}

instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId)
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, *model.InstanceId)
if err != nil {
p.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = *model.InstanceId
Expand Down Expand Up @@ -105,7 +105,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiUpdateBackupScheduleRequest {
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, *model.InstanceId)
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, *model.InstanceId)
req = req.UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{
BackupSchedule: model.BackupSchedule,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
)

var projectIdFlag = globalflags.ProjectIdFlag

type testCtxKey struct{}

var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
var testClient = &postgresflex.APIClient{}
var testProjectId = uuid.NewString()
var testInstanceId = uuid.NewString()
var testSchedule = "0 0 * * *"
var testRegion = "eu01"

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
scheduleFlag: testSchedule,
instanceIdFlag: testInstanceId,
globalflags.ProjectIdFlag: testProjectId,
globalflags.RegionFlag: testRegion,
scheduleFlag: testSchedule,
instanceIdFlag: testInstanceId,
}
for _, mod := range mods {
mod(flagValues)
Expand All @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
model := &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
Verbosity: globalflags.VerbosityDefault,
},
InstanceId: utils.Ptr(testInstanceId),
Expand All @@ -61,7 +62,7 @@ func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePaylo
}

func fixtureRequest(mods ...func(request *postgresflex.ApiUpdateBackupScheduleRequest)) postgresflex.ApiUpdateBackupScheduleRequest {
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId)
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
request = request.UpdateBackupSchedulePayload(fixturePayload())
for _, mod := range mods {
mod(&request)
Expand Down Expand Up @@ -91,21 +92,21 @@ func TestParseInput(t *testing.T) {
{
description: "project id missing",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, projectIdFlag)
delete(flagValues, globalflags.ProjectIdFlag)
}),
isValid: false,
},
{
description: "project id invalid 1",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = ""
flagValues[globalflags.ProjectIdFlag] = ""
}),
isValid: false,
},
{
description: "project id invalid 2",
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
flagValues[projectIdFlag] = "invalid-uuid"
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
}),
isValid: false,
},
Expand Down Expand Up @@ -200,10 +201,11 @@ func TestBuildRequest(t *testing.T) {
model: &inputModel{
GlobalFlagModel: &globalflags.GlobalFlagModel{
ProjectId: testProjectId,
Region: testRegion,
},
InstanceId: utils.Ptr(testInstanceId),
},
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId).
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{}),
},
}
Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/postgresflex/instance/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return err
}

instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.InstanceId)
instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, model.Region, model.InstanceId)
if err != nil {
p.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = model.InstanceId
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
if !model.Async {
s := spinner.New(p)
s.Start("Cloning instance")
_, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx)
_, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.Region, instanceId).WaitWithContext(ctx)
if err != nil {
return fmt.Errorf("wait for PostgreSQL Flex instance cloning: %w", err)
}
Expand Down Expand Up @@ -162,25 +162,25 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
}

type PostgreSQLFlexClient interface {
CloneInstance(ctx context.Context, projectId, instanceId string) postgresflex.ApiCloneInstanceRequest
GetInstanceExecute(ctx context.Context, projectId, instanceId string) (*postgresflex.InstanceResponse, error)
ListStoragesExecute(ctx context.Context, projectId, flavorId string) (*postgresflex.ListStoragesResponse, error)
CloneInstance(ctx context.Context, projectId, region, instanceId string) postgresflex.ApiCloneInstanceRequest
GetInstanceExecute(ctx context.Context, projectId, region, instanceId string) (*postgresflex.InstanceResponse, error)
ListStoragesExecute(ctx context.Context, projectId, region, flavorId string) (*postgresflex.ListStoragesResponse, error)
}

func buildRequest(ctx context.Context, model *inputModel, apiClient PostgreSQLFlexClient) (postgresflex.ApiCloneInstanceRequest, error) {
req := apiClient.CloneInstance(ctx, model.ProjectId, model.InstanceId)
req := apiClient.CloneInstance(ctx, model.ProjectId, model.Region, model.InstanceId)

var storages *postgresflex.ListStoragesResponse
if model.StorageClass != nil || model.StorageSize != nil {
currentInstance, err := apiClient.GetInstanceExecute(ctx, model.ProjectId, model.InstanceId)
currentInstance, err := apiClient.GetInstanceExecute(ctx, model.ProjectId, model.Region, model.InstanceId)
if err != nil {
return req, fmt.Errorf("get PostgreSQL Flex instance: %w", err)
}
validationFlavorId := currentInstance.Item.Flavor.Id
currentInstanceStorageClass := currentInstance.Item.Storage.Class
currentInstanceStorageSize := currentInstance.Item.Storage.Size

storages, err = apiClient.ListStoragesExecute(ctx, model.ProjectId, *validationFlavorId)
storages, err = apiClient.ListStoragesExecute(ctx, model.ProjectId, model.Region, *validationFlavorId)
if err != nil {
return req, fmt.Errorf("get PostgreSQL Flex storages: %w", err)
}
Expand Down
Loading
Loading