diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index f3c2ef0e92..90935f7eb4 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -46,6 +46,14 @@ To run a specific e2e test locally: $ make e2e-local TEST=TestCreateInstallPlanManualApproval ``` +##### Updating test images + +Sometimes you will need to update the index or bundle images used in the unit or e2e tests. To update those images, you will need to be logged into quay.io with membership in the `olmtest` organization. Then simply run `./scripts/build_e2e_test_images.sh` which will build all the required bundle images, push those to quay.io, build all the index images, and push those to quay.io as well. + +Please be aware that these scripts push directly to the image tags used by the actual e2e tests. + +The contents and Containerfiles of these bundles can be found in `./test/images/`. + [controller-runtime instructions]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest#section-readme #### Building diff --git a/scripts/build_e2e_test_images.sh b/scripts/build_e2e_test_images.sh new file mode 100755 index 0000000000..916a07898d --- /dev/null +++ b/scripts/build_e2e_test_images.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +QUAY_REPO="${QUAY_REPO:-olmtest}" +SINGLE_BUNDLE_TAG="${BUNDLE_TAG:-objects-pdb-v2}" +SINGLE_BUNDLE_INDEX_TAG="${INDEX_TAG:-pdb-v2}" + +# Busybox Operator Index Image +docker build -t quay.io/${QUAY_REPO}/busybox-bundle:1.0.0 ./test/images/busybox-index/busybox/1.0.0 +docker build -t quay.io/${QUAY_REPO}/busybox-bundle:2.0.0 ./test/images/busybox-index/busybox/2.0.0 + +docker build -t quay.io/${QUAY_REPO}/busybox-dependency-bundle:1.0.0 ./test/images/busybox-index/busybox-dependency/1.0.0 +docker build -t quay.io/${QUAY_REPO}/busybox-dependency-bundle:2.0.0 ./test/images/busybox-index/busybox-dependency/2.0.0 + +docker push quay.io/${QUAY_REPO}/busybox-bundle:1.0.0 +docker push quay.io/${QUAY_REPO}/busybox-bundle:2.0.0 +docker push quay.io/${QUAY_REPO}/busybox-dependency-bundle:1.0.0 +docker push quay.io/${QUAY_REPO}/busybox-dependency-bundle:2.0.0 + +opm index add --bundles quay.io/${QUAY_REPO}/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/${QUAY_REPO}/busybox-dependencies-index:1.0.0-with-ListBundles-method + +opm index add --bundles quay.io/${QUAY_REPO}/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/${QUAY_REPO}/busybox-dependencies-index:2.0.0-with-ListBundles-method + +# Single Bundle E2E Test Image +docker build -t quay.io/${QUAY_REPO}/bundle:${BUNDLE_TAG} ./test/images/single-bundle-index +docker push quay.io/${QUAY_REPO}/bundle:${BUNDLE_TAG} + +opm index add --bundles quay.io/${QUAY_REPO}/bundle:${BUNDLE_TAG} --tag quay.io/${QUAY_REPO}/single-bundle-index:${INDEX_TAG} -c docker +docker push quay.io/${QUAY_REPO}/single-bundle-index:${INDEX_TAG} 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/test/e2e/bundle_e2e_test.go b/test/e2e/bundle_e2e_test.go index 9accdbb9c0..365d1cdf27 100644 --- a/test/e2e/bundle_e2e_test.go +++ b/test/e2e/bundle_e2e_test.go @@ -47,7 +47,8 @@ var _ = Describe("Installing bundles with new object types", Label("ObjectTypes" TeardownNamespace(generatedNamespace.GetName()) }) - When("a bundle with a pdb, priorityclass, and VPA object is installed", func() { + When("a bundle that includes supported resources is installed", func() { + // Supported resources installed are a NetworkPolicy, pdb, priorityclass, and VPA object const ( packageName = "busybox" channelName = "alpha" @@ -59,7 +60,7 @@ var _ = Describe("Installing bundles with new object types", Label("ObjectTypes" By("first installing the VPA CRD on cluster") const ( sourceName = "test-catalog" - imageName = "quay.io/olmtest/single-bundle-index:pdb-v1" + imageName = "quay.io/olmtest/single-bundle-index:pdb-v2" ) By("create VPA CRD on cluster") @@ -141,6 +142,7 @@ var _ = Describe("Installing bundles with new object types", Label("ObjectTypes" pdbName = "busybox-pdb" priorityClassName = "super-priority" vpaName = "busybox-vpa" + networkPolicyName = "busybox-networkpolicy" ) var resource = schema.GroupVersionResource{ @@ -164,6 +166,11 @@ var _ = Describe("Installing bundles with new object types", Label("ObjectTypes" _, err := kubeClient.KubernetesInterface().PolicyV1().PodDisruptionBudgets(generatedNamespace.GetName()).Get(context.Background(), pdbName, metav1.GetOptions{}) return err }).Should(Succeed(), "expected no error getting pdb object associated with CSV") + + Eventually(func() error { + _, err := kubeClient.KubernetesInterface().NetworkingV1().NetworkPolicies(generatedNamespace.GetName()).Get(context.Background(), networkPolicyName, metav1.GetOptions{}) + return err + }).Should(Succeed(), "expected no error finding networkpolicy object associated with CSV") }) AfterEach(func() { diff --git a/test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml b/test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml index 83153df57d..92d804c296 100644 --- a/test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml +++ b/test/images/busybox-index/busybox/1.0.0/manifests/csv.yaml @@ -34,6 +34,12 @@ spec: command: - sleep - "9000" + permissions: + - serviceAccountName: busybox-operator + rules: + - apiGroups: ["networking.k8s.io"] + resources: ["networkpolicies"] + verbs: ["get", "list", "create", "update", "delete"] strategy: deployment installModes: - supported: true diff --git a/test/images/single-bundle-image/Containerfile b/test/images/single-bundle-image/Containerfile new file mode 100644 index 0000000000..94c7d62983 --- /dev/null +++ b/test/images/single-bundle-image/Containerfile @@ -0,0 +1,13 @@ +FROM scratch + +# We are pushing an operator-registry bundle +# that has both metadata and manifests. +LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1 +LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ +LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ +LABEL operators.operatorframework.io.bundle.package.v1=busybox +LABEL operators.operatorframework.io.bundle.channels.v1=alpha +LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha + +COPY ./manifests/*.yaml /manifests/ +COPY ./metadata/annotations.yaml /metadata/annotations.yaml diff --git a/test/images/single-bundle-image/manifests/csv.yaml b/test/images/single-bundle-image/manifests/csv.yaml new file mode 100644 index 0000000000..8ef57b02b3 --- /dev/null +++ b/test/images/single-bundle-image/manifests/csv.yaml @@ -0,0 +1,42 @@ +apiVersion: operators.coreos.com/v1alpha1 +kind: ClusterServiceVersion +metadata: + name: busybox.v2.0.0 + namespace: operators +spec: + description: busybox + displayName: busybox + install: + spec: + deployments: + - name: busybox + spec: + replicas: 1 + selector: + matchLabels: + app: busybox + template: + metadata: + labels: + app: busybox + spec: + containers: + - command: + - sleep + - "9000" + image: busybox + name: busybox + strategy: deployment + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: true + type: MultiNamespace + - supported: true + type: AllNamespaces + maturity: alpha + provider: + name: Red Hat + version: 2.0.0 diff --git a/test/images/single-bundle-image/manifests/networkpolicy.yaml b/test/images/single-bundle-image/manifests/networkpolicy.yaml new file mode 100644 index 0000000000..9cfe91985e --- /dev/null +++ b/test/images/single-bundle-image/manifests/networkpolicy.yaml @@ -0,0 +1,8 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: busybox-networkpolicy +spec: + podSelector: {} + policyTypes: + - Ingress diff --git a/test/images/single-bundle-image/manifests/poddisruptionbudget.yaml b/test/images/single-bundle-image/manifests/poddisruptionbudget.yaml new file mode 100644 index 0000000000..98f45c8781 --- /dev/null +++ b/test/images/single-bundle-image/manifests/poddisruptionbudget.yaml @@ -0,0 +1,10 @@ +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: busybox-pdb +spec: + minAvailable: 2 + selector: + matchLabels: + app: busybox + \ No newline at end of file diff --git a/test/images/single-bundle-image/manifests/priorityclass.yaml b/test/images/single-bundle-image/manifests/priorityclass.yaml new file mode 100644 index 0000000000..92320d2fdb --- /dev/null +++ b/test/images/single-bundle-image/manifests/priorityclass.yaml @@ -0,0 +1,7 @@ +apiVersion: scheduling.k8s.io/v1 +kind: PriorityClass +metadata: + name: super-priority +description: This priority class should be used for XYZ service pods only. +globalDefault: false +value: 1000 diff --git a/test/images/single-bundle-image/manifests/verticalpodautoscaler.yaml b/test/images/single-bundle-image/manifests/verticalpodautoscaler.yaml new file mode 100644 index 0000000000..1b550efb60 --- /dev/null +++ b/test/images/single-bundle-image/manifests/verticalpodautoscaler.yaml @@ -0,0 +1,11 @@ +apiVersion: autoscaling.k8s.io/v1 +kind: VerticalPodAutoscaler +metadata: + name: busybox-vpa +spec: + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: busybox + updatePolicy: + updateMode: "Off" diff --git a/test/images/single-bundle-image/metadata/annotations.yaml b/test/images/single-bundle-image/metadata/annotations.yaml new file mode 100644 index 0000000000..8d4f3fd706 --- /dev/null +++ b/test/images/single-bundle-image/metadata/annotations.yaml @@ -0,0 +1,7 @@ +annotations: + operators.operatorframework.io.bundle.mediatype.v1: "registry+v1" + operators.operatorframework.io.bundle.manifests.v1: "manifests/" + operators.operatorframework.io.bundle.metadata.v1: "metadata/" + operators.operatorframework.io.bundle.package.v1: "busybox" + operators.operatorframework.io.bundle.channels.v1: "alpha" + operators.operatorframework.io.bundle.channel.default.v1: "alpha"