Skip to content

Commit

Permalink
Fix LB update
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Nov 25, 2024
1 parent 4347614 commit 8a11da1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions cmd/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ Each field is separated by '|'`

lbInstancePoolExample := `Define instance pool configurations for the load balancer.
Use this format:
--instance-pool "tags=web,db|names=frontend,backend|protocol=http|source-port=80|target-port=8080|health-check.port=8080|health-check.path=/health"
--instance-pool "tags=web,db|names=frontend,backend|protocol=TCP|source-port=80|target-port=8080|health-check.port=8080|health-check.path=/health"
Each field is separated by '|'`

lbUpdateBackendExample := `Update backend configurations for the load balancer.
Use this format:
--backends "ip=10.0.0.1;protocol=http;source-port=80;target-port=8080;health-check-port=8080"
Each field is separated by ';'.
If you need multiple backends, use the flag multiple times.`

lbUpdateInstancePoolExample := `Update instance pool configurations for the load balancer.
Use this format:
--instance-pools "tags=web,db;names=frontend,backend;protocol=TCP;source-port=80;target-port=8080;health-check.port=8080;health-check.path=/health"
Each field is separated by ';'.
If you need multiple instance pools, use the flag multiple times.`

LoadBalancerCmd.AddCommand(loadBalancerListCmd)
LoadBalancerCmd.AddCommand(loadBalancerShowCmd)
LoadBalancerCmd.AddCommand(loadBalancerRemoveCmd)
Expand All @@ -51,8 +63,8 @@ Each field is separated by '|'`
loadBalancerCreateCmd.Flags().StringSliceVar(&lbInstancePools, "instance-pool", []string{}, lbInstancePoolExample)

// Balancer update subcommand
loadBalancerUpdateCmd.Flags().StringVarP(&lbNameUpdate, "name", "", "", "New name of the load balancer to be update")
loadBalancerUpdateCmd.Flags().StringVarP(&lbAlgorithmUpdate, "algorithm", "a", "", "<round_robin | least_connections> - LoadBalancing algorithm to distribute traffic")
loadBalancerUpdateCmd.Flags().StringArrayVarP(&lbBackendsUpdate, "backends", "b", []string{}, "Specify a backend instance to associate with the load balancer. Takes ip, protocol(optional), source-port, target-port and health-check-port(optional) in the format --backend=ip:instance-ip,protocol:HTTP|TCP,source-port:80,target-port:31579,health-check-port:31580")
loadBalancerUpdateCmd.Flags().StringArrayVarP(&lbInstancePoolsUpdate, "instance-pools", "i", []string{}, "Specify instance pool configurations. Takes tags, names, protocol, source-port, target-port, health-check.port, health-check.path in the format 'tags=tag1,tag2;names=name1,name2;protocol=http;source-port=80;target-port=8080;health-check.port=8080;health-check.path=/health'")
loadBalancerUpdateCmd.Flags().StringVarP(&lbNameUpdate, "name", "", "", "New name of the load balancer to update (optional)")
loadBalancerUpdateCmd.Flags().StringVarP(&lbAlgorithmUpdate, "algorithm", "a", "", "<round_robin | least_connections> - LoadBalancing algorithm to distribute traffic (optional)")
loadBalancerUpdateCmd.Flags().StringArrayVarP(&lbBackendsUpdate, "backends", "b", []string{}, lbUpdateBackendExample)
loadBalancerUpdateCmd.Flags().StringArrayVarP(&lbInstancePoolsUpdate, "instance-pools", "i", []string{}, lbUpdateInstancePoolExample)
}
4 changes: 2 additions & 2 deletions cmd/loadbalancer/loadbalancer_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var loadBalancerUpdateCmd = &cobra.Command{
os.Exit(1)
}

configLoadBalancer := &civogo.LoadBalancerUpdateConfig{}
configLoadBalancer := &civogo.LoadBalancerUpdateConfig{Region: client.Region}

if lbNameUpdate != "" {
configLoadBalancer.Name = lbNameUpdate
Expand Down Expand Up @@ -156,7 +156,7 @@ var loadBalancerUpdateCmd = &cobra.Command{

loadBalancerUpdate, err := client.UpdateLoadBalancer(loadBalancer.ID, configLoadBalancer)
if err != nil {
utility.Error("%s", err)
utility.Error("error while updating the LB: %s", err)
os.Exit(1)
}

Expand Down

0 comments on commit 8a11da1

Please sign in to comment.