diff --git a/Dockerfiles/Dockerfile b/Dockerfiles/Dockerfile index 874be872f27..e469dcde116 100644 --- a/Dockerfiles/Dockerfile +++ b/Dockerfiles/Dockerfile @@ -37,7 +37,6 @@ COPY components/ components/ COPY controllers/ controllers/ COPY main.go main.go COPY pkg/ pkg/ -COPY infrastructure/ infrastructure/ # Copy monitoring config COPY config/monitoring/ /opt/odh-manifests/monitoring/ diff --git a/apis/dscinitialization/v1/dscinitialization_types.go b/apis/dscinitialization/v1/dscinitialization_types.go index 7fad5bcb69e..9ca21207cd6 100644 --- a/apis/dscinitialization/v1/dscinitialization_types.go +++ b/apis/dscinitialization/v1/dscinitialization_types.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" ) // +operator-sdk:csv:customresourcedefinitions:order=1 diff --git a/infrastructure/v1/cert_types.go b/apis/infrastructure/v1/cert_types.go similarity index 100% rename from infrastructure/v1/cert_types.go rename to apis/infrastructure/v1/cert_types.go diff --git a/infrastructure/v1/doc.go b/apis/infrastructure/v1/doc.go similarity index 100% rename from infrastructure/v1/doc.go rename to apis/infrastructure/v1/doc.go diff --git a/infrastructure/v1/serverless_types.go b/apis/infrastructure/v1/serverless_types.go similarity index 100% rename from infrastructure/v1/serverless_types.go rename to apis/infrastructure/v1/serverless_types.go diff --git a/infrastructure/v1/servicemesh_types.go b/apis/infrastructure/v1/servicemesh_types.go similarity index 100% rename from infrastructure/v1/servicemesh_types.go rename to apis/infrastructure/v1/servicemesh_types.go diff --git a/infrastructure/v1/zz_generated.deepcopy.go b/apis/infrastructure/v1/zz_generated.deepcopy.go similarity index 100% rename from infrastructure/v1/zz_generated.deepcopy.go rename to apis/infrastructure/v1/zz_generated.deepcopy.go diff --git a/components/kserve/kserve.go b/components/kserve/kserve.go index e11dd62f4fe..dce65a7cf34 100644 --- a/components/kserve/kserve.go +++ b/components/kserve/kserve.go @@ -13,8 +13,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring" diff --git a/components/kserve/kserve_config_handler.go b/components/kserve/kserve_config_handler.go index 39fdd62f8f9..735d2518c93 100644 --- a/components/kserve/kserve_config_handler.go +++ b/components/kserve/kserve_config_handler.go @@ -138,7 +138,7 @@ func (k *Kserve) configureServerless(cli client.Client, instance *dsciv1.DSCInit return dependOpsErrors } - serverlessFeatures := feature.ComponentFeaturesHandler(k, instance, k.configureServerlessFeatures()) + serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures()) if err := serverlessFeatures.Apply(); err != nil { return err @@ -148,7 +148,7 @@ func (k *Kserve) configureServerless(cli client.Client, instance *dsciv1.DSCInit } func (k *Kserve) removeServerlessFeatures(instance *dsciv1.DSCInitializationSpec) error { - serverlessFeatures := feature.ComponentFeaturesHandler(k, instance, k.configureServerlessFeatures()) + serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures()) return serverlessFeatures.Delete() } diff --git a/components/kserve/servicemesh_setup.go b/components/kserve/servicemesh_setup.go index e48005185e2..c8217cb8504 100644 --- a/components/kserve/servicemesh_setup.go +++ b/components/kserve/servicemesh_setup.go @@ -12,7 +12,7 @@ import ( func (k *Kserve) configureServiceMesh(dscispec *dsciv1.DSCInitializationSpec) error { if dscispec.ServiceMesh.ManagementState == operatorv1.Managed && k.GetManagementState() == operatorv1.Managed { - serviceMeshInitializer := feature.ComponentFeaturesHandler(k, dscispec, k.defineServiceMeshFeatures()) + serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures()) return serviceMeshInitializer.Apply() } if dscispec.ServiceMesh.ManagementState == operatorv1.Unmanaged && k.GetManagementState() == operatorv1.Managed { @@ -23,7 +23,7 @@ func (k *Kserve) configureServiceMesh(dscispec *dsciv1.DSCInitializationSpec) er } func (k *Kserve) removeServiceMeshConfigurations(dscispec *dsciv1.DSCInitializationSpec) error { - serviceMeshInitializer := feature.ComponentFeaturesHandler(k, dscispec, k.defineServiceMeshFeatures()) + serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures()) return serviceMeshInitializer.Delete() } @@ -44,6 +44,18 @@ func (k *Kserve) defineServiceMeshFeatures() feature.FeaturesProvider { return kserveExtAuthzErr } + temporaryFixesErr := feature.CreateFeature("kserve-temporary-fixes"). + For(handler). + Manifests( + path.Join(feature.KServeDir, "grpc-envoyfilter-temp-fix.tmpl"), + ). + WithData(servicemesh.ClusterDetails). + Load() + + if temporaryFixesErr != nil { + return temporaryFixesErr + } + return nil } } diff --git a/pkg/feature/builder.go b/pkg/feature/builder.go index 5990c1e797e..0a4f6889b9a 100644 --- a/pkg/feature/builder.go +++ b/pkg/feature/builder.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/config" featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" ) type partialBuilder func(f *Feature) error diff --git a/pkg/feature/cert.go b/pkg/feature/cert.go index 98959f792eb..8c829920221 100644 --- a/pkg/feature/cert.go +++ b/pkg/feature/cert.go @@ -19,7 +19,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" ) func (f *Feature) CreateSelfSignedCertificate(secretName string, certificateType infrav1.CertType, domain, namespace string) error { diff --git a/pkg/feature/handler.go b/pkg/feature/handler.go index 0dc539a5bb1..f2479163f7b 100644 --- a/pkg/feature/handler.go +++ b/pkg/feature/handler.go @@ -7,7 +7,6 @@ import ( v1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1" - "github.com/opendatahub-io/opendatahub-operator/v2/components" ) // FeaturesHandler coordinates feature creations and removal from within controllers. @@ -30,10 +29,10 @@ func ClusterFeaturesHandler(dsci *v1.DSCInitialization, def FeaturesProvider) *F } } -func ComponentFeaturesHandler(component components.ComponentInterface, spec *v1.DSCInitializationSpec, def FeaturesProvider) *FeaturesHandler { +func ComponentFeaturesHandler(componentName string, spec *v1.DSCInitializationSpec, def FeaturesProvider) *FeaturesHandler { return &FeaturesHandler{ DSCInitializationSpec: spec, - source: featurev1.Source{Type: featurev1.ComponentType, Name: component.GetComponentName()}, + source: featurev1.Source{Type: featurev1.ComponentType, Name: componentName}, featuresProvider: def, } } diff --git a/pkg/feature/templates/servicemesh/kserve/grpc-envoyfilter-temp-fix.tmpl b/pkg/feature/templates/servicemesh/kserve/grpc-envoyfilter-temp-fix.tmpl new file mode 100644 index 00000000000..d16a0220482 --- /dev/null +++ b/pkg/feature/templates/servicemesh/kserve/grpc-envoyfilter-temp-fix.tmpl @@ -0,0 +1,37 @@ +# Temporary workaround for https://issues.redhat.com/browse/RHOAIENG-165 +apiVersion: networking.istio.io/v1alpha3 +kind: EnvoyFilter +metadata: + name: grpc-only + namespace: {{ .ControlPlane.Namespace }} + labels: + app.opendatahub.io/kserve: "true" + app.kubernetes.io/part-of: kserve + opendatahub.io/related-to: RHOAIENG-165 +spec: + priority: 20 + workloadSelector: + labels: + protocol: "grpconly" + configPatches: + - applyTo: HTTP_FILTER + match: + context: SIDECAR_INBOUND + listener: + filterChain: + filter: + name: envoy.filters.network.http_connection_manager + patch: + operation: INSERT_BEFORE + value: + name: envoy.filters.http.lua + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua + inlineCode: | + function envoy_on_request(request_handle) + local header_value = request_handle:headers():get("Content-Type") + local pattern = "^application/grpc" + if header_value:find(pattern) == nil then + request_handle:respond({[":status"] = "400"}, "Invalid request, this endpoint only serves grpc.") + end + end diff --git a/pkg/feature/types.go b/pkg/feature/types.go index 77c30d29ece..47122458060 100644 --- a/pkg/feature/types.go +++ b/pkg/feature/types.go @@ -4,7 +4,7 @@ import ( "strings" featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" ) type Spec struct { diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 6be5b1dd3a0..fdb9f38d4cc 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -29,6 +29,7 @@ import ( kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1" dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1" dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/components/codeflare" "github.com/opendatahub-io/opendatahub-operator/v2/components/dashboard" @@ -38,7 +39,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/components/modelmeshserving" "github.com/opendatahub-io/opendatahub-operator/v2/components/ray" "github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy" ) diff --git a/tests/e2e/helper_test.go b/tests/e2e/helper_test.go index 592a95cff4b..7b80420466e 100644 --- a/tests/e2e/helper_test.go +++ b/tests/e2e/helper_test.go @@ -15,6 +15,7 @@ import ( dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1" dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components" "github.com/opendatahub-io/opendatahub-operator/v2/components/codeflare" "github.com/opendatahub-io/opendatahub-operator/v2/components/dashboard" @@ -25,7 +26,6 @@ import ( "github.com/opendatahub-io/opendatahub-operator/v2/components/ray" "github.com/opendatahub-io/opendatahub-operator/v2/components/trustyai" "github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" ) func (tc *testContext) waitForControllerDeployment(name string, replicas int32) error { diff --git a/tests/integration/features/serverless_feature_test.go b/tests/integration/features/serverless_feature_test.go index cbbc3144c66..03dc01c6536 100644 --- a/tests/integration/features/serverless_feature_test.go +++ b/tests/integration/features/serverless_feature_test.go @@ -13,8 +13,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" + infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/components/kserve" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/serverless" "github.com/opendatahub-io/opendatahub-operator/v2/tests/envtestutil" @@ -48,7 +48,7 @@ var _ = Describe("Serverless feature", func() { It("should fail on precondition check", func() { // given - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("no-serverless-operator-check"). For(handler). UsingConfig(envTest.Config). @@ -95,7 +95,7 @@ var _ = Describe("Serverless feature", func() { It("should succeed checking operator installation using precondition", func() { // when - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("serverless-operator-check"). For(handler). UsingConfig(envTest.Config). @@ -113,7 +113,7 @@ var _ = Describe("Serverless feature", func() { It("should succeed if serving is not installed for KNative serving precondition", func() { // when - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("no-serving-installed-yet"). For(handler). UsingConfig(envTest.Config). @@ -142,7 +142,7 @@ var _ = Describe("Serverless feature", func() { Expect(envTestClient.Create(context.TODO(), knativeServing)).To(Succeed()) // when - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("serving-already-installed"). For(handler). UsingConfig(envTest.Config). @@ -239,7 +239,7 @@ var _ = Describe("Serverless feature", func() { kserveComponent.Serving.IngressGateway.Certificate.Type = infrav1.SelfSigned kserveComponent.Serving.IngressGateway.Domain = fixtures.TestDomainFooCom - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("tls-secret-creation"). For(handler). UsingConfig(envTest.Config). @@ -278,7 +278,7 @@ var _ = Describe("Serverless feature", func() { // given kserveComponent.Serving.IngressGateway.Certificate.Type = infrav1.Provided kserveComponent.Serving.IngressGateway.Domain = fixtures.TestDomainFooCom - featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error { + featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error { verificationFeatureErr := feature.CreateFeature("tls-secret-creation"). For(handler). UsingConfig(envTest.Config). diff --git a/tests/integration/features/servicemesh_feature_test.go b/tests/integration/features/servicemesh_feature_test.go index 6e57f72497b..4156b12cddc 100644 --- a/tests/integration/features/servicemesh_feature_test.go +++ b/tests/integration/features/servicemesh_feature_test.go @@ -2,7 +2,6 @@ package features_test import ( "context" - "path" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -15,7 +14,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/envtest" dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" - infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/servicemesh" @@ -26,7 +24,7 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("Service Mesh setup", func() { +var _ = Describe("Service Mesh feature", func() { var ( dsci *dsciv1.DSCInitialization @@ -45,209 +43,129 @@ var _ = Describe("Service Mesh setup", func() { Expect(err).ToNot(HaveOccurred()) }) - Describe("preconditions", func() { - - Context("operator setup", func() { - - When("operator is not installed", func() { + AfterEach(func() { - It("should fail using precondition check", func() { - // given - featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - verificationFeatureErr := feature.CreateFeature("no-service-mesh-operator-check"). - For(handler). - UsingConfig(envTest.Config). - PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled). - Load() - - Expect(verificationFeatureErr).ToNot(HaveOccurred()) + }) - return nil - }) + Describe("preconditions", func() { - // when - applyErr := featuresHandler.Apply() + When("operator is not installed", func() { - // then - Expect(applyErr).To(MatchError(ContainSubstring("failed to find the pre-requisite operator subscription \"servicemeshoperator\""))) - }) - }) + It("should fail using precondition check", func() { + // given + featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { + verificationFeatureErr := feature.CreateFeature("no-service-mesh-operator-check"). + For(handler). + UsingConfig(envTest.Config). + PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled). + Load() - When("operator is installed", func() { - var smcpCrdObj *apiextensionsv1.CustomResourceDefinition + Expect(verificationFeatureErr).ToNot(HaveOccurred()) - BeforeEach(func() { - err := fixtures.CreateSubscription(fixtures.OssmSubscription, "openshift-operators", envTestClient) - Expect(err).ToNot(HaveOccurred()) - smcpCrdObj = installServiceMeshCRD() + return nil }) - AfterEach(func() { - objectCleaner.DeleteAll(smcpCrdObj) - }) + // when + applyErr := featuresHandler.Apply() - It("should succeed using precondition check", func() { - // when - featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - verificationFeatureErr := feature.CreateFeature("service-mesh-operator-check"). - For(handler). - UsingConfig(envTest.Config). - PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled). - Load() + // then + Expect(applyErr).To(MatchError(ContainSubstring("failed to find the pre-requisite operator subscription \"servicemeshoperator\""))) + }) + }) - Expect(verificationFeatureErr).ToNot(HaveOccurred()) + When("operator is installed", func() { + var smcpCrdObj *apiextensionsv1.CustomResourceDefinition - return nil - }) + BeforeEach(func() { + err := fixtures.CreateSubscription(fixtures.OssmSubscription, "openshift-operators", envTestClient) + Expect(err).ToNot(HaveOccurred()) - // when - Expect(featuresHandler.Apply()).To(Succeed()) + // Create SMCP CRD + smcpCrdObj = &apiextensionsv1.CustomResourceDefinition{} + Expect(yaml.Unmarshal([]byte(fixtures.ServiceMeshControlPlaneCRD), smcpCrdObj)).ToNot(HaveOccurred()) + c, err := client.New(envTest.Config, client.Options{}) + Expect(err).ToNot(HaveOccurred()) + Expect(c.Create(context.TODO(), smcpCrdObj)).ToNot(HaveOccurred()) - }) + crdOptions := envtest.CRDInstallOptions{PollInterval: interval, MaxTime: timeout} + err = envtest.WaitForCRDs(envTest.Config, []*apiextensionsv1.CustomResourceDefinition{smcpCrdObj}, crdOptions) + Expect(err).ToNot(HaveOccurred()) + }) - It("should find installed Service Mesh Control Plane", func() { - // given - c, err := client.New(envTest.Config, client.Options{}) - Expect(err).ToNot(HaveOccurred()) + AfterEach(func() { + // Delete SMCP CRD + objectCleaner.DeleteAll(smcpCrdObj) + }) - ns := envtestutil.AppendRandomNameTo(fixtures.TestNamespacePrefix) - nsResource := fixtures.NewNamespace(ns) - Expect(c.Create(context.Background(), nsResource)).To(Succeed()) - defer objectCleaner.DeleteAll(nsResource) + It("should succeed using precondition check", func() { + // when + featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { + verificationFeatureErr := feature.CreateFeature("service-mesh-operator-check"). + For(handler). + UsingConfig(envTest.Config). + PreConditions(servicemesh.EnsureServiceMeshOperatorInstalled). + Load() - createServiceMeshControlPlane("test-name", ns) - dsci.Spec.ServiceMesh.ControlPlane.Namespace = ns - dsci.Spec.ServiceMesh.ControlPlane.Name = "test-name" + Expect(verificationFeatureErr).ToNot(HaveOccurred()) - // when - featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - verificationFeatureErr := feature.CreateFeature("service-mesh-control-plane-check"). - For(handler). - UsingConfig(envTest.Config). - PreConditions(servicemesh.EnsureServiceMeshInstalled). - Load() + return nil + }) - Expect(verificationFeatureErr).ToNot(HaveOccurred()) + // when + Expect(featuresHandler.Apply()).To(Succeed()) - return nil - }) + }) - // then - Expect(featuresHandler.Apply()).To(Succeed()) - }) + It("should find installed Service Mesh Control Plane", func() { + // given + c, err := client.New(envTest.Config, client.Options{}) + Expect(err).ToNot(HaveOccurred()) - It("should fail to find Service Mesh Control Plane if not present", func() { - // given - dsci.Spec.ServiceMesh.ControlPlane.Name = "test-name" + ns := envtestutil.AppendRandomNameTo(fixtures.TestNamespacePrefix) + nsResource := fixtures.NewNamespace(ns) + Expect(c.Create(context.Background(), nsResource)).To(Succeed()) + defer objectCleaner.DeleteAll(nsResource) - // when - featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - verificationFeatureErr := feature.CreateFeature("no-service-mesh-control-plane-check"). - For(handler). - UsingConfig(envTest.Config). - PreConditions(servicemesh.EnsureServiceMeshInstalled). - Load() + createServiceMeshControlPlane("test-name", ns) + dsci.Spec.ServiceMesh.ControlPlane.Namespace = ns + dsci.Spec.ServiceMesh.ControlPlane.Name = "test-name" - Expect(verificationFeatureErr).ToNot(HaveOccurred()) + // when + featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { + verificationFeatureErr := feature.CreateFeature("service-mesh-control-plane-check"). + For(handler). + UsingConfig(envTest.Config). + PreConditions(servicemesh.EnsureServiceMeshInstalled). + Load() - return nil - }) + Expect(verificationFeatureErr).ToNot(HaveOccurred()) - // then - Expect(featuresHandler.Apply()).To(MatchError(ContainSubstring("failed to find Service Mesh Control Plane"))) + return nil }) + // then + Expect(featuresHandler.Apply()).To(Succeed()) }) - }) - - Context("Control Plane configuration", func() { - - When("setting up auth(z) provider", func() { - var ( - objectCleaner *envtestutil.Cleaner - dsci *dsciv1.DSCInitialization - serviceMeshSpec *infrav1.ServiceMeshSpec - smcpCrdObj *apiextensionsv1.CustomResourceDefinition - namespace = "test-ns" - name = "minimal" - ) + It("should fail to find Service Mesh Control Plane if not present", func() { + // given + dsci.Spec.ServiceMesh.ControlPlane.Name = "test-name" - BeforeEach(func() { - smcpCrdObj = installServiceMeshCRD() - objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, timeout, interval) - dsci = newDSCInitialization(namespace) + // when + featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { + verificationFeatureErr := feature.CreateFeature("no-service-mesh-control-plane-check"). + For(handler). + UsingConfig(envTest.Config). + PreConditions(servicemesh.EnsureServiceMeshInstalled). + Load() - serviceMeshSpec = &dsci.Spec.ServiceMesh - - serviceMeshSpec.ControlPlane.Name = name - serviceMeshSpec.ControlPlane.Namespace = namespace - }) - - AfterEach(func() { - objectCleaner.DeleteAll(smcpCrdObj) - }) - - It("should be able to remove external provider on cleanup", func() { - // given - ns := fixtures.NewNamespace(namespace) - Expect(envTestClient.Create(context.Background(), ns)).To(Succeed()) - defer objectCleaner.DeleteAll(ns) - - serviceMeshSpec.Auth.Namespace = "auth-provider" - - createServiceMeshControlPlane(name, namespace) - - handler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - return feature.CreateFeature("control-plane-with-external-authz-provider"). - For(handler). - Manifests(path.Join(feature.AuthDir, "mesh-authz-ext-provider.patch.tmpl")). - OnDelete(servicemesh.RemoveExtensionProvider). - UsingConfig(envTest.Config). - Load() - }) - - // when - By("verifying extension provider has been added after applying feature", func() { - Expect(handler.Apply()).To(Succeed()) - serviceMeshControlPlane, err := getServiceMeshControlPlane(namespace, name) - Expect(err).ToNot(HaveOccurred()) - - extensionProviders, found, err := unstructured.NestedSlice(serviceMeshControlPlane.Object, "spec", "techPreview", "meshConfig", "extensionProviders") - Expect(err).ToNot(HaveOccurred()) - Expect(found).To(BeTrue()) - - extensionProvider, ok := extensionProviders[0].(map[string]interface{}) - if !ok { - Fail("extension provider has not been added after applying feature") - } - Expect(extensionProvider["name"]).To(Equal("test-ns-auth-provider")) - - envoyExtAuthzGrpc, ok := extensionProvider["envoyExtAuthzGrpc"].(map[string]interface{}) - if !ok { - Fail("extension provider envoyExtAuthzGrpc has not been added after applying feature") - } - Expect(envoyExtAuthzGrpc["service"]).To(Equal("authorino-authorino-authorization.auth-provider.svc.cluster.local")) - }) - - // then - By("verifying that extension provider has been removed", func() { - Expect(handler.Delete()).To(Succeed()) - Eventually(func() []interface{} { - - serviceMeshControlPlane, err := getServiceMeshControlPlane(namespace, name) - Expect(err).ToNot(HaveOccurred()) - - extensionProviders, found, err := unstructured.NestedSlice(serviceMeshControlPlane.Object, "spec", "techPreview", "meshConfig", "extensionProviders") - Expect(err).ToNot(HaveOccurred()) - Expect(found).To(BeTrue()) - return extensionProviders - - }).WithTimeout(timeout).WithPolling(interval).Should(BeEmpty()) - }) + Expect(verificationFeatureErr).ToNot(HaveOccurred()) + return nil }) + // then + Expect(featuresHandler.Apply()).To(MatchError(ContainSubstring("failed to find Service Mesh Control Plane"))) }) }) @@ -255,17 +173,6 @@ var _ = Describe("Service Mesh setup", func() { }) }) -func installServiceMeshCRD() *apiextensionsv1.CustomResourceDefinition { - smcpCrdObj := &apiextensionsv1.CustomResourceDefinition{} - Expect(yaml.Unmarshal([]byte(fixtures.ServiceMeshControlPlaneCRD), smcpCrdObj)).ToNot(HaveOccurred()) - Expect(envTestClient.Create(context.TODO(), smcpCrdObj)).ToNot(HaveOccurred()) - - crdOptions := envtest.CRDInstallOptions{PollInterval: interval, MaxTime: timeout} - Expect(envtest.WaitForCRDs(envTest.Config, []*apiextensionsv1.CustomResourceDefinition{smcpCrdObj}, crdOptions)).To(Succeed()) - - return smcpCrdObj -} - func getGateway(cfg *rest.Config, namespace, name string) (*unstructured.Unstructured, error) { dynamicClient, err := dynamic.NewForConfig(cfg) if err != nil { @@ -334,15 +241,3 @@ func createSMCPInCluster(smcpObj *unstructured.Unstructured, namespace string) e return envTestClient.Status().Update(context.TODO(), update) } - -func getServiceMeshControlPlane(namespace, name string) (*unstructured.Unstructured, error) { - smcpObj := &unstructured.Unstructured{} - smcpObj.SetGroupVersionKind(cluster.ServiceMeshControlPlaneGVK) - - err := envTestClient.Get(context.TODO(), client.ObjectKey{ - Namespace: namespace, - Name: name, - }, smcpObj) - - return smcpObj, err -}