Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v2.2.x] Properly detect unsupported API errors #4477

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/flux/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"context"
"errors"
"fmt"
"os"
"strings"
Expand All @@ -28,7 +27,6 @@ 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"

Expand Down Expand Up @@ -178,8 +176,7 @@ 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)) {
if getAll && apimeta.IsNoMatchError(err) {
return nil
}
return err
Expand Down
5 changes: 2 additions & 3 deletions cmd/flux/get_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ limitations under the License.
package main

import (
"strings"

"github.com/spf13/cobra"
apimeta "k8s.io/apimachinery/pkg/api/meta"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
Expand Down Expand Up @@ -87,7 +86,7 @@ var getAllCmd = &cobra.Command{
}

func logError(err error) {
if !strings.Contains(err.Error(), "no matches for kind") {
if !apimeta.IsNoMatchError(err) {
logger.Failuref(err.Error())
}
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/flux/get_source_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ limitations under the License.
package main

import (
"strings"

"github.com/spf13/cobra"
apimeta "k8s.io/apimachinery/pkg/api/meta"

sourcev1 "github.com/fluxcd/source-controller/api/v1"
sourcev1b2 "github.com/fluxcd/source-controller/api/v1beta2"
Expand Down Expand Up @@ -65,7 +64,7 @@ var getSourceAllCmd = &cobra.Command{

for _, c := range allSourceCmd {
if err := c.run(cmd, args); err != nil {
if !strings.Contains(err.Error(), "no matches for kind") {
if !apimeta.IsNoMatchError(err) {
logger.Failuref(err.Error())
}
}
Expand Down
Loading