@@ -273,8 +273,10 @@ func (cr *commandRegistry) buildLoadBalancerCmd() *cobra.Command {
273273 }
274274 loadBalancerCmd .AddCommand (
275275 buildCreateLoadBalancerCmd (),
276+ buildDeleteLoadBalancerCmd (),
276277 buildLoadBalancerPGUrl (),
277278 buildLoadBalancerIP (),
279+ buildLoadBalancerList (),
278280 )
279281 return loadBalancerCmd
280282}
@@ -304,6 +306,26 @@ These resources will automatically be destroyed when the cluster is destroyed.
304306 return createLoadBalancerCmd
305307}
306308
309+ func buildDeleteLoadBalancerCmd () * cobra.Command {
310+ deleteLoadBalancerCmd := & cobra.Command {
311+ Use : "destroy <cluster>" ,
312+ Short : "destroy a load balancer for a cluster" ,
313+ Long : `Destroy a load balancer for a specific service (port), system by default, for the given cluster.
314+
315+ The load balancer is deleted using the cloud provider's API.
316+ ` ,
317+ Args : cobra .ExactArgs (1 ),
318+ Run : Wrap (func (cmd * cobra.Command , args []string ) error {
319+ return roachprod .DeleteLoadBalancer (context .Background (), config .Logger ,
320+ args [0 ], isSecure , virtualClusterName , sqlInstance ,
321+ )
322+ }),
323+ }
324+ initFlagInsecureForCmd (deleteLoadBalancerCmd )
325+ initFlagsClusterNSQLForCmd (deleteLoadBalancerCmd )
326+ return deleteLoadBalancerCmd
327+ }
328+
307329func buildLoadBalancerPGUrl () * cobra.Command {
308330 loadBalancerPGUrl := & cobra.Command {
309331 Use : "pgurl <cluster>" ,
@@ -357,6 +379,30 @@ func buildLoadBalancerIP() *cobra.Command {
357379 return loadBalancerIP
358380}
359381
382+ func buildLoadBalancerList () * cobra.Command {
383+ loadBalancerList := & cobra.Command {
384+ Use : "list <cluster>" ,
385+ Short : "list all load balancers for a cluster" ,
386+ Long : "List all load balancers and their addresses for the given cluster." ,
387+ Args : cobra .ExactArgs (1 ),
388+ Run : Wrap (func (cmd * cobra.Command , args []string ) error {
389+ addresses , err := roachprod .ListLoadBalancers (config .Logger , args [0 ])
390+ if err != nil {
391+ return err
392+ }
393+ if len (addresses ) == 0 {
394+ fmt .Println ("No load balancers found for cluster." )
395+ return nil
396+ }
397+ for _ , addr := range addresses {
398+ fmt .Printf ("%s:%d\n " , addr .IP , addr .Port )
399+ }
400+ return nil
401+ }),
402+ }
403+ return loadBalancerList
404+ }
405+
360406func (cr * commandRegistry ) buildListCmd () * cobra.Command {
361407 listCmd := & cobra.Command {
362408 Use : "list [--details | --json] [ --mine | --pattern ]" ,
0 commit comments