Merge pull request #4002 from fluxcd/fix-get-all

Don't log errors with missing CRDs for "get * all" commands
pull/3489/head
Max Jonas Werner 2 years ago committed by GitHub
commit cf5e7c39e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,7 @@ package main
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"strings" "strings"
@ -27,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/discovery"
watchtools "k8s.io/client-go/tools/watch" watchtools "k8s.io/client-go/tools/watch"
"sigs.k8s.io/controller-runtime/pkg/client" "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...) err = kubeClient.List(ctx, get.list.asClientList(), listOpts...)
if err != nil { 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 return err
} }

@ -17,8 +17,6 @@ limitations under the License.
package main package main
import ( import (
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1" autov1 "github.com/fluxcd/image-automation-controller/api/v1beta1"
@ -57,9 +55,7 @@ var getImageAllCmd = &cobra.Command{
for _, c := range allImageCmd { for _, c := range allImageCmd {
if err := c.run(cmd, args); err != nil { 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())
}
} }
} }

Loading…
Cancel
Save