|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + //nolint:staticcheck // ST1001: dot-imports for readability |
| 7 | + . "github.com/onsi/ginkgo/v2" |
| 8 | + //nolint:staticcheck // ST1001: dot-imports for readability |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + |
| 11 | + "github.com/openshift/api/features" |
| 12 | + "github.com/openshift/origin/test/extended/util/image" |
| 13 | + appsv1 "k8s.io/api/apps/v1" |
| 14 | + "k8s.io/apimachinery/pkg/api/errors" |
| 15 | + "k8s.io/apimachinery/pkg/util/rand" |
| 16 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 17 | + |
| 18 | + olmv1 "github.com/operator-framework/operator-controller/api/v1" |
| 19 | + |
| 20 | + catalogdata "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/bindata/catalog" |
| 21 | + operatordata "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/bindata/operator" |
| 22 | + "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/env" |
| 23 | + "github.com/openshift/operator-framework-operator-controller/openshift/tests-extension/pkg/helpers" |
| 24 | +) |
| 25 | + |
| 26 | +var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMBoxCutterRuntime] OLMv1 Boxcutter runtime", func() { |
| 27 | + var unique, nsName, ccName, opName string |
| 28 | + |
| 29 | + BeforeEach(func(ctx SpecContext) { |
| 30 | + if !env.Get().IsOpenShift { |
| 31 | + Skip("Requires OpenShift for Boxcutter runtime tests") |
| 32 | + } |
| 33 | + helpers.RequireFeatureGateEnabled(features.FeatureGateNewOLMBoxCutterRuntime) |
| 34 | + helpers.RequireImageRegistry(ctx) |
| 35 | + |
| 36 | + testVersion := env.Get().OpenShiftVersion |
| 37 | + replacements := map[string]string{ |
| 38 | + "{{ TEST-BUNDLE }}": "", |
| 39 | + "{{ NAMESPACE }}": "", |
| 40 | + "{{ VERSION }}": testVersion, |
| 41 | + "{{ TEST-CONTROLLER }}": image.ShellImage(), |
| 42 | + } |
| 43 | + unique, nsName, ccName, opName = helpers.NewCatalogAndClusterBundles(ctx, replacements, |
| 44 | + catalogdata.AssetNames, catalogdata.Asset, |
| 45 | + operatordata.AssetNames, operatordata.Asset, |
| 46 | + ) |
| 47 | + }) |
| 48 | + |
| 49 | + AfterEach(func(ctx SpecContext) { |
| 50 | + if CurrentSpecReport().Failed() { |
| 51 | + By("dumping for debugging") |
| 52 | + helpers.DescribeAllClusterCatalogs(context.Background()) |
| 53 | + helpers.DescribeAllClusterExtensions(context.Background(), nsName) |
| 54 | + } |
| 55 | + }) |
| 56 | + |
| 57 | + It("should install a cluster extension via the Boxcutter runtime", func(ctx SpecContext) { |
| 58 | + By("ensuring no ClusterExtension for the operator") |
| 59 | + helpers.EnsureCleanupClusterExtension(context.Background(), opName, "") |
| 60 | + |
| 61 | + By("applying the ClusterExtension resource") |
| 62 | + name, cleanup := helpers.CreateClusterExtension(opName, "", nsName, unique, helpers.WithCatalogNameSelector(ccName)) |
| 63 | + DeferCleanup(cleanup) |
| 64 | + |
| 65 | + By("waiting for the ClusterExtension to be installed with availability probes passing") |
| 66 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, name) |
| 67 | + }) |
| 68 | + |
| 69 | + It("should report active revisions in the ClusterExtension status after installation", func(ctx SpecContext) { |
| 70 | + By("ensuring no ClusterExtension for the operator") |
| 71 | + helpers.EnsureCleanupClusterExtension(context.Background(), opName, "") |
| 72 | + |
| 73 | + By("applying the ClusterExtension resource") |
| 74 | + name, cleanup := helpers.CreateClusterExtension(opName, "", nsName, unique, helpers.WithCatalogNameSelector(ccName)) |
| 75 | + DeferCleanup(cleanup) |
| 76 | + |
| 77 | + By("waiting for the ClusterExtension to be installed") |
| 78 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, name) |
| 79 | + |
| 80 | + By("verifying active revisions are reported in the ClusterExtension status") |
| 81 | + k8sClient := env.Get().K8sClient |
| 82 | + Eventually(func(g Gomega) { |
| 83 | + var ext olmv1.ClusterExtension |
| 84 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: name}, &ext) |
| 85 | + g.Expect(err).ToNot(HaveOccurred()) |
| 86 | + g.Expect(ext.Status.ActiveRevisions).ToNot(BeEmpty(), |
| 87 | + "expected at least one active revision after installation") |
| 88 | + g.Expect(ext.Status.ActiveRevisions[0].Name).ToNot(BeEmpty(), |
| 89 | + "expected active revision name to be non-empty") |
| 90 | + }).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(Succeed()) |
| 91 | + }) |
| 92 | + |
| 93 | + It("should label managed resources with OLM ownership metadata", func(ctx SpecContext) { |
| 94 | + By("ensuring no ClusterExtension for the operator") |
| 95 | + helpers.EnsureCleanupClusterExtension(context.Background(), opName, "") |
| 96 | + |
| 97 | + By("applying the ClusterExtension resource") |
| 98 | + name, cleanup := helpers.CreateClusterExtension(opName, "", nsName, unique, helpers.WithCatalogNameSelector(ccName)) |
| 99 | + DeferCleanup(cleanup) |
| 100 | + |
| 101 | + By("waiting for the ClusterExtension to be installed") |
| 102 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, name) |
| 103 | + |
| 104 | + By("verifying the operator Deployment carries OLM ownership labels") |
| 105 | + k8sClient := env.Get().K8sClient |
| 106 | + Eventually(func(g Gomega) { |
| 107 | + deployments := &appsv1.DeploymentList{} |
| 108 | + err := k8sClient.List(ctx, deployments, client.InNamespace(nsName)) |
| 109 | + g.Expect(err).ToNot(HaveOccurred()) |
| 110 | + g.Expect(deployments.Items).ToNot(BeEmpty(), |
| 111 | + "expected at least one Deployment in namespace %s", nsName) |
| 112 | + |
| 113 | + found := false |
| 114 | + for _, d := range deployments.Items { |
| 115 | + labels := d.GetLabels() |
| 116 | + if labels["olm.operatorframework.io/owner-kind"] == "ClusterExtension" && |
| 117 | + labels["olm.operatorframework.io/owner-name"] == name { |
| 118 | + found = true |
| 119 | + break |
| 120 | + } |
| 121 | + } |
| 122 | + g.Expect(found).To(BeTrue(), |
| 123 | + "expected a Deployment labeled with OLM ownership for ClusterExtension %q", name) |
| 124 | + }).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(Succeed()) |
| 125 | + }) |
| 126 | + |
| 127 | + It("should clean up managed resources when a cluster extension is deleted", func(ctx SpecContext) { |
| 128 | + By("ensuring no ClusterExtension for the operator") |
| 129 | + helpers.EnsureCleanupClusterExtension(context.Background(), opName, "") |
| 130 | + |
| 131 | + By("applying the ClusterExtension resource") |
| 132 | + name, cleanup := helpers.CreateClusterExtension(opName, "", nsName, unique, helpers.WithCatalogNameSelector(ccName)) |
| 133 | + DeferCleanup(cleanup) |
| 134 | + |
| 135 | + By("waiting for the ClusterExtension to be installed") |
| 136 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, name) |
| 137 | + |
| 138 | + k8sClient := env.Get().K8sClient |
| 139 | + |
| 140 | + By("deleting the ClusterExtension") |
| 141 | + ce := &olmv1.ClusterExtension{} |
| 142 | + Expect(k8sClient.Get(ctx, client.ObjectKey{Name: name}, ce)).To(Succeed()) |
| 143 | + Expect(k8sClient.Delete(ctx, ce)).To(Succeed()) |
| 144 | + |
| 145 | + By("waiting for the ClusterExtension to be fully deleted") |
| 146 | + Eventually(func() bool { |
| 147 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: name}, &olmv1.ClusterExtension{}) |
| 148 | + return errors.IsNotFound(err) |
| 149 | + }).WithTimeout(helpers.InstallTimeout).WithPolling(helpers.DefaultPolling).Should(BeTrue(), |
| 150 | + "ClusterExtension %q was not deleted within timeout", name) |
| 151 | + |
| 152 | + By("verifying managed Deployments are removed from the namespace") |
| 153 | + Eventually(func(g Gomega) { |
| 154 | + deployments := &appsv1.DeploymentList{} |
| 155 | + err := k8sClient.List(ctx, deployments, client.InNamespace(nsName), |
| 156 | + client.MatchingLabels{"olm.operatorframework.io/owner-name": name}) |
| 157 | + g.Expect(err).ToNot(HaveOccurred()) |
| 158 | + g.Expect(deployments.Items).To(BeEmpty(), |
| 159 | + "expected no Deployments owned by ClusterExtension %q after deletion", name) |
| 160 | + }).WithTimeout(helpers.DefaultTimeout).WithPolling(helpers.DefaultPolling).Should(Succeed()) |
| 161 | + }) |
| 162 | + |
| 163 | + It("should successfully reinstall a cluster extension after deletion", func(ctx SpecContext) { |
| 164 | + By("ensuring no ClusterExtension for the operator") |
| 165 | + helpers.EnsureCleanupClusterExtension(context.Background(), opName, "") |
| 166 | + |
| 167 | + By("applying the ClusterExtension resource for the first time") |
| 168 | + firstName, firstCleanup := helpers.CreateClusterExtension(opName, "", nsName, unique, helpers.WithCatalogNameSelector(ccName)) |
| 169 | + |
| 170 | + By("waiting for the first installation to complete") |
| 171 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, firstName) |
| 172 | + |
| 173 | + k8sClient := env.Get().K8sClient |
| 174 | + |
| 175 | + By("deleting the first ClusterExtension and associated resources") |
| 176 | + firstCleanup() |
| 177 | + |
| 178 | + By("waiting for the first ClusterExtension to be fully deleted") |
| 179 | + Eventually(func() bool { |
| 180 | + err := k8sClient.Get(ctx, client.ObjectKey{Name: firstName}, &olmv1.ClusterExtension{}) |
| 181 | + return errors.IsNotFound(err) |
| 182 | + }).WithTimeout(helpers.InstallTimeout).WithPolling(helpers.DefaultPolling).Should(BeTrue(), |
| 183 | + "first ClusterExtension %q was not deleted within timeout", firstName) |
| 184 | + |
| 185 | + By("reinstalling the ClusterExtension with a fresh identity") |
| 186 | + reinstallUnique := rand.String(4) |
| 187 | + secondName, secondCleanup := helpers.CreateClusterExtension(opName, "", nsName, reinstallUnique, helpers.WithCatalogNameSelector(ccName)) |
| 188 | + DeferCleanup(secondCleanup) |
| 189 | + |
| 190 | + By("waiting for the second installation to complete") |
| 191 | + helpers.ExpectClusterExtensionToBeInstalled(ctx, secondName) |
| 192 | + }) |
| 193 | +}) |
0 commit comments