diff --git a/Makefile b/Makefile index 532f57639..3431a5ef1 100644 --- a/Makefile +++ b/Makefile @@ -110,10 +110,9 @@ e2e: $(GINKGO) #EXHELP Run the e2e tests. export REGISTRY_CTRL_IMG=localhost/registry:v0.0.1 export REGISTRY_BUNDLE_IMG=localhost/registry-bundle:v0.0.1 -export REGISTRY_CATALOG_IMG=localhost/catalog:registry export PLAIN_CTRL_IMG=localhost/plain:v0.0.1 export PLAIN_BUNDLE_IMG=localhost/plain-bundle:v0.0.1 -export PLAIN_CATALOG_IMG=localhost/catalog:plain +export CATALOG_IMG=localhost/catalog:e2e .PHONY: test-op-dev-e2e test-op-dev-e2e: $(GINKGO) $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run operator create, upgrade and delete tests. test/operator-framework-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) diff --git a/test/operator-framework-e2e/operator_framework_test.go b/test/operator-framework-e2e/operator_framework_test.go index ed4d5be83..36f0caf4a 100644 --- a/test/operator-framework-e2e/operator_framework_test.go +++ b/test/operator-framework-e2e/operator_framework_test.go @@ -11,12 +11,12 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/rand" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" - rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" ) @@ -45,108 +45,89 @@ var _ = BeforeSuite(func() { err = operatorv1alpha1.AddToScheme(scheme) Expect(err).ToNot(HaveOccurred()) - // TODO: is this necessary? - err = rukpakv1alpha1.AddToScheme(scheme) - Expect(err).ToNot(HaveOccurred()) - c, err = client.New(cfg, client.Options{Scheme: scheme}) Expect(err).ToNot(HaveOccurred()) ctx = context.Background() }) -var _ = Describe("Operator Framework E2E for plain+v0 bundles", func() { - var ( - catalog *catalogd.Catalog - operator *operatorv1alpha1.Operator - ) +var _ = Describe("Operator Framework E2E", func() { + var catalog *catalogd.Catalog BeforeEach(func() { catalog = &catalogd.Catalog{ ObjectMeta: metav1.ObjectMeta{ - Name: "plainv0", + Name: "catalog" + rand.String(10), }, Spec: catalogd.CatalogSpec{ Source: catalogd.CatalogSource{ Type: catalogd.SourceTypeImage, Image: &catalogd.ImageSource{ // TODO: make this configurable - Ref: "localhost/catalog:plain", + Ref: "localhost/catalog:e2e", }, }, }, } Expect(c.Create(ctx, catalog)).NotTo(HaveOccurred()) - operator = &operatorv1alpha1.Operator{ - ObjectMeta: metav1.ObjectMeta{ - Name: "plainv0", - }, - Spec: operatorv1alpha1.OperatorSpec{ - PackageName: "plain-operator", - }, - } - - Expect(c.Create(ctx, operator)).NotTo(HaveOccurred()) - }) - It("should succeed", func() { - Eventually(func(g Gomega) { - op := &operatorv1alpha1.Operator{} - g.Expect(c.Get(ctx, client.ObjectKeyFromObject(operator), op)).NotTo(HaveOccurred()) - cond := meta.FindStatusCondition(op.Status.Conditions, operatorv1alpha1.TypeInstalled) - g.Expect(cond).NotTo(BeNil()) - g.Expect(cond.Status).Should(Equal(metav1.ConditionTrue)) - g.Expect(cond.Reason).Should(Equal(operatorv1alpha1.ReasonSuccess)) - }).WithTimeout(2 * time.Minute).Should(Succeed()) - }) - AfterEach(func() { - Expect(c.Delete(ctx, operator)).NotTo(HaveOccurred()) - Expect(c.Delete(ctx, catalog)).NotTo(HaveOccurred()) }) -}) - -var _ = Describe("Operator Framework E2E for registry+v1 bundles", func() { - var ( - catalog *catalogd.Catalog - operator *operatorv1alpha1.Operator - ) - BeforeEach(func() { - catalog = &catalogd.Catalog{ - ObjectMeta: metav1.ObjectMeta{ - Name: "registryv0", - }, - Spec: catalogd.CatalogSpec{ - Source: catalogd.CatalogSource{ - Type: catalogd.SourceTypeImage, - Image: &catalogd.ImageSource{ - // TODO: make this configurable - Ref: "localhost/catalog:registry", - }, + When("Creating an Operator that references a package with a plain+v0 bundle type", func() { + var operator *operatorv1alpha1.Operator + BeforeEach(func() { + operator = &operatorv1alpha1.Operator{ + ObjectMeta: metav1.ObjectMeta{ + Name: "plainv0", }, - }, - } - Expect(c.Create(ctx, catalog)).NotTo(HaveOccurred()) - - operator = &operatorv1alpha1.Operator{ - ObjectMeta: metav1.ObjectMeta{ - Name: "registryv1", - }, - Spec: operatorv1alpha1.OperatorSpec{ - PackageName: "registry-operator", - }, - } - Expect(c.Create(ctx, operator)).NotTo(HaveOccurred()) + Spec: operatorv1alpha1.OperatorSpec{ + PackageName: "plain-operator", + }, + } + + Expect(c.Create(ctx, operator)).NotTo(HaveOccurred()) + }) + It("should have a status condition type of Installed with a status of True and a reason of Success", func() { + Eventually(func(g Gomega) { + op := &operatorv1alpha1.Operator{} + g.Expect(c.Get(ctx, client.ObjectKeyFromObject(operator), op)).NotTo(HaveOccurred()) + cond := meta.FindStatusCondition(op.Status.Conditions, operatorv1alpha1.TypeInstalled) + g.Expect(cond).NotTo(BeNil()) + g.Expect(cond.Status).Should(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).Should(Equal(operatorv1alpha1.ReasonSuccess)) + }).WithTimeout(2 * time.Minute).Should(Succeed()) + }) + AfterEach(func() { + Expect(c.Delete(ctx, operator)).NotTo(HaveOccurred()) + }) }) - It("should succeed", func() { - Eventually(func(g Gomega) { - op := &operatorv1alpha1.Operator{} - g.Expect(c.Get(ctx, client.ObjectKeyFromObject(operator), op)).NotTo(HaveOccurred()) - cond := meta.FindStatusCondition(op.Status.Conditions, operatorv1alpha1.TypeInstalled) - g.Expect(cond).NotTo(BeNil()) - g.Expect(cond.Status).Should(Equal(metav1.ConditionTrue)) - g.Expect(cond.Reason).Should(Equal(operatorv1alpha1.ReasonSuccess)) - }).WithTimeout(2 * time.Minute).Should(Succeed()) + When("Creating an Operator that references a package with a registry+v1 bundle type", func() { + var operator *operatorv1alpha1.Operator + BeforeEach(func() { + operator = &operatorv1alpha1.Operator{ + ObjectMeta: metav1.ObjectMeta{ + Name: "registryv1", + }, + Spec: operatorv1alpha1.OperatorSpec{ + PackageName: "registry-operator", + }, + } + + Expect(c.Create(ctx, operator)).NotTo(HaveOccurred()) + }) + It("should have a status condition type of Installed with a status of True and a reason of Success", func() { + Eventually(func(g Gomega) { + op := &operatorv1alpha1.Operator{} + g.Expect(c.Get(ctx, client.ObjectKeyFromObject(operator), op)).NotTo(HaveOccurred()) + cond := meta.FindStatusCondition(op.Status.Conditions, operatorv1alpha1.TypeInstalled) + g.Expect(cond).NotTo(BeNil()) + g.Expect(cond.Status).Should(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).Should(Equal(operatorv1alpha1.ReasonSuccess)) + }).WithTimeout(2 * time.Minute).Should(Succeed()) + }) + AfterEach(func() { + Expect(c.Delete(ctx, operator)).NotTo(HaveOccurred()) + }) }) + AfterEach(func() { - Expect(c.Delete(ctx, operator)).NotTo(HaveOccurred()) Expect(c.Delete(ctx, catalog)).NotTo(HaveOccurred()) }) }) diff --git a/test/operator-framework-e2e/setup.sh b/test/operator-framework-e2e/setup.sh index 6c9ff0e64..1fc3ecdd1 100755 --- a/test/operator-framework-e2e/setup.sh +++ b/test/operator-framework-e2e/setup.sh @@ -15,14 +15,12 @@ set -e # Defaults to "oc-opdev-e2e.operatorframework.io/registry:v0.0.1" # - $REGISTRY_BUNDLE_IMG - the tag for the registry+v1 operator bundle image. # Defaults to "oc-opdev-e2e.operatorframework.io/registry-bundle:v0.0.1" -# - $REGISTRY_CATALOG_IMG - the tag for the catalog image that contains the registry+v1 operator bundle. -# Defaults to "oc-opdev-e2e.operatorframework.io/catalog:registry" # - $PLAIN_CTRL_IMG - the tag for the plain+v0 operator image. # Defaults to "oc-opdev-e2e.operatorframework.io/registry:v0.0.1" # - $PLAIN_BUNDLE_IMG - the tag for the plain+v0 operator bundle image. # Defaults to "oc-opdev-e2e.operatorframework.io/plain-bundle:v0.0.1" -# - $PLAIN_CATALOG_IMG - the tag for the catalog image that contains the plain+v0 operator bundle. -# Defaults to "oc-opdev-e2e.operatorframework.io/catalog:plain" +# - $CATALOG_IMG - the tag for the catalog image that contains the plain+v0 and registry+v0 operator bundle. +# Defaults to "oc-opdev-e2e.operatorframework.io/catalog:e2e" # setup.sh also takes 4 arguments. Usage: # setup.sh [OPERATOR_SDK] [CONTAINER_RUNTIME] [KUSTOMIZE] [KIND] [KIND_CLUSTER_NAME] ################################################################# @@ -51,10 +49,9 @@ kcluster_name=$5 reg_img=${REGISTRY_CTRL_IMG:-"$DOMAIN/registry:v0.0.1"} reg_bundle_img=${REGISTRY_BUNDLE_IMG:-"$DOMAIN/registry-bundle:v0.0.1"} -reg_catalog_img=${REGISTRY_CATALOG_IMG:-"$DOMAIN/catalog:registry"} plain_img=${PLAIN_CTRL_IMG:-"$DOMAIN/plain:v0.0.1"} plain_bundle_img=${PLAIN_BUNDLE_IMG:-"$DOMAIN/plain-bundle:v0.0.1"} -plain_catalog_img=${PLAIN_CATALOG_IMG:-"$DOMAIN/catalog:plain"} +catalog_img=${CATALOG_IMG:-"$DOMAIN/catalog:e2e"} ######################################## # Create the registry+v1 based operator @@ -76,52 +73,8 @@ plain_catalog_img=${PLAIN_CATALOG_IMG:-"$DOMAIN/catalog:plain"} make bundle-build BUNDLE_IMG="$reg_bundle_img" ) -cat << EOF > "$REG_DIR"/catalog.Dockerfile -FROM quay.io/operator-framework/opm:latest -ENTRYPOINT ["/bin/opm"] -CMD ["serve", "/configs"] -ADD catalog /configs -LABEL operators.operatorframework.io.index.configs.v1=/configs -EOF - -mkdir -p "$REG_DIR"/catalog -cat < "$REG_DIR"/catalog/index.yaml -{ - "schema": "olm.package", - "name": "registry-operator" -} -{ - "schema": "olm.bundle", - "name": "registry-operator.v0.0.1", - "package": "registry-operator", - "image": "$reg_bundle_img", - "properties": [ - { - "type": "olm.package", - "value": { - "packageName": "registry-operator", - "version": "0.0.1" - } - } - ] -} -{ - "schema": "olm.channel", - "name": "preview", - "package": "registry-operator", - "entries": [ - { - "name": "registry-operator.v0.0.1" - } - ] -} -EOF - -$container_tool build -t "$reg_catalog_img" -f "$REG_DIR"/catalog.Dockerfile "$REG_DIR"/ - $kind load docker-image "$reg_img" --name "$kcluster_name" $kind load docker-image "$reg_bundle_img" --name "$kcluster_name" -$kind load docker-image "$reg_catalog_img" --name "$kcluster_name" ##################################### # Create the plain+v0 based operator @@ -149,13 +102,50 @@ EOF $container_tool build -t "$plain_bundle_img" -f "$PLAIN_DIR"/plainbundle.Dockerfile "$PLAIN_DIR"/ -cat << EOF > "$PLAIN_DIR"/catalog.Dockerfile +$kind load docker-image "$plain_img" --name "$kcluster_name" +$kind load docker-image "$plain_bundle_img" --name "$kcluster_name" + +##################################### +# Create the FBC that contains both +# the plain+v0 and registry+v1 operators +##################################### + +cat << EOF > "$TMP_ROOT"/catalog.Dockerfile FROM scratch ADD catalog /configs EOF -mkdir -p "$PLAIN_DIR"/catalog -cat < "$PLAIN_DIR"/catalog/index.yaml +mkdir -p "$TMP_ROOT/catalog" +cat < "$TMP_ROOT"/catalog/index.yaml +{ + "schema": "olm.package", + "name": "registry-operator" +} +{ + "schema": "olm.bundle", + "name": "registry-operator.v0.0.1", + "package": "registry-operator", + "image": "$reg_bundle_img", + "properties": [ + { + "type": "olm.package", + "value": { + "packageName": "registry-operator", + "version": "0.0.1" + } + } + ] +} +{ + "schema": "olm.channel", + "name": "preview", + "package": "registry-operator", + "entries": [ + { + "name": "registry-operator.v0.0.1" + } + ] +} { "schema": "olm.package", "name": "plain-operator" @@ -191,11 +181,8 @@ cat < "$PLAIN_DIR"/catalog/index.yaml } EOF -docker build -t "$plain_catalog_img" -f "$PLAIN_DIR"/catalog.Dockerfile "$PLAIN_DIR"/ - -$kind load docker-image "$plain_img" --name "$kcluster_name" -$kind load docker-image "$plain_bundle_img" --name "$kcluster_name" -$kind load docker-image "$plain_catalog_img" --name "$kcluster_name" +docker build -t "$catalog_img" -f "$TMP_ROOT"/catalog.Dockerfile "$TMP_ROOT"/ +$kind load docker-image "$catalog_img" --name "$kcluster_name" # Make sure all files are removable. This is necessary because # the Makefiles generated by the Operator-SDK have targets