|
1 | 1 | package operators |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "encoding/json" |
6 | 5 | "fmt" |
7 | | - "os" |
8 | | - "path/filepath" |
9 | | - "strings" |
10 | | - "time" |
11 | | - |
12 | 6 | g "github.com/onsi/ginkgo/v2" |
13 | 7 | o "github.com/onsi/gomega" |
| 8 | + configv1 "github.com/openshift/api/config/v1" |
| 9 | + exutil "github.com/openshift/origin/test/extended/util" |
14 | 10 | "k8s.io/apimachinery/pkg/api/meta" |
15 | 11 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
16 | 12 | "k8s.io/apimachinery/pkg/util/rand" |
17 | | - "k8s.io/apimachinery/pkg/util/wait" |
18 | | - |
19 | | - configv1 "github.com/openshift/api/config/v1" |
20 | | - exutil "github.com/openshift/origin/test/extended/util" |
| 13 | + "os" |
| 14 | + "strings" |
21 | 15 | ) |
22 | 16 |
|
23 | 17 | const ( |
24 | | - olmv1GroupName = "olm.operatorframework.io" |
25 | | - typeIncompatibleOperatorsUpgradeable = "InstalledOLMOperatorsUpgradeable" |
26 | | - reasonIncompatibleOperatorsInstalled = "IncompatibleOperatorsInstalled" |
27 | | - |
28 | 18 | typeInstalled = "Installed" |
29 | 19 | typeProgressing = "Progressing" |
30 | 20 |
|
31 | 21 | reasonRetrying = "Retrying" |
32 | 22 | ) |
33 | 23 |
|
34 | | -var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 operator installation", func() { |
35 | | - defer g.GinkgoRecover() |
36 | | - |
37 | | - var ( |
38 | | - baseDir = exutil.FixturePath("testdata", "olmv1") |
39 | | - ceFile = filepath.Join(baseDir, "install-operator.yaml") |
40 | | - ) |
41 | | - oc := exutil.NewCLI("openshift-operator-controller") |
42 | | - |
43 | | - g.BeforeEach(func() { |
44 | | - exutil.PreTestDump() |
45 | | - }) |
46 | | - |
47 | | - g.AfterEach(func() { |
48 | | - if g.CurrentSpecReport().Failed() { |
49 | | - exutil.DumpPodLogsStartingWith("", oc) |
50 | | - } |
51 | | - }) |
52 | | - |
53 | | - g.It("should install a cluster extension", func(ctx g.SpecContext) { |
54 | | - checkFeatureCapability(oc) |
55 | | - |
56 | | - const ( |
57 | | - packageName = "quay-operator" |
58 | | - version = "3.13.0" |
59 | | - ) |
60 | | - |
61 | | - cleanup, unique := applyResourceFile(oc, packageName, version, "", ceFile) |
62 | | - ceName := "install-test-ce-" + unique |
63 | | - g.DeferCleanup(cleanup) |
64 | | - |
65 | | - g.By("waiting for the ClusterExtention to be installed") |
66 | | - var lastReason string |
67 | | - err := wait.PollUntilContextTimeout(ctx, time.Second, 5*time.Minute, true, |
68 | | - func(ctx context.Context) (bool, error) { |
69 | | - b, err, s := waitForClusterExtensionReady(oc, ceName) |
70 | | - if lastReason != s { |
71 | | - g.GinkgoLogr.Info(fmt.Sprintf("waitForClusterExtensionReady: %q", s)) |
72 | | - lastReason = s |
73 | | - } |
74 | | - return b, err |
75 | | - }) |
76 | | - o.Expect(lastReason).To(o.BeEmpty()) |
77 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
78 | | - }) |
79 | | - |
80 | | - g.It("should fail to install a non-existing cluster extension", func(ctx g.SpecContext) { |
81 | | - checkFeatureCapability(oc) |
82 | | - |
83 | | - const ( |
84 | | - packageName = "does-not-exist" |
85 | | - version = "99.99.99" |
86 | | - ) |
87 | | - |
88 | | - cleanup, unique := applyResourceFile(oc, packageName, version, "", ceFile) |
89 | | - ceName := "install-test-ce-" + unique |
90 | | - g.DeferCleanup(cleanup) |
91 | | - |
92 | | - g.By("waiting for the ClusterExtention to report failure") |
93 | | - var lastReason string |
94 | | - err := wait.PollUntilContextTimeout(ctx, time.Second, 5*time.Minute, true, |
95 | | - func(ctx context.Context) (bool, error) { |
96 | | - b, err, s := waitForClusterExtensionFailure(oc, ceName) |
97 | | - if lastReason != s { |
98 | | - g.GinkgoLogr.Info(fmt.Sprintf("waitForClusterExtensionFailure: %q", s)) |
99 | | - lastReason = s |
100 | | - } |
101 | | - return b, err |
102 | | - }) |
103 | | - o.Expect(lastReason).To(o.BeEmpty()) |
104 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
105 | | - }) |
106 | | - |
107 | | - g.It("should block cluster upgrades if an incompatible operator is installed", func(ctx g.SpecContext) { |
108 | | - checkFeatureCapability(oc) |
109 | | - |
110 | | - const ( |
111 | | - packageName = "cluster-logging" |
112 | | - version = "6.2.2" |
113 | | - ) |
114 | | - |
115 | | - cleanup, unique := applyResourceFile(oc, packageName, version, "", ceFile) |
116 | | - ceName := "install-test-ce-" + unique |
117 | | - g.DeferCleanup(cleanup) |
118 | | - |
119 | | - g.By("waiting for the ClusterExtention to be installed") |
120 | | - var lastReason string |
121 | | - err := wait.PollUntilContextTimeout(ctx, time.Second, 5*time.Minute, true, |
122 | | - func(ctx context.Context) (bool, error) { |
123 | | - b, err, s := waitForClusterExtensionReady(oc, ceName) |
124 | | - if lastReason != s { |
125 | | - g.GinkgoLogr.Info(fmt.Sprintf("waitForClusterExtensionReady: %q", s)) |
126 | | - lastReason = s |
127 | | - } |
128 | | - return b, err |
129 | | - }) |
130 | | - o.Expect(lastReason).To(o.BeEmpty()) |
131 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
132 | | - |
133 | | - g.By("ensuring the cluster is not upgradeable when olm.maxopenshiftversion is specified") |
134 | | - lastReason = "" |
135 | | - err = wait.PollUntilContextTimeout(ctx, time.Second, 5*time.Minute, true, |
136 | | - func(ctx context.Context) (bool, error) { |
137 | | - b, err, s := waitForUpgradableCondition(oc, false, ceName) |
138 | | - if lastReason != s { |
139 | | - g.GinkgoLogr.Info(fmt.Sprintf("waitForUpgradableCondition: %q", s)) |
140 | | - lastReason = s |
141 | | - } |
142 | | - return b, err |
143 | | - }) |
144 | | - o.Expect(lastReason).To(o.BeEmpty()) |
145 | | - o.Expect(err).NotTo(o.HaveOccurred()) |
146 | | - }) |
147 | | -}) |
148 | | - |
149 | 24 | // Use the supplied |unique| value if provided, otherwise generate a unique string. The unique string is returned. |
150 | 25 | // |unique| is used to combine common test elements and to avoid duplicate names, which can occur if, for instance, |
151 | 26 | // the packageName is used. |
@@ -207,75 +82,6 @@ func waitForClusterExtensionReady(oc *exutil.CLI, ceName string) (bool, error, s |
207 | 82 | return true, nil, "" |
208 | 83 | } |
209 | 84 |
|
210 | | -func waitForClusterExtensionFailure(oc *exutil.CLI, ceName string) (bool, error, string) { |
211 | | - var conditions []metav1.Condition |
212 | | - output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterextensions.olm.operatorframework.io", ceName, "-o=jsonpath={.status.conditions}").Output() |
213 | | - if err != nil { |
214 | | - return false, err, "" |
215 | | - } |
216 | | - // no data yet, so try again |
217 | | - if output == "" { |
218 | | - return false, nil, "no output" |
219 | | - } |
220 | | - if err := json.Unmarshal([]byte(output), &conditions); err != nil { |
221 | | - return false, fmt.Errorf("error in json.Unmarshal(%v): %v", output, err), "" |
222 | | - } |
223 | | - c := meta.FindStatusCondition(conditions, typeProgressing) |
224 | | - if c == nil { |
225 | | - return false, nil, fmt.Sprintf("condition not present: %q", typeProgressing) |
226 | | - } |
227 | | - if c.Status != metav1.ConditionTrue { |
228 | | - return false, nil, fmt.Sprintf("expected status to be %q: %+v", metav1.ConditionTrue, c) |
229 | | - } |
230 | | - if !strings.HasPrefix(c.Message, "no bundles found") { |
231 | | - return false, nil, fmt.Sprintf("expected message to contain %q: %+v", "no bundles found", c) |
232 | | - } |
233 | | - c = meta.FindStatusCondition(conditions, typeInstalled) |
234 | | - if c == nil { |
235 | | - return false, nil, fmt.Sprintf("condition not present: %q", typeInstalled) |
236 | | - } |
237 | | - if c.Status != metav1.ConditionFalse { |
238 | | - return false, nil, fmt.Sprintf("expected status to be %q: %+v", metav1.ConditionFalse, c) |
239 | | - } |
240 | | - return true, nil, "" |
241 | | -} |
242 | | - |
243 | | -func waitForUpgradableCondition(oc *exutil.CLI, status bool, ceName string) (bool, error, string) { |
244 | | - var conditions []metav1.Condition |
245 | | - output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("olms.operator.openshift.io", "cluster", "-o=jsonpath={.status.conditions}").Output() |
246 | | - if err != nil { |
247 | | - return false, err, "" |
248 | | - } |
249 | | - // no data yet, so try again |
250 | | - if output == "" { |
251 | | - return false, nil, "no output" |
252 | | - } |
253 | | - if err := json.Unmarshal([]byte(output), &conditions); err != nil { |
254 | | - return false, fmt.Errorf("error in json.Unmarshal(%v): %v", output, err), "" |
255 | | - } |
256 | | - c := meta.FindStatusCondition(conditions, typeIncompatibleOperatorsUpgradeable) |
257 | | - if c == nil { |
258 | | - return false, nil, fmt.Sprintf("condition not present: %q", typeIncompatibleOperatorsUpgradeable) |
259 | | - } |
260 | | - if status { |
261 | | - if c.Status != metav1.ConditionTrue { |
262 | | - return false, nil, fmt.Sprintf("expected status to be %q: %+v", metav1.ConditionTrue, c) |
263 | | - } |
264 | | - return true, nil, "" |
265 | | - } |
266 | | - if c.Status != metav1.ConditionFalse { |
267 | | - return false, nil, fmt.Sprintf("expected status to be %q: %+v", metav1.ConditionFalse, c) |
268 | | - } |
269 | | - if c.Reason != reasonIncompatibleOperatorsInstalled { |
270 | | - return false, nil, fmt.Sprintf("expected reason to be %q: %+v", reasonIncompatibleOperatorsInstalled, c) |
271 | | - } |
272 | | - // Message should include "bundle %q for ClusterExtension %q" |
273 | | - if !strings.Contains(c.Message, ceName) { |
274 | | - return false, nil, fmt.Sprintf("expected message to contain %q: %+v", ceName, c) |
275 | | - } |
276 | | - return true, nil, "" |
277 | | -} |
278 | | - |
279 | 85 | func checkFeatureCapability(oc *exutil.CLI) { |
280 | 86 | cap, err := exutil.IsCapabilityEnabled(oc, configv1.ClusterVersionCapabilityOperatorLifecycleManagerV1) |
281 | 87 | o.Expect(err).NotTo(o.HaveOccurred()) |
|
0 commit comments