From a9d0dceb37d6bf18ce20f60172ade050e25a913e Mon Sep 17 00:00:00 2001 From: Per Goncalves da Silva <pegoncal@redhat.com> Date: Mon, 10 Jun 2024 11:23:02 +0200 Subject: [PATCH 1/4] update test bundles and catalog to a declarative config Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> --- .../busybox-dependency/1.0.0/dockerfile | 0 .../1.0.0/manifests/csv.yaml | 0 .../1.0.0/manifests/foo.crd.yaml | 0 .../1.0.0/metadata/annotations.yaml | 0 .../busybox-dependency/2.0.0/dockerfile | 0 .../2.0.0/manifests/csv.yaml | 0 .../2.0.0/manifests/foo.crd.yaml | 0 .../2.0.0/metadata/annotations.yaml | 0 .../{ => bundles}/busybox/1.0.0/dockerfile | 0 .../busybox/1.0.0/manifests/csv.yaml | 0 .../busybox/1.0.0/metadata/annotations.yaml | 0 .../{ => bundles}/busybox/2.0.0/dockerfile | 0 .../busybox/2.0.0/manifests/csv.yaml | 0 .../busybox/2.0.0/metadata/annotations.yaml | 0 test/images/busybox-index/index.Dockerfile | 16 ++ .../indexv1/configs/.indexignore | 2 + .../indexv1/configs/catalog.json | 178 +++++++++++++++++ .../indexv2/configs/.indexignore | 2 + .../indexv2/configs/catalog.json | 186 ++++++++++++++++++ 19 files changed, 384 insertions(+) rename test/images/busybox-index/{ => bundles}/busybox-dependency/1.0.0/dockerfile (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/1.0.0/manifests/csv.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/1.0.0/manifests/foo.crd.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/1.0.0/metadata/annotations.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/2.0.0/dockerfile (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/2.0.0/manifests/csv.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/2.0.0/manifests/foo.crd.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox-dependency/2.0.0/metadata/annotations.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox/1.0.0/dockerfile (100%) rename test/images/busybox-index/{ => bundles}/busybox/1.0.0/manifests/csv.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox/1.0.0/metadata/annotations.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox/2.0.0/dockerfile (100%) rename test/images/busybox-index/{ => bundles}/busybox/2.0.0/manifests/csv.yaml (100%) rename test/images/busybox-index/{ => bundles}/busybox/2.0.0/metadata/annotations.yaml (100%) create mode 100644 test/images/busybox-index/index.Dockerfile create mode 100644 test/images/busybox-index/indexv1/configs/.indexignore create mode 100644 test/images/busybox-index/indexv1/configs/catalog.json create mode 100644 test/images/busybox-index/indexv2/configs/.indexignore create mode 100644 test/images/busybox-index/indexv2/configs/catalog.json diff --git a/test/images/busybox-index/busybox-dependency/1.0.0/dockerfile b/test/images/busybox-index/bundles/busybox-dependency/1.0.0/dockerfile similarity index 100% rename from test/images/busybox-index/busybox-dependency/1.0.0/dockerfile rename to test/images/busybox-index/bundles/busybox-dependency/1.0.0/dockerfile diff --git a/test/images/busybox-index/busybox-dependency/1.0.0/manifests/csv.yaml b/test/images/busybox-index/bundles/busybox-dependency/1.0.0/manifests/csv.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/1.0.0/manifests/csv.yaml rename to test/images/busybox-index/bundles/busybox-dependency/1.0.0/manifests/csv.yaml diff --git a/test/images/busybox-index/busybox-dependency/1.0.0/manifests/foo.crd.yaml b/test/images/busybox-index/bundles/busybox-dependency/1.0.0/manifests/foo.crd.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/1.0.0/manifests/foo.crd.yaml rename to test/images/busybox-index/bundles/busybox-dependency/1.0.0/manifests/foo.crd.yaml diff --git a/test/images/busybox-index/busybox-dependency/1.0.0/metadata/annotations.yaml b/test/images/busybox-index/bundles/busybox-dependency/1.0.0/metadata/annotations.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/1.0.0/metadata/annotations.yaml rename to test/images/busybox-index/bundles/busybox-dependency/1.0.0/metadata/annotations.yaml diff --git a/test/images/busybox-index/busybox-dependency/2.0.0/dockerfile b/test/images/busybox-index/bundles/busybox-dependency/2.0.0/dockerfile similarity index 100% rename from test/images/busybox-index/busybox-dependency/2.0.0/dockerfile rename to test/images/busybox-index/bundles/busybox-dependency/2.0.0/dockerfile diff --git a/test/images/busybox-index/busybox-dependency/2.0.0/manifests/csv.yaml b/test/images/busybox-index/bundles/busybox-dependency/2.0.0/manifests/csv.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/2.0.0/manifests/csv.yaml rename to test/images/busybox-index/bundles/busybox-dependency/2.0.0/manifests/csv.yaml diff --git a/test/images/busybox-index/busybox-dependency/2.0.0/manifests/foo.crd.yaml b/test/images/busybox-index/bundles/busybox-dependency/2.0.0/manifests/foo.crd.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/2.0.0/manifests/foo.crd.yaml rename to test/images/busybox-index/bundles/busybox-dependency/2.0.0/manifests/foo.crd.yaml diff --git a/test/images/busybox-index/busybox-dependency/2.0.0/metadata/annotations.yaml b/test/images/busybox-index/bundles/busybox-dependency/2.0.0/metadata/annotations.yaml similarity index 100% rename from test/images/busybox-index/busybox-dependency/2.0.0/metadata/annotations.yaml rename to test/images/busybox-index/bundles/busybox-dependency/2.0.0/metadata/annotations.yaml diff --git a/test/images/busybox-index/busybox/1.0.0/dockerfile b/test/images/busybox-index/bundles/busybox/1.0.0/dockerfile similarity index 100% rename from test/images/busybox-index/busybox/1.0.0/dockerfile rename to test/images/busybox-index/bundles/busybox/1.0.0/dockerfile diff --git a/test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml b/test/images/busybox-index/bundles/busybox/1.0.0/manifests/csv.yaml similarity index 100% rename from test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml rename to test/images/busybox-index/bundles/busybox/1.0.0/manifests/csv.yaml diff --git a/test/images/busybox-index/busybox/1.0.0/metadata/annotations.yaml b/test/images/busybox-index/bundles/busybox/1.0.0/metadata/annotations.yaml similarity index 100% rename from test/images/busybox-index/busybox/1.0.0/metadata/annotations.yaml rename to test/images/busybox-index/bundles/busybox/1.0.0/metadata/annotations.yaml diff --git a/test/images/busybox-index/busybox/2.0.0/dockerfile b/test/images/busybox-index/bundles/busybox/2.0.0/dockerfile similarity index 100% rename from test/images/busybox-index/busybox/2.0.0/dockerfile rename to test/images/busybox-index/bundles/busybox/2.0.0/dockerfile diff --git a/test/images/busybox-index/busybox/2.0.0/manifests/csv.yaml b/test/images/busybox-index/bundles/busybox/2.0.0/manifests/csv.yaml similarity index 100% rename from test/images/busybox-index/busybox/2.0.0/manifests/csv.yaml rename to test/images/busybox-index/bundles/busybox/2.0.0/manifests/csv.yaml diff --git a/test/images/busybox-index/busybox/2.0.0/metadata/annotations.yaml b/test/images/busybox-index/bundles/busybox/2.0.0/metadata/annotations.yaml similarity index 100% rename from test/images/busybox-index/busybox/2.0.0/metadata/annotations.yaml rename to test/images/busybox-index/bundles/busybox/2.0.0/metadata/annotations.yaml diff --git a/test/images/busybox-index/index.Dockerfile b/test/images/busybox-index/index.Dockerfile new file mode 100644 index 0000000000..08c6e009d2 --- /dev/null +++ b/test/images/busybox-index/index.Dockerfile @@ -0,0 +1,16 @@ +# The base image is expected to contain +# /bin/opm (with a serve subcommand) and /bin/grpc_health_probe +ARG OPM_VERSION=latest +FROM quay.io/operator-framework/opm:${OPM_VERSION} + +# Set DC-specific label for the location of the DC root directory +# in the image +LABEL operators.operatorframework.io.index.configs.v1=/configs + +# Copy declarative config root into image at /configs and pre-populate serve cache +COPY /configs /configs +RUN ["/bin/opm", "serve", "/configs", "--cache-dir=/tmp/cache", "--cache-only"] + +# Configure the entrypoint and command +ENTRYPOINT ["/bin/opm"] +CMD ["serve", "/configs", "--cache-dir=/tmp/cache"] diff --git a/test/images/busybox-index/indexv1/configs/.indexignore b/test/images/busybox-index/indexv1/configs/.indexignore new file mode 100644 index 0000000000..620c429a51 --- /dev/null +++ b/test/images/busybox-index/indexv1/configs/.indexignore @@ -0,0 +1,2 @@ +/expected_all.json +..* \ No newline at end of file diff --git a/test/images/busybox-index/indexv1/configs/catalog.json b/test/images/busybox-index/indexv1/configs/catalog.json new file mode 100644 index 0000000000..4915a26952 --- /dev/null +++ b/test/images/busybox-index/indexv1/configs/catalog.json @@ -0,0 +1,178 @@ +{ + "schema": "olm.package", + "name": "busybox", + "defaultChannel": "alpha" +} +{ + "schema": "olm.channel", + "name": "alpha", + "package": "busybox", + "entries": [ + { + "name": "busybox.v1.0.0" + } + ] +} +{ + "schema": "olm.bundle", + "name": "busybox.v1.0.0", + "package": "busybox", + "image": "quay.io/olmtest/busybox-bundle:1.0.0", + "properties": [ + { + "type": "olm.gvk.required", + "value": { + "group": "olm.test.io", + "kind": "Foo", + "version": "v1" + } + }, + { + "type": "olm.package", + "value": { + "packageName": "busybox", + "version": "1.0.0" + } + }, + { + "type": "olm.csv.metadata", + "value": { + "apiServiceDefinitions": {}, + "crdDescriptions": { + "required": [ + { + "name": "foos.olm.test.io", + "version": "v1", + "kind": "Foo", + "displayName": "Foo", + "description": "Foo resources for testing dependencies" + } + ] + }, + "description": "A busybox CSV.\n", + "displayName": "busybox", + "installModes": [ + { + "type": "OwnNamespace", + "supported": true + }, + { + "type": "SingleNamespace", + "supported": true + }, + { + "type": "MultiNamespace", + "supported": true + }, + { + "type": "AllNamespaces", + "supported": true + } + ], + "maturity": "alpha", + "provider": { + "name": "Red Hat" + } + } + } + ], + "relatedImages": [ + { + "name": "", + "image": "busybox" + }, + { + "name": "", + "image": "quay.io/olmtest/busybox-bundle:1.0.0" + } + ] +} +{ + "schema": "olm.package", + "name": "busybox-dependency", + "defaultChannel": "alpha" +} +{ + "schema": "olm.channel", + "name": "alpha", + "package": "busybox-dependency", + "entries": [ + { + "name": "busybox-dependency.v1.0.0" + } + ] +} +{ + "schema": "olm.bundle", + "name": "busybox-dependency.v1.0.0", + "package": "busybox-dependency", + "image": "quay.io/olmtest/busybox-dependency-bundle:1.0.0", + "properties": [ + { + "type": "olm.gvk", + "value": { + "group": "olm.test.io", + "kind": "Foo", + "version": "v1" + } + }, + { + "type": "olm.package", + "value": { + "packageName": "busybox-dependency", + "version": "1.0.0" + } + }, + { + "type": "olm.csv.metadata", + "value": { + "apiServiceDefinitions": {}, + "crdDescriptions": { + "owned": [ + { + "name": "foos.olm.test.io", + "version": "v1", + "kind": "Foo", + "displayName": "Foo", + "description": "Foo resources for testing dependencies" + } + ] + }, + "description": "A busybox-dependency CSV.\n", + "displayName": "busybox-dependency", + "installModes": [ + { + "type": "OwnNamespace", + "supported": true + }, + { + "type": "SingleNamespace", + "supported": true + }, + { + "type": "MultiNamespace", + "supported": true + }, + { + "type": "AllNamespaces", + "supported": true + } + ], + "maturity": "alpha", + "provider": { + "name": "Red Hat" + } + } + } + ], + "relatedImages": [ + { + "name": "", + "image": "busybox" + }, + { + "name": "", + "image": "quay.io/olmtest/busybox-dependency-bundle:1.0.0" + } + ] +} diff --git a/test/images/busybox-index/indexv2/configs/.indexignore b/test/images/busybox-index/indexv2/configs/.indexignore new file mode 100644 index 0000000000..620c429a51 --- /dev/null +++ b/test/images/busybox-index/indexv2/configs/.indexignore @@ -0,0 +1,2 @@ +/expected_all.json +..* \ No newline at end of file diff --git a/test/images/busybox-index/indexv2/configs/catalog.json b/test/images/busybox-index/indexv2/configs/catalog.json new file mode 100644 index 0000000000..35331655e9 --- /dev/null +++ b/test/images/busybox-index/indexv2/configs/catalog.json @@ -0,0 +1,186 @@ +{ + "schema": "olm.package", + "name": "busybox", + "defaultChannel": "alpha" +} +{ + "schema": "olm.channel", + "name": "alpha", + "package": "busybox", + "entries": [ + { + "name": "busybox.v2.0.0", + "skipRange": ">=0.0.0 <2.0.0" + } + ] +} +{ + "schema": "olm.bundle", + "name": "busybox.v2.0.0", + "package": "busybox", + "image": "quay.io/olmtest/busybox-bundle:2.0.0", + "properties": [ + { + "type": "olm.gvk.required", + "value": { + "group": "olm.test.io", + "kind": "Foo", + "version": "v1" + } + }, + { + "type": "olm.package", + "value": { + "packageName": "busybox", + "version": "2.0.0" + } + }, + { + "type": "olm.csv.metadata", + "value": { + "annotations": { + "olm.skipRange": ">=0.0.0 <2.0.0" + }, + "apiServiceDefinitions": {}, + "crdDescriptions": { + "required": [ + { + "name": "foos.olm.test.io", + "version": "v1", + "kind": "Foo", + "displayName": "Foo", + "description": "Foo resources for testing dependencies" + } + ] + }, + "description": "A busybox CSV.\n", + "displayName": "busybox", + "installModes": [ + { + "type": "OwnNamespace", + "supported": true + }, + { + "type": "SingleNamespace", + "supported": true + }, + { + "type": "MultiNamespace", + "supported": true + }, + { + "type": "AllNamespaces", + "supported": true + } + ], + "maturity": "alpha", + "provider": { + "name": "Red Hat" + } + } + } + ], + "relatedImages": [ + { + "name": "", + "image": "busybox" + }, + { + "name": "", + "image": "quay.io/olmtest/busybox-bundle:2.0.0" + } + ] +} +{ + "schema": "olm.package", + "name": "busybox-dependency", + "defaultChannel": "alpha" +} +{ + "schema": "olm.channel", + "name": "alpha", + "package": "busybox-dependency", + "entries": [ + { + "name": "busybox-dependency.v2.0.0", + "skipRange": ">=0.0.0 <2.0.0" + } + ] +} +{ + "schema": "olm.bundle", + "name": "busybox-dependency.v2.0.0", + "package": "busybox-dependency", + "image": "quay.io/olmtest/busybox-dependency-bundle:2.0.0", + "properties": [ + { + "type": "olm.gvk", + "value": { + "group": "olm.test.io", + "kind": "Foo", + "version": "v1" + } + }, + { + "type": "olm.package", + "value": { + "packageName": "busybox-dependency", + "version": "2.0.0" + } + }, + { + "type": "olm.csv.metadata", + "value": { + "annotations": { + "olm.skipRange": ">=0.0.0 <2.0.0" + }, + "apiServiceDefinitions": {}, + "crdDescriptions": { + "owned": [ + { + "name": "foos.olm.test.io", + "version": "v1", + "kind": "Foo", + "displayName": "Foo", + "description": "Foo resources for testing dependencies" + } + ] + }, + "description": "A busybox-dependency CSV.\n", + "displayName": "busybox-dependency", + "installModes": [ + { + "type": "OwnNamespace", + "supported": true + }, + { + "type": "SingleNamespace", + "supported": true + }, + { + "type": "MultiNamespace", + "supported": true + }, + { + "type": "AllNamespaces", + "supported": true + } + ], + "maturity": "alpha", + "provider": { + "name": "Red Hat" + } + } + } + ], + "relatedImages": [ + { + "name": "", + "image": "busybox" + }, + { + "name": "", + "image": "quay.io/olmtest/busybox-dependency-bundle:2.0.0" + } + ] +} From 73f61f9bdc8ac11765553ab6c8ae5982a7d9ac68 Mon Sep 17 00:00:00 2001 From: Per Goncalves da Silva <pegoncal@redhat.com> Date: Mon, 10 Jun 2024 13:04:28 +0200 Subject: [PATCH 2/4] update e2e test to take opm version as a parameter Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> --- test/e2e/catalog_e2e_test.go | 11 ++++++----- test/e2e/e2e_test.go | 24 ++++++++++++------------ test/e2e/util.go | 4 ++-- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/test/e2e/catalog_e2e_test.go b/test/e2e/catalog_e2e_test.go index 7fbb968ed9..fd39a5912b 100644 --- a/test/e2e/catalog_e2e_test.go +++ b/test/e2e/catalog_e2e_test.go @@ -49,6 +49,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { c operatorclient.ClientInterface crc versioned.Interface packageserverClient *packageserverclientset.Clientset + testCatalogImage string ) BeforeEach(func() { @@ -67,6 +68,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { c = ctx.Ctx().KubeClient() crc = ctx.Ctx().OperatorClient() packageserverClient = packageserverclientset.NewForConfigOrDie(ctx.Ctx().RESTConfig()) + testCatalogImage = fmt.Sprintf("%s/test-catalog:e2e", testClusterRegistry) }) AfterEach(func() { @@ -704,7 +706,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { }, Spec: v1alpha1.CatalogSourceSpec{ SourceType: v1alpha1.SourceTypeGrpc, - Image: communityOperatorsImage, + Image: testCatalogImage, GrpcPodConfig: &v1alpha1.GrpcPodConfig{ SecurityContextConfig: v1alpha1.Restricted, }, @@ -764,7 +766,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { }, Spec: v1alpha1.CatalogSourceSpec{ SourceType: v1alpha1.SourceTypeGrpc, - Image: communityOperatorsImage, + Image: testCatalogImage, GrpcPodConfig: &v1alpha1.GrpcPodConfig{ SecurityContextConfig: v1alpha1.Restricted, ExtractContent: &v1alpha1.ExtractContentConfig{ @@ -1075,7 +1077,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { }, Spec: v1alpha1.CatalogSourceSpec{ SourceType: v1alpha1.SourceTypeGrpc, - Image: catSrcImage + ":1.0.0-with-ListBundles-method", + Image: fmt.Sprintf("%s:1.0.0-with-ListBundles-method", catSrcImage), GrpcPodConfig: &v1alpha1.GrpcPodConfig{ SecurityContextConfig: v1alpha1.Restricted, }, @@ -1126,8 +1128,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() { if err != nil { return err } - existingSource.Spec.Image = catSrcImage + ":2.0.0-with-ListBundles-method" - + existingSource.Spec.Image = fmt.Sprintf("%s:2.0.0-with-ListBundles-method", catSrcImage) source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.Background(), existingSource, metav1.UpdateOptions{}) return err }).Should(Succeed()) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 7deb176552..f8e89ca5ef 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -38,12 +38,6 @@ var ( catalogNamespace = flag.String( "catalogNamespace", "", "namespace where the global catalog content is stored") - communityOperators = flag.String( - "communityOperators", - "quay.io/operatorhubio/catalog:latest", - "reference to upstream-community-operators image", - ) - dummyImage = flag.String( "dummyImage", "bitnami/nginx:latest", @@ -62,6 +56,12 @@ var ( "configures where to find the testdata directory", ) + clusterRegistry = flag.String( + "cluster-registry", + "localhost:5001", + "set cluster registry url (default: localhost:5001)", + ) + kubeconfigRootDir = flag.String( "kubeconfig-root", "", @@ -71,11 +71,11 @@ var ( "Note that this flag will override the kubeconfig flag.", ) - testdataDir = "" - testNamespace = "" - operatorNamespace = "" - communityOperatorsImage = "" - globalCatalogNamespace = "" + testdataDir = "" + testNamespace = "" + operatorNamespace = "" + globalCatalogNamespace = "" + testClusterRegistry = "" ) func TestEndToEnd(t *testing.T) { @@ -104,9 +104,9 @@ var _ = BeforeSuite(func() { testNamespace = *namespace operatorNamespace = *olmNamespace - communityOperatorsImage = *communityOperators globalCatalogNamespace = *catalogNamespace testdataDir = *testdataPath + testClusterRegistry = *clusterRegistry deprovision = ctx.MustProvision(ctx.Ctx()) ctx.MustInstall(ctx.Ctx()) diff --git a/test/e2e/util.go b/test/e2e/util.go index 1241113bec..33401e170c 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -359,12 +359,12 @@ func catalogSourceRegistryPodSynced() func(catalog *operatorsv1alpha1.CatalogSou state = connState.LastObservedState } if state != lastState { - fmt.Printf("waiting %s for catalog pod %s/%s to be available (for sync) - %s\n", time.Since(lastTime), catalog.GetNamespace(), catalog.GetName(), state) + ctx.Ctx().Logf("waiting %s for catalog pod %s/%s to be available (for sync) - %s\n", time.Since(lastTime), catalog.GetNamespace(), catalog.GetName(), state) lastState = state lastTime = time.Now() } if registry != nil && connState != nil && !connState.LastConnectTime.IsZero() && connState.LastObservedState == "READY" { - fmt.Printf("probing catalog %s pod with address %s\n", catalog.GetName(), registry.Address()) + ctx.Ctx().Logf("probing catalog %s pod with address %s\n", catalog.GetName(), registry.Address()) return registryPodHealthy(registry.Address()) } return false From 08484899f3c9417a8efb4ab4aa720a1dacc5a226 Mon Sep 17 00:00:00 2001 From: Per Goncalves da Silva <pegoncal@redhat.com> Date: Thu, 20 Jun 2024 10:38:47 +0200 Subject: [PATCH 3/4] setup kind with local registry Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> --- Makefile | 21 +++++++--- scripts/build_test_images.sh | 19 --------- scripts/e2e_test_fixtures.sh | 30 ++++++++++++++ scripts/kind_with_registry.sh | 77 +++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 25 deletions(-) delete mode 100755 scripts/build_test_images.sh create mode 100755 scripts/e2e_test_fixtures.sh create mode 100755 scripts/kind_with_registry.sh diff --git a/Makefile b/Makefile index 8e6e295892..fbb19078be 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ export CONFIGMAP_SERVER_IMAGE ?= quay.io/operator-framework/configmap-operator-r PKG := github.com/operator-framework/operator-lifecycle-manager IMAGE_REPO ?= quay.io/operator-framework/olm -IMAGE_TAG ?= "dev" +IMAGE_TAG ?= "local" # Go build settings # @@ -102,8 +102,8 @@ KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use -p path $(KUBE_MINOR).x) # Kind node image tags are in the format x.y.z we pin to version x.y.0 because patch releases and node images # are not guaranteed to be available when a new version of the kube apis is released -KIND_CLUSTER_IMAGE := kindest/node:v$(KUBE_MINOR).0 -KIND_CLUSTER_NAME ?= kind-olmv0 +export KIND_CLUSTER_IMAGE := kindest/node:v$(KUBE_MINOR).0 +export KIND_CLUSTER_NAME ?= kind-olmv0 # Targets # # Disable -j flag for make @@ -145,6 +145,10 @@ image: export GOOS = linux image: clean build #HELP Build image image for linux on host architecture docker build -t $(IMAGE_REPO):$(IMAGE_TAG) -f Dockerfile bin +.PHONE: build-e2e-fixture-images +build-e2e-fixture-images: #HELP Build images for e2e testing + ./scripts/e2e_test_fixtures.sh + .PHONY: e2e-build # the e2e and experimental_metrics tags are required to get e2e tests to pass # search the code for go:build e2e or go:build experimental_metrics to see where these tags are used @@ -207,13 +211,18 @@ kind-clean: $(KIND) #HELP Delete kind cluster $KIND_CLUSTER_NAME (default: kind- .PHONY: kind-create kind-create: kind-clean #HELP Create a new kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) - $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) $(KIND_CREATE_OPTS) + ./scripts/kind_with_registry.sh $(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME) +.PHONY: load-test-images +export REGISTRY ?= localhost:5001 +load-test-images: #HELP Load the OLM images into the kind cluster's registry + ./scripts/e2e_test_fixtures.sh --push-to="localhost:5001" + .PHONY: deploy -OLM_IMAGE := quay.io/operator-framework/olm:local +OLM_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG) deploy: $(KIND) $(HELM) #HELP Deploy OLM to kind cluster $KIND_CLUSTER_NAME (default: kind-olmv0) using $OLM_IMAGE (default: quay.io/operator-framework/olm:local) - $(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME); \ + $(KIND) load docker-image $(OLM_IMAGE) --name $(KIND_CLUSTER_NAME) $(HELM) upgrade --install olm deploy/chart \ --set debug=true \ --set olm.image.ref=$(OLM_IMAGE) \ diff --git a/scripts/build_test_images.sh b/scripts/build_test_images.sh deleted file mode 100755 index 32f1fcaa6e..0000000000 --- a/scripts/build_test_images.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -# Busybox Operator Index Image -docker build -t quay.io/olmtest/busybox-bundle:1.0.0 ./test/images/busybox-index/busybox/1.0.0 -docker build -t quay.io/olmtest/busybox-bundle:2.0.0 ./test/images/busybox-index/busybox/2.0.0 - -docker build -t quay.io/olmtest/busybox-dependency-bundle:1.0.0 ./test/images/busybox-index/busybox-dependency/1.0.0 -docker build -t quay.io/olmtest/busybox-dependency-bundle:2.0.0 ./test/images/busybox-index/busybox-dependency/2.0.0 - -docker push quay.io/olmtest/busybox-bundle:1.0.0 -docker push quay.io/olmtest/busybox-bundle:2.0.0 -docker push quay.io/olmtest/busybox-dependency-bundle:1.0.0 -docker push quay.io/olmtest/busybox-dependency-bundle:2.0.0 - -opm index add --bundles quay.io/olmtest/busybox-dependency-bundle:1.0.0,quay.io/olmtest/busybox-bundle:1.0.0 --tag quay.io/olmtest/busybox-dependencies-index:1.0.0-with-ListBundles-method -c docker -docker push quay.io/olmtest/busybox-dependencies-index:1.0.0-with-ListBundles-method - -opm index add --bundles quay.io/olmtest/busybox-dependency-bundle:2.0.0,quay.io/olmtest/busybox-bundle:2.0.0 --tag quay.io/olmtest/busybox-dependencies-index:2.0.0-with-ListBundles-method --from-index quay.io/olmtest/busybox-dependencies-index:1.0.0-with-ListBundles-method -c docker -docker push quay.io/olmtest/busybox-dependencies-index:2.0.0-with-ListBundles-method diff --git a/scripts/e2e_test_fixtures.sh b/scripts/e2e_test_fixtures.sh new file mode 100755 index 0000000000..6d8c39381a --- /dev/null +++ b/scripts/e2e_test_fixtures.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +KIND=${KIND:-kind} +CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-docker} + +# Default values +OPERATOR_REGISTRY_VERSION="${OPERATOR_REGISTRY_VERSION:-$(go list -m github.com/operator-framework/operator-registry | cut -d" " -f2 | sed 's/^v//')}" +KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind-olmv0}" +REGISTRY="${REGISTRY:-localhost:5001}" + +# Fixtures +# Note: the following catalogs reference bundles stored in quay.io/olmtest +INDEX_V1="${REGISTRY}/busybox-dependencies-index:1.0.0-with-ListBundles-method-${OPM_VERSION}" +INDEX_V2="${REGISTRY}/busybox-dependencies-index:2.0.0-with-ListBundles-method-${OPM_VERSION}" +TEST_CATALOG_IMAGE="${REGISTRY}/test-catalog:e2e" + +## Build +${CONTAINER_RUNTIME} build -t "${INDEX_V1}" --build-arg="OPM_VERSION=v${OPERATOR_REGISTRY_VERSION}" -f ./test/images/busybox-index/index.Dockerfile ./test/images/busybox-index/indexv1 +${CONTAINER_RUNTIME} build -t "${INDEX_V2}" --build-arg="OPM_VERSION=v${OPERATOR_REGISTRY_VERSION}" -f ./test/images/busybox-index/index.Dockerfile ./test/images/busybox-index/indexv2 + +# The following catalog used for e2e tests related to serving an extracted registry +# See catalog_e2e_test.go +# let's just reuse one of the other catalogs for this - the tests don't care about the content +# only that a catalog's content can be extracted and served by a different container +${CONTAINER_RUNTIME} tag "${INDEX_V2}" "${TEST_CATALOG_IMAGE}" + +### Push +${CONTAINER_RUNTIME} push "${INDEX_V1}" +${CONTAINER_RUNTIME} push "${INDEX_V2}" +${CONTAINER_RUNTIME} push "${TEST_CATALOG_IMAGE}" diff --git a/scripts/kind_with_registry.sh b/scripts/kind_with_registry.sh new file mode 100755 index 0000000000..1a05734664 --- /dev/null +++ b/scripts/kind_with_registry.sh @@ -0,0 +1,77 @@ +#!/bin/sh +set -o errexit +set -x + +. ".bingo/variables.env" + +# Original source: https://kind.sigs.k8s.io/docs/user/local-registry/ +KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind-olmv0} +KIND=${KIND:-kind} +DOCKER=${DOCKER:-docker} +KUBECTL=${KUBECTL:-kubectl} + +# 1. Create registry container unless it already exists +reg_name='kind-registry' +reg_port='5001' +if [ "$(${DOCKER} inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then + ${DOCKER} run \ + -d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \ + registry:2 +fi + +# 2. Create kind cluster with containerd registry config dir enabled +# TODO: kind will eventually enable this by default and this patch will +# be unnecessary. +# +# See: +# https://github.com/kubernetes-sigs/kind/issues/2875 +# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration +# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md +if [ -n "${KIND_CLUSTER_IMAGE}" ]; then + KIND_IMAGE="--image=${KIND_CLUSTER_IMAGE}" +fi +cat <<EOF | ${KIND} create cluster --name="${KIND_CLUSTER_NAME}" "${KIND_IMAGE}" ${KIND_CREATE_OPTS} --config=- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +containerdConfigPatches: +- |- + [plugins."io.containerd.grpc.v1.cri".registry] + config_path = "/etc/containerd/certs.d" +EOF + +# 3. Add the registry config to the nodes +# +# This is necessary because localhost resolves to loopback addresses that are +# network-namespace local. +# In other words: localhost in the container is not localhost on the host. +# +# We want a consistent name that works from both ends, so we tell containerd to +# alias localhost:${reg_port} to the registry container when pulling images +REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}" +for node in $(${KIND} --name="${KIND_CLUSTER_NAME}" get nodes); do + ${DOCKER} exec "${node}" mkdir -p "${REGISTRY_DIR}" + cat <<EOF | ${DOCKER} exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml" +[host."http://${reg_name}:5000"] +EOF +done + +# 4. Connect the registry to the cluster network +# This allows kind to bootstrap the network but ensures they're on the same network +if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then + docker network connect "kind" "${reg_name}" +fi + +# 5. Document the local registry +# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry +${KIND} export kubeconfig --name="${KIND_CLUSTER_NAME}" +cat <<EOF | ${KUBECTL} apply -f - +apiVersion: v1 +kind: ConfigMap +metadata: + name: local-registry-hosting + namespace: kube-public +data: + localRegistryHosting.v1: | + host: "localhost:${reg_port}" + help: "https://kind.sigs.k8s.io/docs/user/local-registry/" +EOF From 7aede27477dde35d0f34b8438b5c59ffbe314796 Mon Sep 17 00:00:00 2001 From: Per Goncalves da Silva <pegoncal@redhat.com> Date: Thu, 20 Jun 2024 10:38:56 +0200 Subject: [PATCH 4/4] update e2e gha Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com> --- .github/workflows/e2e-tests.yml | 31 +++++++++++++++---------------- Makefile | 9 ++++++++- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 0ba645efe6..5d34cdd474 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -13,8 +13,6 @@ jobs: # Build the OLM image and save it as an artifact build: runs-on: ubuntu-latest - outputs: - sha: ${{ steps.vars.outputs.sha }} steps: # checkout code and setup go - uses: actions/checkout@v4 @@ -22,15 +20,13 @@ jobs: with: go-version-file: "go.mod" # build binaries and image for e2e test (includes experimental features) - - name: Build controller image - run: make e2e-build - - name: Save image - run: docker save quay.io/operator-framework/olm:local -o olm-image.tar - - name: Upload Docker image as artifact + - name: Build OLM Image + run: make e2e-build save-image + - name: Upload Artifacts uses: actions/upload-artifact@v4 with: - name: olm-image.tar - path: olm-image.tar + name: docker-images + path: "*.tar.gz" # Run e2e tests in parallel jobs # Take olm image from the previous stage @@ -53,14 +49,17 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: "go.mod" - - # load the olm image - - name: Load OLM Docker image + - name: Download build artifacts uses: actions/download-artifact@v4 with: - name: olm-image.tar - path: . - - run: docker load < olm-image.tar + name: docker-images + path: images/ + - name: Load Docker images + run: | + for image in images/*.tar.gz; do + echo "Loading image $image" + docker load -i $image + done # set e2e environment variables # Set ginkgo output and parallelism @@ -87,7 +86,7 @@ jobs: KIND_CLUSTER_NAME="kind-olmv0-${i}" \ KIND_CREATE_OPTS="--kubeconfig=${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \ HELM_INSTALL_OPTS="--kubeconfig ${E2E_KUBECONFIG_ROOT}/kubeconfig-${i}" \ - make kind-create deploy; + make kind-create load-test-images deploy; done # run non-flakes if matrix-id is not 'flakes' diff --git a/Makefile b/Makefile index fbb19078be..d90848d3ad 100644 --- a/Makefile +++ b/Makefile @@ -145,6 +145,12 @@ image: export GOOS = linux image: clean build #HELP Build image image for linux on host architecture docker build -t $(IMAGE_REPO):$(IMAGE_TAG) -f Dockerfile bin +.PHONY: save-image +TARGZ_FILE ?= olm-image.tar.gz +save-image: + docker save $(IMAGE_REPO):$(IMAGE_TAG) | gzip > "$(TARGZ_FILE)" + + .PHONE: build-e2e-fixture-images build-e2e-fixture-images: #HELP Build images for e2e testing ./scripts/e2e_test_fixtures.sh @@ -152,6 +158,7 @@ build-e2e-fixture-images: #HELP Build images for e2e testing .PHONY: e2e-build # the e2e and experimental_metrics tags are required to get e2e tests to pass # search the code for go:build e2e or go:build experimental_metrics to see where these tags are used + e2e-build: export GO_BUILD_TAGS += e2e experimental_metrics #HELP Build image for e2e testing e2e-build: IMAGE_TAG = local e2e-build: image @@ -217,7 +224,7 @@ kind-create: kind-clean #HELP Create a new kind cluster $KIND_CLUSTER_NAME (defa .PHONY: load-test-images export REGISTRY ?= localhost:5001 load-test-images: #HELP Load the OLM images into the kind cluster's registry - ./scripts/e2e_test_fixtures.sh --push-to="localhost:5001" + ./scripts/e2e_test_fixtures.sh --push-to="$(REGISTRY)" .PHONY: deploy OLM_IMAGE ?= $(IMAGE_REPO):$(IMAGE_TAG)