Skip to content

Commit 8e7e4aa

Browse files
authored
feat(postgresql): Region adjustment (#648)
Signed-off-by: Alexander Dahmen <[email protected]>
1 parent dcb09fa commit 8e7e4aa

36 files changed

+275
-254
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/stackitcloud/stackit-sdk-go/services/iaas v0.21.1
2222
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.18.0
2323
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0
24-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0
24+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1
2525
github.com/stackitcloud/stackit-sdk-go/services/resourcemanager v0.13.0
2626
github.com/stackitcloud/stackit-sdk-go/services/runcommand v0.3.0
2727
github.com/stackitcloud/stackit-sdk-go/services/secretsmanager v0.11.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ github.com/stackitcloud/stackit-sdk-go/services/observability v0.3.0 h1:Hn4BwKCz
139139
github.com/stackitcloud/stackit-sdk-go/services/observability v0.3.0/go.mod h1:PxfwA6YFtxwOajB4iTp1Eq7G02qUC3HdQPJvHGjQ1hk=
140140
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0 h1:y83IhdbQv8EHovWPTqeulGgyZKJ39AQW1klo0g7a7og=
141141
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.20.0/go.mod h1:Gk3hWaQDCJGgaixjGkUmoIr74VNWwdAakiUrvizpOWQ=
142-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0 h1:cwdmiwbSml70kE9xV9C25t9WggDT98NdSfWD9w/r4wU=
143-
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.18.0/go.mod h1:wNPezvzJUgUj+C50EqyMAj5PSkhawT+2Zsdh01WQpAM=
142+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1 h1:vUi9//CyfS6UMv0hftYMamimjJLco5lxT/KW9y4QPqM=
143+
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v1.0.1/go.mod h1:7TqfCUZRW7sjv8qOrLV5IvS6jqvY9Uxka165zdjYwD4=
144144
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.21.0 h1:zEJXwsuasmYH8dONZrCsZzcann/+6HZDKUPhN3mOmY0=
145145
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.21.0/go.mod h1:SaL9BCTeWcEmU9JiKgNihEXKnFKDTn91L9ehgvauWuM=
146146
github.com/stackitcloud/stackit-sdk-go/services/redis v0.21.0 h1:UDIRWwiZ2/2ukmn60wPo83PUSuWPaXqbuRzkRTjRQNQ=

internal/cmd/postgresflex/backup/describe/describe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
102102
}
103103

104104
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiGetBackupRequest {
105-
req := apiClient.GetBackup(ctx, model.ProjectId, model.InstanceId, model.BackupId)
105+
req := apiClient.GetBackup(ctx, model.ProjectId, model.Region, model.InstanceId, model.BackupId)
106106
return req
107107
}
108108

internal/cmd/postgresflex/backup/describe/describe_test.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import (
1414
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1515
)
1616

17-
var projectIdFlag = globalflags.ProjectIdFlag
18-
1917
type testCtxKey struct{}
2018

2119
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2220
var testClient = &postgresflex.APIClient{}
2321
var testProjectId = uuid.NewString()
2422
var testInstanceId = uuid.NewString()
2523
var testBackupId = "backupID"
24+
var testRegion = "eu01"
2625

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

3736
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3837
flagValues := map[string]string{
39-
projectIdFlag: testProjectId,
40-
instanceIdFlag: testInstanceId,
38+
globalflags.ProjectIdFlag: testProjectId,
39+
globalflags.RegionFlag: testRegion,
40+
instanceIdFlag: testInstanceId,
4141
}
4242
for _, mod := range mods {
4343
mod(flagValues)
@@ -49,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4949
model := &inputModel{
5050
GlobalFlagModel: &globalflags.GlobalFlagModel{
5151
ProjectId: testProjectId,
52+
Region: testRegion,
5253
Verbosity: globalflags.VerbosityDefault,
5354
},
5455
InstanceId: testInstanceId,
@@ -61,7 +62,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6162
}
6263

6364
func fixtureRequest(mods ...func(request *postgresflex.ApiGetBackupRequest)) postgresflex.ApiGetBackupRequest {
64-
request := testClient.GetBackup(testCtx, testProjectId, testInstanceId, testBackupId)
65+
request := testClient.GetBackup(testCtx, testProjectId, testRegion, testInstanceId, testBackupId)
6566
for _, mod := range mods {
6667
mod(&request)
6768
}
@@ -105,23 +106,23 @@ func TestParseInput(t *testing.T) {
105106
description: "project id missing",
106107
argValues: fixtureArgValues(),
107108
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
108-
delete(flagValues, projectIdFlag)
109+
delete(flagValues, globalflags.ProjectIdFlag)
109110
}),
110111
isValid: false,
111112
},
112113
{
113114
description: "project id invalid 1",
114115
argValues: fixtureArgValues(),
115116
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
116-
flagValues[projectIdFlag] = ""
117+
flagValues[globalflags.ProjectIdFlag] = ""
117118
}),
118119
isValid: false,
119120
},
120121
{
121122
description: "project id invalid 2",
122123
argValues: fixtureArgValues(),
123124
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
124-
flagValues[projectIdFlag] = "invalid-uuid"
125+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
125126
}),
126127
isValid: false,
127128
},

internal/cmd/postgresflex/backup/list/list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
6868
return err
6969
}
7070

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

131131
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest {
132-
req := apiClient.ListBackups(ctx, model.ProjectId, *model.InstanceId)
132+
req := apiClient.ListBackups(ctx, model.ProjectId, model.Region, *model.InstanceId)
133133
return req
134134
}
135135

internal/cmd/postgresflex/backup/list/list_test.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ import (
1414
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1515
)
1616

17-
var projectIdFlag = globalflags.ProjectIdFlag
18-
1917
type testCtxKey struct{}
2018

2119
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2220
var testClient = &postgresflex.APIClient{}
2321
var testProjectId = uuid.NewString()
2422
var testInstanceId = uuid.NewString()
23+
var testRegion = "eu01"
2524

2625
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2726
flagValues := map[string]string{
28-
projectIdFlag: testProjectId,
29-
instanceIdFlag: testInstanceId,
30-
limitFlag: "10",
27+
globalflags.ProjectIdFlag: testProjectId,
28+
globalflags.RegionFlag: testRegion,
29+
instanceIdFlag: testInstanceId,
30+
limitFlag: "10",
3131
}
3232
for _, mod := range mods {
3333
mod(flagValues)
@@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3939
model := &inputModel{
4040
GlobalFlagModel: &globalflags.GlobalFlagModel{
4141
ProjectId: testProjectId,
42+
Region: testRegion,
4243
Verbosity: globalflags.VerbosityDefault,
4344
},
4445
InstanceId: utils.Ptr(testInstanceId),
@@ -51,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5152
}
5253

5354
func fixtureRequest(mods ...func(request *postgresflex.ApiListBackupsRequest)) postgresflex.ApiListBackupsRequest {
54-
request := testClient.ListBackups(testCtx, testProjectId, testInstanceId)
55+
request := testClient.ListBackups(testCtx, testProjectId, testRegion, testInstanceId)
5556
for _, mod := range mods {
5657
mod(&request)
5758
}
@@ -79,21 +80,21 @@ func TestParseInput(t *testing.T) {
7980
{
8081
description: "project id missing",
8182
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
82-
delete(flagValues, projectIdFlag)
83+
delete(flagValues, globalflags.ProjectIdFlag)
8384
}),
8485
isValid: false,
8586
},
8687
{
8788
description: "project id invalid 1",
8889
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
89-
flagValues[projectIdFlag] = ""
90+
flagValues[globalflags.ProjectIdFlag] = ""
9091
}),
9192
isValid: false,
9293
},
9394
{
9495
description: "project id invalid 2",
9596
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
96-
flagValues[projectIdFlag] = "invalid-uuid"
97+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
9798
}),
9899
isValid: false,
99100
},

internal/cmd/postgresflex/backup/update-schedule/update_schedule.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
5454
return err
5555
}
5656

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

107107
func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiUpdateBackupScheduleRequest {
108-
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, *model.InstanceId)
108+
req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, model.Region, *model.InstanceId)
109109
req = req.UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{
110110
BackupSchedule: model.BackupSchedule,
111111
})

internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import (
1313
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1414
)
1515

16-
var projectIdFlag = globalflags.ProjectIdFlag
17-
1816
type testCtxKey struct{}
1917

2018
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2119
var testClient = &postgresflex.APIClient{}
2220
var testProjectId = uuid.NewString()
2321
var testInstanceId = uuid.NewString()
2422
var testSchedule = "0 0 * * *"
23+
var testRegion = "eu01"
2524

2625
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2726
flagValues := map[string]string{
28-
projectIdFlag: testProjectId,
29-
scheduleFlag: testSchedule,
30-
instanceIdFlag: testInstanceId,
27+
globalflags.ProjectIdFlag: testProjectId,
28+
globalflags.RegionFlag: testRegion,
29+
scheduleFlag: testSchedule,
30+
instanceIdFlag: testInstanceId,
3131
}
3232
for _, mod := range mods {
3333
mod(flagValues)
@@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3939
model := &inputModel{
4040
GlobalFlagModel: &globalflags.GlobalFlagModel{
4141
ProjectId: testProjectId,
42+
Region: testRegion,
4243
Verbosity: globalflags.VerbosityDefault,
4344
},
4445
InstanceId: utils.Ptr(testInstanceId),
@@ -61,7 +62,7 @@ func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePaylo
6162
}
6263

6364
func fixtureRequest(mods ...func(request *postgresflex.ApiUpdateBackupScheduleRequest)) postgresflex.ApiUpdateBackupScheduleRequest {
64-
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId)
65+
request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId)
6566
request = request.UpdateBackupSchedulePayload(fixturePayload())
6667
for _, mod := range mods {
6768
mod(&request)
@@ -91,21 +92,21 @@ func TestParseInput(t *testing.T) {
9192
{
9293
description: "project id missing",
9394
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
94-
delete(flagValues, projectIdFlag)
95+
delete(flagValues, globalflags.ProjectIdFlag)
9596
}),
9697
isValid: false,
9798
},
9899
{
99100
description: "project id invalid 1",
100101
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
101-
flagValues[projectIdFlag] = ""
102+
flagValues[globalflags.ProjectIdFlag] = ""
102103
}),
103104
isValid: false,
104105
},
105106
{
106107
description: "project id invalid 2",
107108
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
108-
flagValues[projectIdFlag] = "invalid-uuid"
109+
flagValues[globalflags.ProjectIdFlag] = "invalid-uuid"
109110
}),
110111
isValid: false,
111112
},
@@ -200,10 +201,11 @@ func TestBuildRequest(t *testing.T) {
200201
model: &inputModel{
201202
GlobalFlagModel: &globalflags.GlobalFlagModel{
202203
ProjectId: testProjectId,
204+
Region: testRegion,
203205
},
204206
InstanceId: utils.Ptr(testInstanceId),
205207
},
206-
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId).
208+
expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testRegion, testInstanceId).
207209
UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{}),
208210
},
209211
}

internal/cmd/postgresflex/instance/clone/clone.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7272
return err
7373
}
7474

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

164164
type PostgreSQLFlexClient interface {
165-
CloneInstance(ctx context.Context, projectId, instanceId string) postgresflex.ApiCloneInstanceRequest
166-
GetInstanceExecute(ctx context.Context, projectId, instanceId string) (*postgresflex.InstanceResponse, error)
167-
ListStoragesExecute(ctx context.Context, projectId, flavorId string) (*postgresflex.ListStoragesResponse, error)
165+
CloneInstance(ctx context.Context, projectId, region, instanceId string) postgresflex.ApiCloneInstanceRequest
166+
GetInstanceExecute(ctx context.Context, projectId, region, instanceId string) (*postgresflex.InstanceResponse, error)
167+
ListStoragesExecute(ctx context.Context, projectId, region, flavorId string) (*postgresflex.ListStoragesResponse, error)
168168
}
169169

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

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

183-
storages, err = apiClient.ListStoragesExecute(ctx, model.ProjectId, *validationFlavorId)
183+
storages, err = apiClient.ListStoragesExecute(ctx, model.ProjectId, model.Region, *validationFlavorId)
184184
if err != nil {
185185
return req, fmt.Errorf("get PostgreSQL Flex storages: %w", err)
186186
}

0 commit comments

Comments
 (0)