Skip to content

Commit 1913cc5

Browse files
committed
feat(alb): retrieve target pool name from configuration file
1 parent 4567443 commit 1913cc5

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

internal/cmd/beta/alb/pool/update/update.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ import (
2626
const (
2727
configurationFlag = "configuration"
2828
albNameFlag = "name"
29-
poolNameFlag = "pool"
3029
)
3130

3231
type inputModel struct {
3332
*globalflags.GlobalFlagModel
3433
Configuration *string
3534
AlbName *string
36-
Poolname *string
3735
}
3836

3937
func NewCmd(p *print.Printer) *cobra.Command {
@@ -44,8 +42,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
4442
Args: args.NoArgs,
4543
Example: examples.Build(
4644
examples.NewExample(
47-
`Update an application target pool from a configuration file`,
48-
"$ stackit beta alb update --configuration my-target pool.json"),
45+
`Update an application target pool from a configuration file (the name of the pool is read from the file)`,
46+
"$ stackit beta alb update --configuration my-target-pool.json --name my-load-balancer"),
4947
),
5048
RunE: func(cmd *cobra.Command, _ []string) error {
5149
ctx := context.Background()
@@ -94,8 +92,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
9492
func configureFlags(cmd *cobra.Command) {
9593
cmd.Flags().StringP(configurationFlag, "c", "", "filename of the input configuration file")
9694
cmd.Flags().StringP(albNameFlag, "n", "", "name of the target pool name to update")
97-
cmd.Flags().StringP(poolNameFlag, "t", "", "name of the target pool to update")
98-
err := flags.MarkFlagsRequired(cmd, configurationFlag, albNameFlag, poolNameFlag)
95+
err := flags.MarkFlagsRequired(cmd, configurationFlag, albNameFlag)
9996
cobra.CheckErr(err)
10097
}
10198

@@ -109,7 +106,6 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
109106
GlobalFlagModel: globalFlags,
110107
Configuration: flags.FlagToStringPointer(p, cmd, configurationFlag),
111108
AlbName: flags.FlagToStringPointer(p, cmd, albNameFlag),
112-
Poolname: flags.FlagToStringPointer(p, cmd, poolNameFlag),
113109
}
114110

115111
if p.IsVerbosityDebug() {
@@ -129,7 +125,10 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *alb.APIClie
129125
if err != nil {
130126
return req, err
131127
}
132-
req = apiClient.UpdateTargetPool(ctx, model.ProjectId, model.Region, *model.AlbName, *model.Poolname)
128+
if payload.Name == nil {
129+
return req, fmt.Errorf("update target pool: no poolname provided")
130+
}
131+
req = apiClient.UpdateTargetPool(ctx, model.ProjectId, model.Region, *model.AlbName, *payload.Name)
133132
return req.UpdateTargetPoolPayload(payload), nil
134133
}
135134

internal/cmd/beta/alb/pool/update/update_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
testProjectId = uuid.NewString()
3030
testRegion = "eu01"
3131
testLoadBalancer = "my-load-balancer"
32-
testPool = "my-target"
32+
testPool = "my-target-pool"
3333
testConfig = "testdata/testconfig.json"
3434
)
3535

@@ -39,7 +39,6 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3939
configurationFlag: testConfig,
4040
globalflags.RegionFlag: testRegion,
4141
albNameFlag: testLoadBalancer,
42-
poolNameFlag: testPool,
4342
}
4443
for _, mod := range mods {
4544
mod(flagValues)
@@ -56,7 +55,6 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5655
},
5756
Configuration: utils.Ptr(testConfig),
5857
AlbName: &testLoadBalancer,
59-
Poolname: &testPool,
6058
}
6159
for _, mod := range mods {
6260
mod(model)
@@ -107,7 +105,6 @@ func TestParseInput(t *testing.T) {
107105
projectIdFlag: testProjectId,
108106
configurationFlag: testConfig,
109107
albNameFlag: testLoadBalancer,
110-
poolNameFlag: testPool,
111108
},
112109
isValid: true,
113110
expectedModel: &inputModel{
@@ -117,7 +114,6 @@ func TestParseInput(t *testing.T) {
117114
},
118115
Configuration: &testConfig,
119116
AlbName: &testLoadBalancer,
120-
Poolname: &testPool,
121117
},
122118
},
123119
{
@@ -210,7 +206,6 @@ func TestBuildRequest(t *testing.T) {
210206
},
211207
Configuration: &testConfig,
212208
AlbName: &testLoadBalancer,
213-
Poolname: &testPool,
214209
},
215210
expectedRequest: testClient.
216211
UpdateTargetPool(testCtx, testProjectId, testRegion, testLoadBalancer, testPool).

0 commit comments

Comments
 (0)