diff --git a/e2e/disable_ingress_wildcard_test.go b/e2e/disable_ingress_wildcard_test.go index 4c327f17..9d9f234f 100644 --- a/e2e/disable_ingress_wildcard_test.go +++ b/e2e/disable_ingress_wildcard_test.go @@ -7,7 +7,6 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" @@ -15,11 +14,11 @@ import ( extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("creating an Ingress with a wildcard when it is denied for the Tenant", func() { @@ -54,8 +53,7 @@ var _ = Describe("creating an Ingress with a wildcard when it is denied for the It("should fail creating an extensions/v1beta1 Ingress with a wildcard hostname", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -135,8 +133,7 @@ var _ = Describe("creating an Ingress with a wildcard when it is denied for the It("should fail creating an networking.k8s.io/v1beta1 Ingress with a wildcard hostname", func() { if err := k8sClient.List(context.Background(), &networkingv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -216,8 +213,7 @@ var _ = Describe("creating an Ingress with a wildcard when it is denied for the It("should fail creating an networking.k8s.io/v1 Ingress with a wildcard hostname", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_class_extensions_test.go b/e2e/ingress_class_extensions_test.go index af601e7f..c0054663 100644 --- a/e2e/ingress_class_extensions_test.go +++ b/e2e/ingress_class_extensions_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/utils/pointer" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", func() { @@ -72,8 +71,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", By("non-specifying at all", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -96,8 +94,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", }) By("defining as deprecated annotation", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -123,8 +120,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", }) By("using the ingressClassName", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -158,8 +154,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", for _, c := range tnt.Spec.IngressOptions.AllowedClasses.Exact { Eventually(func() (err error) { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -186,8 +181,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", It("should allow enabled class using the ingressClassName field", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -232,8 +226,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", Eventually(func() (err error) { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -267,8 +260,7 @@ var _ = Describe("when Tenant handles Ingress classes with extensions/v1beta1", Eventually(func() (err error) { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_class_networking_test.go b/e2e/ingress_class_networking_test.go index 35f5ab05..242e2b2c 100644 --- a/e2e/ingress_class_networking_test.go +++ b/e2e/ingress_class_networking_test.go @@ -7,7 +7,6 @@ package e2e import ( "context" - "errors" "fmt" "strconv" "strings" @@ -15,7 +14,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" @@ -25,6 +23,7 @@ import ( capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1", func() { @@ -158,8 +157,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should block a non allowed class", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -241,8 +239,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled class using the deprecated annotation for networking.k8s.io/v1", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -281,8 +278,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled class using the ingressClassName field", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -319,8 +315,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled Ingress by regex using the deprecated annotation", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -358,8 +353,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled Ingress by regex using the ingressClassName field", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -395,8 +389,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled Ingress by selector using the deprecated annotation", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -451,8 +444,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should allow enabled Ingress by selector using the ingressClassName field", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -535,8 +527,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should mutate to default tenant IngressClass (class exists)", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -575,8 +566,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("shoult mutate to default tenant IngressClass although the cluster global one is not allowed", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -622,8 +612,7 @@ var _ = Describe("when Tenant handles Ingress classes with networking.k8s.io/v1" It("should mutate to default tenant IngressClass although the cluster global one is allowed", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_hostnames_collision_cluster_scope_test.go b/e2e/ingress_hostnames_collision_cluster_scope_test.go index fa23e49f..0836489e 100644 --- a/e2e/ingress_hostnames_collision_cluster_scope_test.go +++ b/e2e/ingress_hostnames_collision_cluster_scope_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when handling Cluster scoped Ingress hostnames collision", func() { @@ -156,8 +155,7 @@ var _ = Describe("when handling Cluster scoped Ingress hostnames collision", fun By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -191,8 +189,7 @@ var _ = Describe("when handling Cluster scoped Ingress hostnames collision", fun By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_hostnames_collision_disabled_test.go b/e2e/ingress_hostnames_collision_disabled_test.go index e8139ec7..ff8ccd09 100644 --- a/e2e/ingress_hostnames_collision_disabled_test.go +++ b/e2e/ingress_hostnames_collision_disabled_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when disabling Ingress hostnames collision", func() { @@ -130,8 +129,7 @@ var _ = Describe("when disabling Ingress hostnames collision", func() { By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -171,8 +169,7 @@ var _ = Describe("when disabling Ingress hostnames collision", func() { By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_hostnames_collision_namespace_scope_test.go b/e2e/ingress_hostnames_collision_namespace_scope_test.go index 66b5eabf..3f76bd49 100644 --- a/e2e/ingress_hostnames_collision_namespace_scope_test.go +++ b/e2e/ingress_hostnames_collision_namespace_scope_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when handling Namespace scoped Ingress hostnames collision", func() { @@ -130,8 +129,7 @@ var _ = Describe("when handling Namespace scoped Ingress hostnames collision", f By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -172,8 +170,7 @@ var _ = Describe("when handling Namespace scoped Ingress hostnames collision", f By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_hostnames_collision_tenant_scope_test.go b/e2e/ingress_hostnames_collision_tenant_scope_test.go index 7081ae02..4e430ebb 100644 --- a/e2e/ingress_hostnames_collision_tenant_scope_test.go +++ b/e2e/ingress_hostnames_collision_tenant_scope_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when handling Tenant scoped Ingress hostnames collision", func() { @@ -133,8 +132,7 @@ var _ = Describe("when handling Tenant scoped Ingress hostnames collision", func By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -168,8 +166,7 @@ var _ = Describe("when handling Tenant scoped Ingress hostnames collision", func By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/ingress_hostnames_test.go b/e2e/ingress_hostnames_test.go index cabf671e..5824da7b 100644 --- a/e2e/ingress_hostnames_test.go +++ b/e2e/ingress_hostnames_test.go @@ -7,19 +7,18 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("when Tenant handles Ingress hostnames", func() { @@ -129,8 +128,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -152,8 +150,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -175,8 +172,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -200,8 +196,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -225,8 +220,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing networking.k8s.io", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -250,8 +244,7 @@ var _ = Describe("when Tenant handles Ingress hostnames", func() { By("testing extensions", func() { if err := k8sClient.List(context.Background(), &extensionsv1beta1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } diff --git a/e2e/service_metadata_test.go b/e2e/service_metadata_test.go index 0db3959e..382bdb09 100644 --- a/e2e/service_metadata_test.go +++ b/e2e/service_metadata_test.go @@ -7,7 +7,6 @@ package e2e import ( "context" - "errors" "fmt" . "github.com/onsi/ginkgo" @@ -16,7 +15,6 @@ import ( discoveryv1 "k8s.io/api/discovery/v1" discoveryv1beta1 "k8s.io/api/discovery/v1beta1" networkingv1 "k8s.io/api/networking/v1" - "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" @@ -25,6 +23,7 @@ import ( capsulev1beta2 "github.com/clastix/capsule/api/v1beta2" "github.com/clastix/capsule/pkg/api" + "github.com/clastix/capsule/pkg/utils" ) var _ = Describe("adding metadata to Service objects", func() { @@ -222,8 +221,7 @@ var _ = Describe("adding metadata to Service objects", func() { It("should apply them to EndpointSlice in v1", func() { if err := k8sClient.List(context.Background(), &networkingv1.IngressList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } } @@ -254,8 +252,7 @@ var _ = Describe("adding metadata to Service objects", func() { var eps client.Object if err := k8sClient.List(context.Background(), &discoveryv1.EndpointSliceList{}); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { Skip(fmt.Sprintf("Running test due to unsupported API kind: %s", err.Error())) } diff --git a/pkg/indexer/indexer.go b/pkg/indexer/indexer.go index c2b3cdb5..e726ca8b 100644 --- a/pkg/indexer/indexer.go +++ b/pkg/indexer/indexer.go @@ -8,11 +8,9 @@ import ( "fmt" "github.com/go-logr/logr" - "github.com/pkg/errors" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" - "k8s.io/apimachinery/pkg/api/meta" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -21,6 +19,7 @@ import ( "github.com/clastix/capsule/pkg/indexer/namespace" "github.com/clastix/capsule/pkg/indexer/tenant" "github.com/clastix/capsule/pkg/indexer/tenantresource" + "github.com/clastix/capsule/pkg/utils" ) type CustomIndexer interface { @@ -43,8 +42,7 @@ func AddToManager(ctx context.Context, log logr.Logger, mgr manager.Manager) err for _, f := range indexers { if err := mgr.GetFieldIndexer().IndexField(ctx, f.Object(), f.Field(), f.Func()); err != nil { - missingAPIError := &meta.NoKindMatchError{} - if errors.As(err, &missingAPIError) { + if utils.IsUnsupportedAPI(err) { log.Info(fmt.Sprintf("skipping setup of Indexer %T for object %T", f, f.Object()), "error", err.Error()) continue diff --git a/pkg/utils/errors.go b/pkg/utils/errors.go new file mode 100644 index 00000000..cc552035 --- /dev/null +++ b/pkg/utils/errors.go @@ -0,0 +1,16 @@ +// Copyright 2020-2021 Clastix Labs +// SPDX-License-Identifier: Apache-2.0 + +package utils + +import ( + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/client-go/discovery" +) + +func IsUnsupportedAPI(err error) bool { + missingAPIError, discoveryError := &meta.NoKindMatchError{}, &discovery.ErrGroupDiscoveryFailed{} + + return errors.As(err, &missingAPIError) || errors.As(err, &discoveryError) +}