From 06f123f8f4d00df63e4aeedb714623abfd3ec6c0 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 22 Aug 2024 17:16:09 +0200 Subject: [PATCH 1/2] fix(load-balancer): show message if none of --server, --label-selector or --ip is set --- internal/cmd/loadbalancer/add_target.go | 3 +++ internal/cmd/loadbalancer/remove_target.go | 3 +++ internal/cmd/util/util.go | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/internal/cmd/loadbalancer/add_target.go b/internal/cmd/loadbalancer/add_target.go index 3b3c87ba..941fb0da 100644 --- a/internal/cmd/loadbalancer/add_target.go +++ b/internal/cmd/loadbalancer/add_target.go @@ -46,6 +46,9 @@ var AddTargetCmd = base.Cmd{ labelSelector, _ := cmd.Flags().GetString("label-selector") ipAddr, _ := cmd.Flags().GetString("ip") + if !util.AnySet(serverIDOrName, labelSelector, ipAddr) { + return fmt.Errorf("specify one of --server, --label-selector, or --ip") + } if !util.ExactlyOneSet(serverIDOrName, labelSelector, ipAddr) { return fmt.Errorf("--server, --label-selector, and --ip are mutually exclusive") } diff --git a/internal/cmd/loadbalancer/remove_target.go b/internal/cmd/loadbalancer/remove_target.go index 0cbab9df..eadd3c6a 100644 --- a/internal/cmd/loadbalancer/remove_target.go +++ b/internal/cmd/loadbalancer/remove_target.go @@ -54,6 +54,9 @@ var RemoveTargetCmd = base.Cmd{ return fmt.Errorf("Load Balancer not found: %s", idOrName) } + if !util.AnySet(serverIDOrName, labelSelector, ipAddr) { + return fmt.Errorf("specify one of --server, --label-selector, or --ip") + } if !util.ExactlyOneSet(serverIDOrName, labelSelector, ipAddr) { return fmt.Errorf("--server, --label-selector, and --ip are mutually exclusive") } diff --git a/internal/cmd/util/util.go b/internal/cmd/util/util.go index e2a91e59..44240b77 100644 --- a/internal/cmd/util/util.go +++ b/internal/cmd/util/util.go @@ -88,6 +88,15 @@ func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *c } } +func AnySet(s string, ss ...string) bool { + for _, s := range append(ss, s) { + if s != "" { + return true + } + } + return false +} + func ExactlyOneSet(s string, ss ...string) bool { set := s != "" for _, s := range ss { From 9317d50d3ad8da7a93aa010a7ce5f545080f8fe7 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:58:54 +0200 Subject: [PATCH 2/2] remove unnecessary variable in util function --- internal/cmd/util/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/util/util.go b/internal/cmd/util/util.go index 44240b77..0dedb335 100644 --- a/internal/cmd/util/util.go +++ b/internal/cmd/util/util.go @@ -88,8 +88,8 @@ func ChainRunE(fns ...func(cmd *cobra.Command, args []string) error) func(cmd *c } } -func AnySet(s string, ss ...string) bool { - for _, s := range append(ss, s) { +func AnySet(ss ...string) bool { + for _, s := range ss { if s != "" { return true }