Skip to content

Commit 4080d5a

Browse files
committed
feat(alb): review findings
1 parent b0ed6ea commit 4080d5a

File tree

12 files changed

+112
-42
lines changed

12 files changed

+112
-42
lines changed

docs/stackit_beta_alb_create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stackit beta alb create [flags]
2020
### Options
2121

2222
```
23-
-c, --configuration string filename of the input configuration file
23+
-c, --configuration string Filename of the input configuration file
2424
-h, --help Help for "stackit beta alb create"
2525
```
2626

docs/stackit_beta_alb_describe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Describes an application loadbalancer
44

55
### Synopsis
66

7-
Describes an application loadbalancer.
7+
Describes an application alb.
88

99
```
1010
stackit beta alb describe LOADBALANCER_NAME_ARG [flags]

docs/stackit_beta_alb_pool_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ stackit beta alb pool update [flags]
2020
### Options
2121

2222
```
23-
-c, --configuration string filename of the input configuration file
23+
-c, --configuration string Filename of the input configuration file
2424
-h, --help Help for "stackit beta alb pool update"
25-
-n, --name string name of the target pool name to update
25+
-n, --name string Name of the target pool name to update
2626
```
2727

2828
### Options inherited from parent commands

docs/stackit_beta_alb_update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stackit beta alb update [flags]
2020
### Options
2121

2222
```
23-
-c, --configuration string filename of the input configuration file
23+
-c, --configuration string Filename of the input configuration file
2424
-h, --help Help for "stackit beta alb update"
2525
```
2626

internal/cmd/beta/alb/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
101101
}
102102

103103
func configureFlags(cmd *cobra.Command) {
104-
cmd.Flags().StringP(configurationFlag, "c", "", "filename of the input configuration file")
104+
cmd.Flags().StringP(configurationFlag, "c", "", "Filename of the input configuration file")
105105
err := flags.MarkFlagsRequired(cmd, configurationFlag)
106106
cobra.CheckErr(err)
107107
}

internal/cmd/beta/alb/delete/delete.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,13 @@ func NewCmd(p *print.Printer) *cobra.Command {
7070
return fmt.Errorf("delete loadbalancer: %w", err)
7171
}
7272

73-
p.Outputln("Load balancer deleted.")
73+
p.Outputf("Load balancer %q deleted.", model.Name)
7474
return nil
7575
},
7676
}
77-
configureFlags(cmd)
7877
return cmd
7978
}
8079

81-
func configureFlags(_ *cobra.Command) {
82-
}
83-
8480
func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
8581
globalFlags := globalflags.Parse(p, cmd)
8682

internal/cmd/beta/alb/describe/describe.go

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
3333
cmd := &cobra.Command{
3434
Use: fmt.Sprintf("describe %s", loadbalancerNameArg),
3535
Short: "Describes an application loadbalancer",
36-
Long: "Describes an application loadbalancer.",
36+
Long: "Describes an application alb.",
3737
Args: args.SingleArg(loadbalancerNameArg, nil),
3838
Example: examples.Build(
3939
examples.NewExample(
@@ -117,33 +117,104 @@ func outputResult(p *print.Printer, outputFormat string, response *alb.LoadBalan
117117

118118
return nil
119119
default:
120-
table := tables.NewTable()
121-
table.AddRow("EXTERNAL ADDRESS", utils.PtrString(response.ExternalAddress))
122-
table.AddSeparator()
123-
var numErrors int
124-
if response.Errors != nil {
125-
numErrors = len(*response.Errors)
126-
}
127-
table.AddRow("NUMBER OF ERRORS", numErrors)
128-
table.AddSeparator()
129-
table.AddRow("PLAN ID", utils.PtrString(response.PlanId))
130-
table.AddSeparator()
131-
table.AddRow("REGION", utils.PtrString(response.Region))
132-
table.AddSeparator()
133-
table.AddRow("STATUS", utils.PtrString(response.Status))
134-
table.AddSeparator()
135-
table.AddRow("VERSION", utils.PtrString(response.Version))
136-
if response.Errors != nil {
137-
table.AddSeparator()
138-
var builder strings.Builder
139-
for _, err := range *response.Errors {
140-
builder.WriteString(fmt.Sprintf("[%s] %s\n", utils.PtrString(err.Type), utils.PtrString(err.Description)))
141-
}
142-
table.AddRow("ERRORS", builder.String())
120+
if err := outputResultAsTable(p, response); err != nil {
121+
return err
143122
}
123+
}
144124

145-
p.Outputln(table.Render())
125+
return nil
126+
}
127+
128+
func outputResultAsTable(p *print.Printer, loadbalancer *alb.LoadBalancer) error {
129+
content := []tables.Table{}
130+
131+
content = append(content, buildLoadBalancerTable(loadbalancer))
132+
133+
if loadbalancer.Listeners != nil {
134+
content = append(content, buildListenersTable(*loadbalancer.Listeners))
135+
}
136+
137+
if loadbalancer.TargetPools != nil {
138+
content = append(content, buildTargetPoolsTable(*loadbalancer.TargetPools))
139+
}
140+
141+
err := tables.DisplayTables(p, content)
142+
if err != nil {
143+
return fmt.Errorf("display output: %w", err)
146144
}
147145

148146
return nil
149147
}
148+
149+
func buildLoadBalancerTable(loadbalancer *alb.LoadBalancer) tables.Table {
150+
acl := []string{}
151+
privateAccessOnly := false
152+
if loadbalancer.Options != nil {
153+
if loadbalancer.Options.AccessControl != nil && loadbalancer.Options.AccessControl.AllowedSourceRanges != nil {
154+
acl = *loadbalancer.Options.AccessControl.AllowedSourceRanges
155+
}
156+
157+
if loadbalancer.Options.PrivateNetworkOnly != nil {
158+
privateAccessOnly = *loadbalancer.Options.PrivateNetworkOnly
159+
}
160+
}
161+
162+
networkId := "-"
163+
if loadbalancer.Networks != nil && len(*loadbalancer.Networks) > 0 {
164+
networks := *loadbalancer.Networks
165+
networkId = *networks[0].NetworkId
166+
}
167+
168+
externalAddress := utils.PtrStringDefault(loadbalancer.ExternalAddress, "-")
169+
170+
errorDescriptions := []string{}
171+
if loadbalancer.Errors != nil && len((*loadbalancer.Errors)) > 0 {
172+
for _, err := range *loadbalancer.Errors {
173+
errorDescriptions = append(errorDescriptions, *err.Description)
174+
}
175+
}
176+
177+
table := tables.NewTable()
178+
table.SetTitle("Load Balancer")
179+
table.AddRow("NAME", utils.PtrString(loadbalancer.Name))
180+
table.AddSeparator()
181+
table.AddRow("STATE", utils.PtrString(loadbalancer.Status))
182+
table.AddSeparator()
183+
if len(errorDescriptions) > 0 {
184+
table.AddRow("ERROR DESCRIPTIONS", strings.Join(errorDescriptions, "\n"))
185+
table.AddSeparator()
186+
}
187+
table.AddRow("PRIVATE ACCESS ONLY", privateAccessOnly)
188+
table.AddSeparator()
189+
table.AddRow("ATTACHED PUBLIC IP", externalAddress)
190+
table.AddSeparator()
191+
table.AddRow("ATTACHED NETWORK ID", networkId)
192+
table.AddSeparator()
193+
table.AddRow("ACL", acl)
194+
return table
195+
}
196+
197+
func buildListenersTable(listeners []alb.Listener) tables.Table {
198+
table := tables.NewTable()
199+
table.SetTitle("Listeners")
200+
table.SetHeader("NAME", "PORT", "PROTOCOL", "TARGET POOL")
201+
for i := range listeners {
202+
listener := listeners[i]
203+
table.AddRow(
204+
utils.PtrString(listener.Name),
205+
utils.PtrString(listener.Port),
206+
utils.PtrString(listener.Protocol),
207+
)
208+
}
209+
return table
210+
}
211+
212+
func buildTargetPoolsTable(targetPools []alb.TargetPool) tables.Table {
213+
table := tables.NewTable()
214+
table.SetTitle("Target Pools")
215+
table.SetHeader("NAME", "PORT", "TARGETS")
216+
for _, targetPool := range targetPools {
217+
table.AddRow(utils.PtrString(targetPool.Name), utils.PtrString(targetPool.TargetPort), len(*targetPool.Targets))
218+
}
219+
return table
220+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
9090
}
9191

9292
func configureFlags(cmd *cobra.Command) {
93-
cmd.Flags().StringP(configurationFlag, "c", "", "filename of the input configuration file")
94-
cmd.Flags().StringP(albNameFlag, "n", "", "name of the target pool name to update")
93+
cmd.Flags().StringP(configurationFlag, "c", "", "Filename of the input configuration file")
94+
cmd.Flags().StringP(albNameFlag, "n", "", "Name of the target pool name to update")
9595
err := flags.MarkFlagsRequired(cmd, configurationFlag, albNameFlag)
9696
cobra.CheckErr(err)
9797
}

internal/cmd/beta/alb/template/template-alb.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ targetPools:
8686
# allows defining the TLS configuration
8787
# tlsConfig:
8888
# # A PEM and base64 encoded certificate
89-
# customCa: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tDQpNSUlEbkRDQ0EwS2dBd0lCQWdJUkFNUmhrL3pZWkh5UUVDRjQwd3JrTHMwd0NnWUlLb1pJemowRUF3SXdPekVMDQpNQWtHQTFVRUJoTUNWVk14SGpBY0JnTlZCQW9URlVkdmIyZHNaU0JVY25WemRDQlRaWEoyYVdObGN6RU1NQW9HDQpBMVVFQXhNRFYwVXlNQjRYRFRJMU1ETXlNREV4TWpFeU0xb1hEVEkxTURZeE1qRXhNakV5TWxvd0ZqRVVNQklHDQpBMVVFQXd3TEtpNW5iMjluYkdVdVpHVXdXVEFUQmdjcWhrak9QUUlCQmdncWhrak9QUU1CQndOQ0FBUUtNUldLDQpyZTV2RUtkVkNVam9oSlJxSitZdnJ6Mmg2RlpwTGo4SkpHTUlEajh1VlNzY0MvNG9jOURtRDI1c0ZhWnhlUytRDQozcVpGU1FkamxLTGdaRTdPbzRJQ1NqQ0NBa1l3RGdZRFZSMFBBUUgvQkFRREFnZUFNQk1HQTFVZEpRUU1NQW9HDQpDQ3NHQVFVRkJ3TUJNQXdHQTFVZEV3RUIvd1FDTUFBd0hRWURWUjBPQkJZRUZHQVY3ekQvT0Nvd1RrTmhjNGN0DQpEM2lpZ0FnTE1COEdBMVVkSXdRWU1CYUFGSFcreEhldWlmWkVOMzNQc1dnZkhScnIzRFJaTUZnR0NDc0dBUVVGDQpCd0VCQkV3d1NqQWhCZ2dyQmdFRkJRY3dBWVlWYUhSMGNE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/cmd/beta/alb/template/template-pool.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ targets:
1717
# allows defining the TLS configuration
1818
# tlsConfig:
1919
# # A PEM and base64 encoded certificate
20-
# customCa: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tDQpNSUlEbkRDQ0EwS2dBd0lCQWdJUkFNUmhrL3pZWkh5UUVDRjQwd3JrTHMwd0NnWUlLb1pJemowRUF3SXdPekVMDQpNQWtHQTFVRUJoTUNWVk14SGpBY0JnTlZCQW9URlVkdmIyZHNaU0JVY25WemRDQlRaWEoyYVdObGN6RU1NQW9HDQpBMVVFQXhNRFYwVXlNQjRYRFRJMU1ETXlNREV4TWpFeU0xb1hEVEkxTURZeE1qRXhNakV5TWxvd0ZqRVVNQklHDQpBMVVFQXd3TEtpNW5iMjluYkdVdVpHVXdXVEFUQmdjcWhrak9QUUlCQmdncWhrak9QUU1CQndOQ0FBUUtNUldLDQpyZTV2RUtkVkNVam9oSlJxSitZdnJ6Mmg2RlpwTGo4SkpHTUlEajh1VlNzY0MvNG9jOURtRDI1c0ZhWnhlUytRDQozcVpGU1FkamxLTGdaRTdPbzRJQ1NqQ0NBa1l3RGdZRFZSMFBBUUgvQkFRREFnZUFNQk1HQTFVZEpRUU1NQW9HDQpDQ3NHQVFVRkJ3TUJNQXdHQTFVZEV3RUIvd1FDTUFBd0hRWURWUjBPQkJZRUZHQVY3ekQvT0Nvd1RrTmhjNGN0DQpEM2lpZ0FnTE1COEdBMVVkSXdRWU1CYUFGSFcreEhldWlmWkVOMzNQc1dnZkhScnIzRFJaTUZnR0NDc0dBUVVGDQpCd0VCQkV3d1NqQWhCZ2dyQmdFRkJRY3dBWVlWYUhSMGNEb3ZMMjh1Y0d0cExtZHZiMmN2ZDJVeU1DVUdDQ3NHDQpBUVVGQnpBQ2hobG9kSFJ3T2k4dmFTNXdhMmt1WjI5dlp5OTNaVEl1WTNKME1DRUdBMVVkRVFR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