diff --git a/components/kserve/feature_resources.go b/components/kserve/feature_resources.go new file mode 100644 index 00000000000..c15971cc430 --- /dev/null +++ b/components/kserve/feature_resources.go @@ -0,0 +1,31 @@ +package kserve + +import ( + "embed" + "io/fs" + "path" +) + +//go:embed resources +var kserveEmbeddedFS embed.FS + +const baseDir = "resources" + +var Resources = struct { + // ServiceMeshDir is the path to the Service Mesh templates. + ServiceMeshDir string + // InstallDir is the path to the Serving install templates. + InstallDir string + // GatewaysDir is the path to the Serving Istio gateways templates. + GatewaysDir string + // Source the templates to be used + Source fs.FS + // BaseDir is the path to the base of the embedded FS + BaseDir string +}{ + ServiceMeshDir: path.Join(baseDir, "servicemesh"), + InstallDir: path.Join(baseDir, "serving-install"), + GatewaysDir: path.Join(baseDir, "servicemesh", "routing"), + Source: kserveEmbeddedFS, + BaseDir: baseDir, +} diff --git a/pkg/feature/templates/servicemesh/kserve/activator-envoyfilter.tmpl b/components/kserve/resources/servicemesh/activator-envoyfilter.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/kserve/activator-envoyfilter.tmpl rename to components/kserve/resources/servicemesh/activator-envoyfilter.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/kserve/envoy-oauth-temp-fix.tmpl b/components/kserve/resources/servicemesh/envoy-oauth-temp-fix.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/kserve/envoy-oauth-temp-fix.tmpl rename to components/kserve/resources/servicemesh/envoy-oauth-temp-fix.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/kserve/grpc-envoyfilter-temp-fix.tmpl b/components/kserve/resources/servicemesh/grpc-envoyfilter-temp-fix.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/kserve/grpc-envoyfilter-temp-fix.tmpl rename to components/kserve/resources/servicemesh/grpc-envoyfilter-temp-fix.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/kserve/kserve-predictor-authorizationpolicy.tmpl b/components/kserve/resources/servicemesh/kserve-predictor-authorizationpolicy.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/kserve/kserve-predictor-authorizationpolicy.tmpl rename to components/kserve/resources/servicemesh/kserve-predictor-authorizationpolicy.tmpl.yaml diff --git a/pkg/feature/templates/serverless/serving-istio-gateways/istio-ingress-gateway.tmpl b/components/kserve/resources/servicemesh/routing/istio-ingress-gateway.tmpl.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-istio-gateways/istio-ingress-gateway.tmpl rename to components/kserve/resources/servicemesh/routing/istio-ingress-gateway.tmpl.yaml diff --git a/pkg/feature/templates/serverless/serving-istio-gateways/istio-local-gateway.yaml b/components/kserve/resources/servicemesh/routing/istio-local-gateway.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-istio-gateways/istio-local-gateway.yaml rename to components/kserve/resources/servicemesh/routing/istio-local-gateway.yaml diff --git a/pkg/feature/templates/serverless/serving-istio-gateways/local-gateway-svc.tmpl b/components/kserve/resources/servicemesh/routing/local-gateway-svc.tmpl.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-istio-gateways/local-gateway-svc.tmpl rename to components/kserve/resources/servicemesh/routing/local-gateway-svc.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/kserve/z-migrations/kserve-predictor-authorizationpolicy.patch.tmpl b/components/kserve/resources/servicemesh/z-migrations/kserve-predictor-authorizationpolicy.patch.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/kserve/z-migrations/kserve-predictor-authorizationpolicy.patch.tmpl rename to components/kserve/resources/servicemesh/z-migrations/kserve-predictor-authorizationpolicy.patch.tmpl.yaml diff --git a/pkg/feature/templates/serverless/serving-install/knative-serving.tmpl b/components/kserve/resources/serving-install/knative-serving.tmpl.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-install/knative-serving.tmpl rename to components/kserve/resources/serving-install/knative-serving.tmpl.yaml diff --git a/pkg/feature/templates/serverless/serving-install/service-mesh-subscription.tmpl b/components/kserve/resources/serving-install/service-mesh-subscription.tmpl.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-install/service-mesh-subscription.tmpl rename to components/kserve/resources/serving-install/service-mesh-subscription.tmpl.yaml diff --git a/pkg/feature/templates/serverless/serving-net-istio-secret-filtering.patch.tmpl b/components/kserve/resources/serving-net-istio-secret-filtering.patch.tmpl.yaml similarity index 100% rename from pkg/feature/templates/serverless/serving-net-istio-secret-filtering.patch.tmpl rename to components/kserve/resources/serving-net-istio-secret-filtering.patch.tmpl.yaml diff --git a/components/kserve/serverless_setup.go b/components/kserve/serverless_setup.go index 47eac118bbb..1078ebf2097 100644 --- a/components/kserve/serverless_setup.go +++ b/components/kserve/serverless_setup.go @@ -12,8 +12,9 @@ func (k *Kserve) configureServerlessFeatures() feature.FeaturesProvider { return func(handler *feature.FeaturesHandler) error { servingDeploymentErr := feature.CreateFeature("serverless-serving-deployment"). For(handler). + ManifestSource(Resources.Source). Manifests( - path.Join(feature.ServerlessDir, "serving-install"), + path.Join(Resources.InstallDir), ). WithData(PopulateComponentSettings(k)). PreConditions( @@ -32,8 +33,9 @@ func (k *Kserve) configureServerlessFeatures() feature.FeaturesProvider { servingNetIstioSecretFilteringErr := feature.CreateFeature("serverless-net-istio-secret-filtering"). For(handler). + ManifestSource(Resources.Source). Manifests( - path.Join(feature.ServerlessDir, "serving-net-istio-secret-filtering.patch.tmpl"), + path.Join(Resources.BaseDir, "serving-net-istio-secret-filtering.patch.tmpl.yaml"), ). WithData(PopulateComponentSettings(k)). PreConditions(serverless.EnsureServerlessServingDeployed). @@ -54,8 +56,9 @@ func (k *Kserve) configureServerlessFeatures() feature.FeaturesProvider { serverless.ServingIngressDomain, ). WithResources(serverless.ServingCertificateResource). + ManifestSource(Resources.Source). Manifests( - path.Join(feature.ServerlessDir, "serving-istio-gateways"), + path.Join(Resources.GatewaysDir), ). Load() if serverlessGwErr != nil { diff --git a/components/kserve/servicemesh_setup.go b/components/kserve/servicemesh_setup.go index a945b700466..4fbd2ac35db 100644 --- a/components/kserve/servicemesh_setup.go +++ b/components/kserve/servicemesh_setup.go @@ -40,11 +40,12 @@ func (k *Kserve) defineServiceMeshFeatures(cli client.Client) feature.FeaturesPr if authorinoInstalled { kserveExtAuthzErr := feature.CreateFeature("kserve-external-authz"). For(handler). + ManifestSource(Resources.Source). Manifests( - path.Join(feature.KServeDir, "activator-envoyfilter.tmpl"), - path.Join(feature.KServeDir, "envoy-oauth-temp-fix.tmpl"), - path.Join(feature.KServeDir, "kserve-predictor-authorizationpolicy.tmpl"), - path.Join(feature.KServeDir, "z-migrations"), + path.Join(Resources.ServiceMeshDir, "activator-envoyfilter.tmpl.yaml"), + path.Join(Resources.ServiceMeshDir, "envoy-oauth-temp-fix.tmpl.yaml"), + path.Join(Resources.ServiceMeshDir, "kserve-predictor-authorizationpolicy.tmpl.yaml"), + path.Join(Resources.ServiceMeshDir, "z-migrations"), ). WithData(servicemesh.ClusterDetails). Load() @@ -58,8 +59,9 @@ func (k *Kserve) defineServiceMeshFeatures(cli client.Client) feature.FeaturesPr temporaryFixesErr := feature.CreateFeature("kserve-temporary-fixes"). For(handler). + ManifestSource(Resources.Source). Manifests( - path.Join(feature.KServeDir, "grpc-envoyfilter-temp-fix.tmpl"), + path.Join(Resources.ServiceMeshDir, "grpc-envoyfilter-temp-fix.tmpl.yaml"), ). WithData(servicemesh.ClusterDetails). Load() diff --git a/controllers/dscinitialization/feature_resources.go b/controllers/dscinitialization/feature_resources.go new file mode 100644 index 00000000000..7141adcef41 --- /dev/null +++ b/controllers/dscinitialization/feature_resources.go @@ -0,0 +1,31 @@ +package dscinitialization + +import ( + "embed" + "io/fs" + "path" +) + +//go:embed resources +var dsciEmbeddedFS embed.FS + +const baseDir = "resources" + +var Templates = struct { + // ServiceMeshDir is the path to the Service Mesh templates. + ServiceMeshDir string + // InstallDir is the path to the Serving install templates. + AuthorinoDir string + // GatewaysDir is the path to the Serving Istio gateways templates. + MetricsDir string + // Source the templates to be used + Source fs.FS + // BaseDir is the path to the base of the embedded FS + BaseDir string +}{ + ServiceMeshDir: path.Join(baseDir, "servicemesh"), + AuthorinoDir: path.Join(baseDir, "authorino"), + MetricsDir: path.Join(baseDir, "metrics-collection"), + Source: dsciEmbeddedFS, + BaseDir: baseDir, +} diff --git a/pkg/feature/templates/servicemesh/authorino/auth-smm.tmpl b/controllers/dscinitialization/resources/authorino/auth-smm.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/authorino/auth-smm.tmpl rename to controllers/dscinitialization/resources/authorino/auth-smm.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/authorino/base/operator-cluster-wide-no-tls.tmpl b/controllers/dscinitialization/resources/authorino/base/operator-cluster-wide-no-tls.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/authorino/base/operator-cluster-wide-no-tls.tmpl rename to controllers/dscinitialization/resources/authorino/base/operator-cluster-wide-no-tls.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/authorino/deployment.injection.patch.tmpl b/controllers/dscinitialization/resources/authorino/deployment.injection.patch.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/authorino/deployment.injection.patch.tmpl rename to controllers/dscinitialization/resources/authorino/deployment.injection.patch.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/authorino/mesh-authz-ext-provider.patch.tmpl b/controllers/dscinitialization/resources/authorino/mesh-authz-ext-provider.patch.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/authorino/mesh-authz-ext-provider.patch.tmpl rename to controllers/dscinitialization/resources/authorino/mesh-authz-ext-provider.patch.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/metrics-collection/envoy-metrics-collection.tmpl b/controllers/dscinitialization/resources/metrics-collection/envoy-metrics-collection.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/metrics-collection/envoy-metrics-collection.tmpl rename to controllers/dscinitialization/resources/metrics-collection/envoy-metrics-collection.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/metrics-collection/pilot-metrics-collection.tmpl b/controllers/dscinitialization/resources/metrics-collection/pilot-metrics-collection.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/metrics-collection/pilot-metrics-collection.tmpl rename to controllers/dscinitialization/resources/metrics-collection/pilot-metrics-collection.tmpl.yaml diff --git a/pkg/feature/templates/servicemesh/base/create-smcp.tmpl b/controllers/dscinitialization/resources/servicemesh/create-smcp.tmpl.yaml similarity index 100% rename from pkg/feature/templates/servicemesh/base/create-smcp.tmpl rename to controllers/dscinitialization/resources/servicemesh/create-smcp.tmpl.yaml diff --git a/controllers/dscinitialization/servicemesh_setup.go b/controllers/dscinitialization/servicemesh_setup.go index 5b8a9c02975..46f9861ef72 100644 --- a/controllers/dscinitialization/servicemesh_setup.go +++ b/controllers/dscinitialization/servicemesh_setup.go @@ -118,8 +118,9 @@ func (r *DSCInitializationReconciler) serviceMeshCapabilityFeatures(instance *ds serviceMeshSpec := instance.Spec.ServiceMesh smcpCreationErr := feature.CreateFeature("mesh-control-plane-creation"). For(handler). + ManifestSource(Templates.Source). Manifests( - path.Join(feature.ServiceMeshDir, "base", "create-smcp.tmpl"), + path.Join(Templates.ServiceMeshDir), ). PreConditions( servicemesh.EnsureServiceMeshOperatorInstalled, @@ -140,8 +141,9 @@ func (r *DSCInitializationReconciler) serviceMeshCapabilityFeatures(instance *ds PreConditions( servicemesh.EnsureServiceMeshInstalled, ). + ManifestSource(Templates.Source). Manifests( - path.Join(feature.ServiceMeshDir, "metrics-collection"), + path.Join(Templates.MetricsDir), ). Load() if metricsCollectionErr != nil { @@ -167,10 +169,11 @@ func (r *DSCInitializationReconciler) authorizationFeatures(instance *dsciv1.DSC extAuthzErr := feature.CreateFeature("mesh-control-plane-external-authz"). For(handler). + ManifestSource(Templates.Source). Manifests( - path.Join(feature.AuthDir, "auth-smm.tmpl"), - path.Join(feature.AuthDir, "base"), - path.Join(feature.AuthDir, "mesh-authz-ext-provider.patch.tmpl"), + path.Join(Templates.AuthorinoDir, "auth-smm.tmpl.yaml"), + path.Join(Templates.AuthorinoDir, "base"), + path.Join(Templates.AuthorinoDir, "mesh-authz-ext-provider.patch.tmpl.yaml"), ). WithData(servicemesh.ClusterDetails). PreConditions( @@ -189,7 +192,7 @@ func (r *DSCInitializationReconciler) authorizationFeatures(instance *dsciv1.DSC // // To make it part of Service Mesh we have to patch it with injection // enabled instead, otherwise it will not have proxy pod injected. - return f.ApplyManifest(path.Join(feature.AuthDir, "deployment.injection.patch.tmpl")) + return f.ApplyManifest(path.Join(Templates.AuthorinoDir, "deployment.injection.patch.tmpl.yaml")) }, ). OnDelete( diff --git a/pkg/feature/builder.go b/pkg/feature/builder.go index a86a92a9b12..a8eaa9beebf 100644 --- a/pkg/feature/builder.go +++ b/pkg/feature/builder.go @@ -53,7 +53,6 @@ func (u *usingFeaturesHandler) For(featuresHandler *FeaturesHandler) *featureBui fb := &featureBuilder{ name: u.name, featuresHandler: featuresHandler, - fsys: embeddedFiles, targetNS: featuresHandler.DSCInitializationSpec.ApplicationsNamespace, } @@ -85,7 +84,18 @@ func createClient(config *rest.Config) partialBuilder { } } -func (fb *featureBuilder) Manifests(paths ...string) *featureBuilder { +// Used to enforce that Manifests() is called after ManifestSource() in the chain. +type featureBuilderWithManifestSource struct { + *featureBuilder +} + +// ManifestSource sets the root file system (fsys) from which manifest paths are loaded. +func (fb *featureBuilder) ManifestSource(fsys fs.FS) *featureBuilderWithManifestSource { + fb.fsys = fsys + return &featureBuilderWithManifestSource{featureBuilder: fb} +} + +func (fb *featureBuilderWithManifestSource) Manifests(paths ...string) *featureBuilderWithManifestSource { fb.builders = append(fb.builders, func(f *Feature) error { var err error var manifests []Manifest @@ -177,6 +187,7 @@ func (fb *featureBuilder) Load() error { } feature.Spec.TargetNamespace = fb.targetNS + feature.fsys = fb.fsys fb.featuresHandler.features = append(fb.featuresHandler.features, feature) @@ -204,13 +215,6 @@ func (fb *featureBuilder) withDefaultClient() error { return nil } -// ManifestSource sets the root file system (fsys) from which manifest paths are loaded -// If ManifestSource is not called in the builder chain, the default source will be the embeddedFiles. -func (fb *featureBuilder) ManifestSource(fsys fs.FS) *featureBuilder { - fb.fsys = fsys - return fb -} - func (fb *featureBuilder) TargetNamespace(targetNs string) *featureBuilder { fb.targetNS = targetNs diff --git a/pkg/feature/feature.go b/pkg/feature/feature.go index 521868e5eac..0bcd09c8a19 100644 --- a/pkg/feature/feature.go +++ b/pkg/feature/feature.go @@ -3,6 +3,7 @@ package feature import ( "context" "fmt" + "io/fs" "github.com/go-logr/logr" "github.com/hashicorp/go-multierror" @@ -33,6 +34,7 @@ type Feature struct { preconditions []Action postconditions []Action loaders []Action + fsys fs.FS Log logr.Logger } @@ -169,7 +171,7 @@ func (f *Feature) addCleanup(cleanupFuncs ...Action) { } func (f *Feature) ApplyManifest(path string) error { - m, err := loadManifestsFrom(embeddedFiles, path) + m, err := loadManifestsFrom(f.fsys, path) if err != nil { return err } diff --git a/pkg/feature/manifest.go b/pkg/feature/manifest.go index c8a6f8973f0..c579bdec46d 100644 --- a/pkg/feature/manifest.go +++ b/pkg/feature/manifest.go @@ -2,12 +2,10 @@ package feature import ( "bytes" - "embed" "fmt" "html/template" "io" "io/fs" - "path" "path/filepath" "regexp" "strings" @@ -16,17 +14,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) -//go:embed templates -var embeddedFiles embed.FS - -var ( - BaseDir = "templates" - ServiceMeshDir = path.Join(BaseDir, "servicemesh") - ServerlessDir = path.Join(BaseDir, "serverless") - AuthDir = path.Join(ServiceMeshDir, "authorino") - KServeDir = path.Join(ServiceMeshDir, "kserve") -) - type Manifest interface { // Process allows any arbitrary struct to be passed and used while processing the content of the manifest. Process(data any) ([]*unstructured.Unstructured, error) @@ -145,13 +132,13 @@ func CreateTemplateManifestFrom(fsys fs.FS, path string) *templateManifest { //n return &templateManifest{ name: basePath, path: path, - patch: strings.Contains(basePath, ".patch"), + patch: strings.Contains(basePath, ".patch."), fsys: fsys, } } func isTemplateManifest(path string) bool { - return strings.Contains(path, ".tmpl") + return strings.Contains(filepath.Base(path), ".tmpl.") } func convertToUnstructuredSlice(resources string) ([]*unstructured.Unstructured, error) { diff --git a/tests/integration/features/fixtures/const.go b/tests/integration/features/fixtures/const.go index 1a5367d4212..92c03c11e9c 100644 --- a/tests/integration/features/fixtures/const.go +++ b/tests/integration/features/fixtures/const.go @@ -7,4 +7,5 @@ const ( Timeout = 5 * time.Second // Interval is the default interval for polling for a condition to be met. Interval = 250 * time.Millisecond + BaseDir = "templates" ) diff --git a/tests/integration/features/fixtures/templates/local-gateway-svc.tmpl.yaml b/tests/integration/features/fixtures/templates/local-gateway-svc.tmpl.yaml new file mode 100644 index 00000000000..16f9fc5d8c9 --- /dev/null +++ b/tests/integration/features/fixtures/templates/local-gateway-svc.tmpl.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + experimental.istio.io/disable-gateway-port-translation: "true" + name: knative-local-gateway + namespace: {{ .ControlPlane.Namespace }} +spec: + ports: + - name: http2 + port: 80 + protocol: TCP + targetPort: 8081 + selector: + knative: ingressgateway + type: ClusterIP diff --git a/tests/integration/features/fixtures/templates/mesh-authz-ext-provider.patch.tmpl.yaml b/tests/integration/features/fixtures/templates/mesh-authz-ext-provider.patch.tmpl.yaml new file mode 100644 index 00000000000..1a91092c7c2 --- /dev/null +++ b/tests/integration/features/fixtures/templates/mesh-authz-ext-provider.patch.tmpl.yaml @@ -0,0 +1,13 @@ +apiVersion: maistra.io/v2 +kind: ServiceMeshControlPlane +metadata: + name: {{ .ControlPlane.Name }} + namespace: {{ .ControlPlane.Namespace }} +spec: + techPreview: + meshConfig: + extensionProviders: + - name: {{ .AppNamespace }}-auth-provider + envoyExtAuthzGrpc: + service: {{ .AuthProviderName }}-authorino-authorization.{{ .Auth.Namespace }}.svc.cluster.local + port: 50051 diff --git a/tests/integration/features/manifests_int_test.go b/tests/integration/features/manifests_int_test.go index d08f6992fd6..e2882ccdb3d 100644 --- a/tests/integration/features/manifests_int_test.go +++ b/tests/integration/features/manifests_int_test.go @@ -40,43 +40,17 @@ var _ = Describe("Manifest sources", func() { objectCleaner.DeleteAll(namespace) }) - It("should be able to process an embedded template from the default location", func() { + It("should be able to process an embedded YAML file", func() { // given featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - createServiceErr := feature.CreateFeature("create-local-gw-svc"). - For(handler). - UsingConfig(envTest.Config). - Manifests(path.Join(feature.ServerlessDir, "serving-istio-gateways", "local-gateway-svc.tmpl")). - Load() - - Expect(createServiceErr).ToNot(HaveOccurred()) - - return nil - }) - - // when - Expect(featuresHandler.Apply()).To(Succeed()) - - // then - service, err := fixtures.GetService(envTestClient, namespace.Name, "knative-local-gateway") - Expect(err).ToNot(HaveOccurred()) - Expect(service.Name).To(Equal("knative-local-gateway")) - }) - - It("should be able to process an embedded YAML file from the default location", func() { - // given - knativeNs, nsErr := cluster.CreateNamespace(envTestClient, "knative-serving") - Expect(nsErr).ToNot(HaveOccurred()) - defer objectCleaner.DeleteAll(knativeNs) - - featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - createGatewayErr := feature.CreateFeature("create-local-gateway"). + createNamespaceErr := feature.CreateFeature("create-namespace"). For(handler). UsingConfig(envTest.Config). - Manifests(path.Join(feature.ServerlessDir, "serving-istio-gateways", "istio-local-gateway.yaml")). + ManifestSource(fixtures.TestEmbeddedFiles). + Manifests(path.Join(fixtures.BaseDir, "namespace.yaml")). Load() - Expect(createGatewayErr).ToNot(HaveOccurred()) + Expect(createNamespaceErr).ToNot(HaveOccurred()) return nil }) @@ -85,22 +59,23 @@ var _ = Describe("Manifest sources", func() { Expect(featuresHandler.Apply()).To(Succeed()) // then - gateway, err := getGateway(envTest.Config, "knative-serving", "knative-local-gateway") + embeddedNs, err := fixtures.GetNamespace(envTestClient, "embedded-test-ns") + defer objectCleaner.DeleteAll(embeddedNs) Expect(err).ToNot(HaveOccurred()) - Expect(gateway).ToNot(BeNil()) + Expect(embeddedNs.Name).To(Equal("embedded-test-ns")) }) - It("should be able to process an embedded file from a non default location", func() { + It("should be able to process an embedded template file", func() { // given featuresHandler := feature.ClusterFeaturesHandler(dsci, func(handler *feature.FeaturesHandler) error { - createNamespaceErr := feature.CreateFeature("create-namespace"). + createServiceErr := feature.CreateFeature("create-local-gw-svc"). For(handler). UsingConfig(envTest.Config). ManifestSource(fixtures.TestEmbeddedFiles). - Manifests(path.Join(feature.BaseDir, "namespace.yaml")). + Manifests(path.Join(fixtures.BaseDir, "local-gateway-svc.tmpl.yaml")). Load() - Expect(createNamespaceErr).ToNot(HaveOccurred()) + Expect(createServiceErr).ToNot(HaveOccurred()) return nil }) @@ -109,10 +84,9 @@ var _ = Describe("Manifest sources", func() { Expect(featuresHandler.Apply()).To(Succeed()) // then - embeddedNs, err := fixtures.GetNamespace(envTestClient, "embedded-test-ns") - defer objectCleaner.DeleteAll(embeddedNs) + service, err := fixtures.GetService(envTestClient, namespace.Name, "knative-local-gateway") Expect(err).ToNot(HaveOccurred()) - Expect(embeddedNs.Name).To(Equal("embedded-test-ns")) + Expect(service.Name).To(Equal("knative-local-gateway")) }) const nsYAML = `apiVersion: v1 diff --git a/tests/integration/features/servicemesh_feature_test.go b/tests/integration/features/servicemesh_feature_test.go index 85de0213075..725401bc93d 100644 --- a/tests/integration/features/servicemesh_feature_test.go +++ b/tests/integration/features/servicemesh_feature_test.go @@ -6,12 +6,8 @@ import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/yaml" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -202,7 +198,8 @@ var _ = Describe("Service Mesh setup", func() { 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")). + ManifestSource(fixtures.TestEmbeddedFiles). + Manifests(path.Join("templates", "mesh-authz-ext-provider.patch.tmpl.yaml")). OnDelete( servicemesh.RemoveExtensionProvider, ). @@ -273,24 +270,6 @@ func installServiceMeshCRD() *apiextensionsv1.CustomResourceDefinition { return smcpCrdObj } -func getGateway(cfg *rest.Config, namespace, name string) (*unstructured.Unstructured, error) { - dynamicClient, err := dynamic.NewForConfig(cfg) - if err != nil { - return nil, err - } - gwGvr := schema.GroupVersionResource{ - Group: "networking.istio.io", - Version: "v1beta1", - Resource: "gateways", - } - - gateway, err := dynamicClient.Resource(gwGvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{}) - if err != nil { - return nil, err - } - return gateway, nil -} - func createServiceMeshControlPlane(name, namespace string) { serviceMeshControlPlane := &unstructured.Unstructured{ Object: map[string]interface{}{