Skip to content

Commit 4362107

Browse files
committed
chore(edge): fix review comments
relates to STACKITCLI-357
1 parent 553bca6 commit 4362107

18 files changed

Lines changed: 163 additions & 187 deletions

File tree

docs/stackit_beta_edge-cloud_kubeconfig_create.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,35 @@ An expiration time can be set for the kubeconfig. The expiration time is set in
1212
Note: the format for the duration is <value><unit>, e.g. 30d for 30 days. You may not combine units.
1313

1414
```
15-
stackit beta edge-cloud kubeconfig create kubeconfig for INSTANCE_ID [flags]
15+
stackit beta edge-cloud kubeconfig create [flags]
1616
```
1717

1818
### Examples
1919

2020
```
2121
Create or update a kubeconfig for the Edge Cloud instance with instance ID "xxx". If the config exists in the kubeconfig file, the information will be updated.
22-
$ stackit beta edge-cloud kubeconfig create xxx
22+
$ stackit beta edge-cloud kubeconfig create --instance-id xxx
2323
2424
Create or update a kubeconfig for the Edge Cloud instance with instance ID "xxx" in a custom filepath.
25-
$ stackit beta edge-cloud kubeconfig create xxx --filepath yyy
25+
$ stackit beta edge-cloud kubeconfig create --instance-id xxx --filepath yyy
2626
2727
Get a kubeconfig for the Edge Cloud instance with instance ID "xxx" without writing it to a file and format the output as json.
28-
$ stackit beta edge-cloud kubeconfig create xxx --disable-writing --output-format json
28+
$ stackit beta edge-cloud kubeconfig create --instance-id xxx --disable-writing --output-format json
2929
3030
Create a kubeconfig for the Edge Cloud instance with instance ID "xxx". This will replace your current kubeconfig file.
31-
$ stackit beta edge-cloud kubeconfig create xxx --overwrite
31+
$ stackit beta edge-cloud kubeconfig create --instance-id xxx --overwrite
3232
```
3333

3434
### Options
3535

3636
```
37-
--disable-writing Disable writing the kubeconfig to a file.
38-
-e, --expiration string Expiration time for the kubeconfig, e.g. 5d. By default, the token is valid for 1h.
39-
-f, --filepath string Path to the kubeconfig file. A default is chosen by Kubernetes if not set.
40-
-h, --help Help for "stackit beta edge-cloud kubeconfig create"
41-
--overwrite Force overwrite the kubeconfig file if it exists.
42-
--switch-context Switch to the context in the kubeconfig file to the new context.
37+
--disable-writing Disable writing the kubeconfig to a file.
38+
-e, --expiration string Expiration time for the kubeconfig, e.g. 5d. By default, the token is valid for 1h.
39+
-f, --filepath string Path to the kubeconfig file. A default is chosen by Kubernetes if not set.
40+
-h, --help Help for "stackit beta edge-cloud kubeconfig create"
41+
--instance-id string Edge Cloud instance ID
42+
--overwrite Force overwrite the kubeconfig file if it exists.
43+
--switch-context Switch to the context in the kubeconfig file to the new context.
4344
```
4445

4546
### Options inherited from parent commands

docs/stackit_beta_edge-cloud_token_create.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ An expiration time can be set for the token. The expiration time is set in secon
1010
Note: the format for the duration is <value><unit>, e.g. 30d for 30 days. You may not combine units.
1111

1212
```
13-
stackit beta edge-cloud token create token for INSTANCE_ID [flags]
13+
stackit beta edge-cloud token create [flags]
1414
```
1515

1616
### Examples
1717

1818
```
1919
Create a token for the Edge Cloud instance with instance ID "xxx".
20-
$ stackit beta edge-cloud token create xxx
20+
$ stackit beta edge-cloud token create --instance-id xxx
2121
2222
Create a token for the Edge Cloud instance with instance ID "xxx". The token will be valid for one day.
23-
$ stackit beta edge-cloud token create xxx --expiration 1d
23+
$ stackit beta edge-cloud token create --instance-id xxx --expiration 1d
2424
```
2525

2626
### Options
2727

2828
```
29-
-e, --expiration string Expiration time for the token, e.g. 5d. By default, the token is valid for 1h.
30-
-h, --help Help for "stackit beta edge-cloud token create"
29+
-e, --expiration string Expiration time for the token, e.g. 5d. By default, the token is valid for 1h.
30+
-h, --help Help for "stackit beta edge-cloud token create"
31+
--instance-id string Edge Cloud instance ID
3132
```
3233

3334
### Options inherited from parent commands

internal/cmd/beta/edge/instance/create/create.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const (
3030

3131
type inputModel struct {
3232
*globalflags.GlobalFlagModel
33-
DisplayName *string
34-
Description string
35-
PlanId *string
33+
DisplayName string
34+
Description *string
35+
PlanId string
3636
}
3737

3838
// NewCmd https://aip.stackit.cloud/aip/general/0121/
@@ -118,19 +118,19 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
118118
return nil, &cliErr.ProjectIdError{}
119119
}
120120

121-
displayNameValue := flags.FlagToStringPointer(p, cmd, displayNameFlag)
121+
displayNameValue := flags.FlagToStringValue(p, cmd, displayNameFlag)
122122
planIdValue := flags.FlagToStringValue(p, cmd, planIdFlag)
123123
err := utils.ValidateUUID(planIdValue)
124124
if err != nil {
125125
return nil, err
126126
}
127-
descriptionValue := flags.FlagToStringValue(p, cmd, descriptionFlag)
127+
descriptionValue := flags.FlagToStringPointer(p, cmd, descriptionFlag)
128128

129129
model := inputModel{
130130
GlobalFlagModel: globalFlags,
131131
DisplayName: displayNameValue,
132132
Description: descriptionValue,
133-
PlanId: &planIdValue,
133+
PlanId: planIdValue,
134134
}
135135

136136
p.DebugInputModel(model)
@@ -141,20 +141,20 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *edge.APICli
141141
req = apiClient.DefaultAPI.CreateInstance(ctx, model.ProjectId, model.Region)
142142

143143
payload := edge.CreateInstancePayload{
144-
DisplayName: *model.DisplayName,
145-
Description: &model.Description,
146-
PlanId: *model.PlanId,
144+
DisplayName: model.DisplayName,
145+
Description: model.Description,
146+
PlanId: model.PlanId,
147147
}
148148

149149
return req.CreateInstancePayload(payload), nil
150150
}
151151

152152
func outputResult(p *print.Printer, model *inputModel, projectLabel string, instance *edge.Instance) error {
153-
if instance == nil {
154-
return fmt.Errorf("instance response is empty")
155-
}
156-
157153
return p.OutputResult(model.OutputFormat, instance, func() error {
154+
if instance == nil {
155+
return fmt.Errorf("instance response is empty")
156+
}
157+
158158
operationState := "Created"
159159
if model.Async {
160160
operationState = "Triggered creation of"

internal/cmd/beta/edge/instance/create/create_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ import (
1919
type testCtxKey struct{}
2020

2121
var (
22-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
23-
testProjectId = uuid.NewString()
24-
testRegion = "eu01"
22+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
23+
testProjectId = uuid.NewString()
24+
testPlanId = uuid.NewString()
25+
testInstanceId = uuid.NewString()
26+
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
27+
)
2528

29+
const (
30+
testRegion = "eu01"
2631
testName = "test"
27-
testPlanId = uuid.NewString()
2832
testDescription = "Initial instance description"
29-
testInstanceId = uuid.NewString()
30-
31-
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
3233
)
3334

3435
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
@@ -52,9 +53,9 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5253
Region: testRegion,
5354
Verbosity: globalflags.VerbosityDefault,
5455
},
55-
DisplayName: utils.Ptr(testName),
56-
Description: testDescription,
57-
PlanId: utils.Ptr(testPlanId),
56+
DisplayName: testName,
57+
Description: utils.Ptr(testDescription),
58+
PlanId: testPlanId,
5859
}
5960
for _, mod := range mods {
6061
mod(model)
@@ -165,15 +166,14 @@ func TestBuildRequest(t *testing.T) {
165166
Region: testRegion,
166167
Verbosity: globalflags.VerbosityDefault,
167168
},
168-
DisplayName: utils.Ptr(testName),
169-
PlanId: utils.Ptr(testPlanId),
169+
DisplayName: testName,
170+
PlanId: testPlanId,
170171
},
171172
expectedRequest: testClient.DefaultAPI.
172173
CreateInstance(testCtx, testProjectId, testRegion).
173174
CreateInstancePayload(edge.CreateInstancePayload{
174175
DisplayName: testName,
175176
PlanId: testPlanId,
176-
Description: utils.Ptr(""),
177177
}),
178178
},
179179
}

internal/cmd/beta/edge/instance/delete/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6262
projectLabel = model.ProjectId
6363
}
6464

65-
instanceLabel, err := edgeUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.InstanceId, model.Region)
65+
instanceLabel, err := edgeUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.ProjectId, model.Region, model.InstanceId)
6666
if err != nil {
6767
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
6868
instanceLabel = model.InstanceId
@@ -95,7 +95,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9595
if model.Async {
9696
operationState = "Triggered deletion of"
9797
}
98-
params.Printer.Info("%s instance %q of project %q.\n", operationState, instanceLabel, projectLabel)
98+
params.Printer.Outputf("%s instance %q of project %q.\n", operationState, instanceLabel, projectLabel)
9999
return nil
100100
},
101101
}

internal/cmd/beta/edge/instance/delete/delete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ var (
1919
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2020
testProjectId = uuid.NewString()
2121
testInstanceId = uuid.NewString()
22-
testRegion = "eu01"
23-
24-
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
22+
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
2523
)
2624

25+
const testRegion = "eu01"
26+
2727
func fixtureArgValues(mods ...func(argValues []string)) []string {
2828
argValues := []string{
2929
testInstanceId,

internal/cmd/beta/edge/instance/describe/describe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *edge.APICli
9494
}
9595

9696
func outputResult(p *print.Printer, outputFormat string, instance *edge.Instance) error {
97-
if instance == nil {
98-
return fmt.Errorf("instance response is empty")
99-
}
100-
10197
return p.OutputResult(outputFormat, instance, func() error {
98+
if instance == nil {
99+
return fmt.Errorf("instance response is empty")
100+
}
101+
102102
table := tables.NewTable()
103103
table.AddRow("ID", instance.Id)
104104
table.AddSeparator()

internal/cmd/beta/edge/instance/describe/describe_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ import (
1717
type testCtxKey struct{}
1818

1919
var (
20-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
testProjectId = uuid.NewString()
22-
testRegion = "eu01"
23-
20+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21+
testProjectId = uuid.NewString()
2422
testInstanceId = uuid.NewString()
25-
26-
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
23+
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
2724
)
2825

26+
const testRegion = "eu01"
27+
2928
func fixtureArgValues(mods ...func(argValues []string)) []string {
3029
argValues := []string{
3130
testInstanceId,
@@ -153,8 +152,10 @@ func TestOutputResult(t *testing.T) {
153152
wantErr bool
154153
}{
155154
{
156-
name: "empty",
157-
args: args{},
155+
name: "instance is nil",
156+
args: args{
157+
instance: nil,
158+
},
158159
wantErr: true,
159160
},
160161
{

internal/cmd/beta/edge/instance/list/list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ func outputResult(p *print.Printer, outputFormat, projectLabel string, instances
127127

128128
table := tables.NewTable()
129129
table.SetHeader("ID", "NAME", "UI", "STATE")
130-
for i := range instances {
131-
instance := instances[i]
130+
for _, instance := range instances {
132131
table.AddRow(
133132
instance.Id,
134133
instance.DisplayName,

internal/cmd/beta/edge/instance/list/list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type testCtxKey struct{}
2020
var (
2121
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
2222
testProjectId = uuid.NewString()
23-
testRegion = "eu01"
24-
25-
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
23+
testClient = &edge.APIClient{DefaultAPI: &edge.DefaultAPIService{}}
2624
)
2725

26+
const testRegion = "eu01"
27+
2828
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
2929
flagValues := map[string]string{
3030
globalflags.ProjectIdFlag: testProjectId,

0 commit comments

Comments
 (0)