From 173ee5fcdc85d5db5ac988841894c9e040ff5348 Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Thu, 22 Jun 2023 17:57:23 +0200 Subject: [PATCH] Don't log errors with missing CRDs for "get * all" commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whenever an API type is not available then both, `flux get all` and `flux get image all` will just skip over that type instead of logging an error message. Before: ``` $ flux get all ✗ failed to get API group resources: unable to retrieve the complete list of server APIs: source.toolkit.fluxcd.io/v1beta2: the server could not find the requested resource [...] ✗ failed to get API group resources: unable to retrieve the complete list of server APIs: image.toolkit.fluxcd.io/v1beta2: the server could not find the requested resource ✗ failed to get API group resources: unable to retrieve the complete list of server APIs: image.toolkit.fluxcd.io/v1beta2: the server could not find the requested resource [...] $ echo $? 0 ``` After: ``` $ flux get all $ echo $? 0 ``` closes #3973 Signed-off-by: Max Jonas Werner --- cmd/flux/get.go | 6 ++++++ cmd/flux/get_image_all.go | 6 +----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/flux/get.go b/cmd/flux/get.go index 54355317..fe70006a 100644 --- a/cmd/flux/get.go +++ b/cmd/flux/get.go @@ -18,6 +18,7 @@ package main import ( "context" + "errors" "fmt" "os" "strings" @@ -27,6 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" watchtools "k8s.io/client-go/tools/watch" "sigs.k8s.io/controller-runtime/pkg/client" @@ -176,6 +178,10 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error { err = kubeClient.List(ctx, get.list.asClientList(), listOpts...) if err != nil { + var discErr *discovery.ErrGroupDiscoveryFailed + if getAll && (strings.Contains(err.Error(), "no matches for kind") || errors.As(err, &discErr)) { + return nil + } return err } diff --git a/cmd/flux/get_image_all.go b/cmd/flux/get_image_all.go index 4a37e238..83c1680c 100644 --- a/cmd/flux/get_image_all.go +++ b/cmd/flux/get_image_all.go @@ -17,8 +17,6 @@ limitations under the License. package main import ( - "strings" - "github.com/spf13/cobra" autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1" @@ -57,9 +55,7 @@ var getImageAllCmd = &cobra.Command{ for _, c := range allImageCmd { if err := c.run(cmd, args); err != nil { - if !strings.Contains(err.Error(), "no matches for kind") { - logger.Failuref(err.Error()) - } + logger.Failuref(err.Error()) } }