Skip to content

Commit 459f6f2

Browse files
authored
Merge pull request #4477 from fluxcd/backport-4476-to-release/v2.2.x
[release/v2.2.x] Properly detect unsupported API errors
2 parents 53ad742 + 986e405 commit 459f6f2

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

cmd/flux/get.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
2322
"os"
2423
"strings"
@@ -28,7 +27,6 @@ import (
2827
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2928
"k8s.io/apimachinery/pkg/runtime"
3029
"k8s.io/apimachinery/pkg/watch"
31-
"k8s.io/client-go/discovery"
3230
watchtools "k8s.io/client-go/tools/watch"
3331
"sigs.k8s.io/controller-runtime/pkg/client"
3432

@@ -178,8 +176,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
178176

179177
err = kubeClient.List(ctx, get.list.asClientList(), listOpts...)
180178
if err != nil {
181-
var discErr *discovery.ErrGroupDiscoveryFailed
182-
if getAll && (strings.Contains(err.Error(), "no matches for kind") || errors.As(err, &discErr)) {
179+
if getAll && apimeta.IsNoMatchError(err) {
183180
return nil
184181
}
185182
return err

cmd/flux/get_all.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"strings"
21-
2220
"github.com/spf13/cobra"
21+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2322

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

8988
func logError(err error) {
90-
if !strings.Contains(err.Error(), "no matches for kind") {
89+
if !apimeta.IsNoMatchError(err) {
9190
logger.Failuref(err.Error())
9291
}
9392
}

cmd/flux/get_source_all.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"strings"
21-
2220
"github.com/spf13/cobra"
21+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2322

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

6665
for _, c := range allSourceCmd {
6766
if err := c.run(cmd, args); err != nil {
68-
if !strings.Contains(err.Error(), "no matches for kind") {
67+
if !apimeta.IsNoMatchError(err) {
6968
logger.Failuref(err.Error())
7069
}
7170
}

0 commit comments

Comments
 (0)