|
1 | 1 | package upgradee2e |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bufio" |
5 | 4 | "context" |
6 | 5 | "fmt" |
7 | 6 | "io" |
@@ -37,52 +36,37 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) { |
37 | 36 | ctx := context.Background() |
38 | 37 | defer getArtifactsOutput(t) |
39 | 38 |
|
40 | | - managerLabelSelector := labels.Set{"control-plane": "operator-controller-controller-manager"} |
| 39 | + // wait for catalogd deployment to finish |
| 40 | + t.Log("Wait for catalogd deployment to be ready") |
| 41 | + waitForDeployment(t, ctx, "catalogd-controller-manager") |
41 | 42 |
|
42 | | - t.Log("Checking that the controller-manager deployment is updated") |
43 | | - require.EventuallyWithT(t, func(ct *assert.CollectT) { |
44 | | - var managerDeployments appsv1.DeploymentList |
45 | | - assert.NoError(ct, c.List(ctx, &managerDeployments, client.MatchingLabelsSelector{Selector: managerLabelSelector.AsSelector()})) |
46 | | - assert.Len(ct, managerDeployments.Items, 1) |
47 | | - managerDeployment := managerDeployments.Items[0] |
| 43 | + // wait for operator-controller deployment to finish |
| 44 | + t.Log("Wait for operator-controller deployment to be ready") |
| 45 | + waitForDeployment(t, ctx, "operator-controller-controller-manager") |
48 | 46 |
|
49 | | - assert.True(ct, |
50 | | - managerDeployment.Status.UpdatedReplicas == *managerDeployment.Spec.Replicas && |
51 | | - managerDeployment.Status.Replicas == *managerDeployment.Spec.Replicas && |
52 | | - managerDeployment.Status.AvailableReplicas == *managerDeployment.Spec.Replicas && |
53 | | - managerDeployment.Status.ReadyReplicas == *managerDeployment.Spec.Replicas, |
54 | | - ) |
55 | | - }, time.Minute, time.Second) |
56 | | - |
57 | | - var managerPods corev1.PodList |
58 | | - t.Log("Waiting for only one controller-manager Pod to remain") |
59 | | - require.EventuallyWithT(t, func(ct *assert.CollectT) { |
60 | | - assert.NoError(ct, c.List(ctx, &managerPods, client.MatchingLabelsSelector{Selector: managerLabelSelector.AsSelector()})) |
61 | | - assert.Len(ct, managerPods.Items, 1) |
62 | | - }, time.Minute, time.Second) |
63 | | - |
64 | | - t.Log("Reading logs to make sure that ClusterExtension was reconciled by operator-controller before we update it") |
65 | | - // Make sure that after we upgrade OLM itself we can still reconcile old objects without any changes |
66 | | - logCtx, cancel := context.WithTimeout(ctx, time.Minute) |
67 | | - defer cancel() |
68 | | - substrings := []string{ |
69 | | - "reconcile ending", |
70 | | - fmt.Sprintf(`ClusterExtension=%q`, testClusterExtensionName), |
71 | | - } |
72 | | - found, err := watchPodLogsForSubstring(logCtx, &managerPods.Items[0], "manager", substrings...) |
73 | | - require.NoError(t, err) |
74 | | - require.True(t, found) |
75 | | - |
76 | | - t.Log("Checking that the ClusterCatalog is serving") |
| 47 | + t.Log("Checking that the ClusterCatalog is unpacked") |
77 | 48 | require.EventuallyWithT(t, func(ct *assert.CollectT) { |
78 | 49 | var clusterCatalog catalogd.ClusterCatalog |
79 | 50 | assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: testClusterCatalogName}, &clusterCatalog)) |
| 51 | + |
| 52 | + // check serving condition |
80 | 53 | cond := apimeta.FindStatusCondition(clusterCatalog.Status.Conditions, catalogd.TypeServing) |
81 | 54 | if !assert.NotNil(ct, cond) { |
82 | 55 | return |
83 | 56 | } |
84 | 57 | assert.Equal(ct, metav1.ConditionTrue, cond.Status) |
85 | 58 | assert.Equal(ct, catalogd.ReasonAvailable, cond.Reason) |
| 59 | + |
| 60 | + // check progressing condition |
| 61 | + cond = apimeta.FindStatusCondition(clusterCatalog.Status.Conditions, catalogd.TypeProgressing) |
| 62 | + if !assert.NotNil(ct, cond) { |
| 63 | + return |
| 64 | + } |
| 65 | + assert.Equal(ct, metav1.ConditionTrue, cond.Status) |
| 66 | + assert.Equal(ct, catalogd.ReasonSucceeded, cond.Reason) |
| 67 | + |
| 68 | + // check that the catalog was recently unpacked (after progressing is over) |
| 69 | + assert.True(ct, cond.LastTransitionTime.Before(clusterCatalog.Status.LastUnpacked)) |
86 | 70 | }, time.Minute, time.Second) |
87 | 71 |
|
88 | 72 | t.Log("Checking that the ClusterExtension is installed") |
@@ -122,37 +106,63 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) { |
122 | 106 | }, time.Minute, time.Second) |
123 | 107 | } |
124 | 108 |
|
125 | | -func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container string, substrings ...string) (bool, error) { |
126 | | - podLogOpts := corev1.PodLogOptions{ |
127 | | - Follow: true, |
128 | | - Container: container, |
129 | | - } |
| 109 | +func waitForDeployment(t *testing.T, ctx context.Context, controlPlaneLabel string) { |
| 110 | + deploymentLabelSelector := labels.Set{"control-plane": controlPlaneLabel}.AsSelector() |
130 | 111 |
|
131 | | - req := kclientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts) |
132 | | - podLogs, err := req.Stream(ctx) |
133 | | - if err != nil { |
134 | | - return false, err |
135 | | - } |
136 | | - defer podLogs.Close() |
137 | | - |
138 | | - scanner := bufio.NewScanner(podLogs) |
139 | | - for scanner.Scan() { |
140 | | - line := scanner.Text() |
| 112 | + t.Log("Checking that the deployment is updated") |
| 113 | + require.EventuallyWithT(t, func(ct *assert.CollectT) { |
| 114 | + var managerDeployments appsv1.DeploymentList |
| 115 | + assert.NoError(ct, c.List(ctx, &managerDeployments, client.MatchingLabelsSelector{Selector: deploymentLabelSelector})) |
| 116 | + assert.Len(ct, managerDeployments.Items, 1) |
| 117 | + managerDeployment := managerDeployments.Items[0] |
141 | 118 |
|
142 | | - foundCount := 0 |
143 | | - for _, substring := range substrings { |
144 | | - if strings.Contains(line, substring) { |
145 | | - foundCount++ |
146 | | - } |
147 | | - } |
148 | | - if foundCount == len(substrings) { |
149 | | - return true, nil |
150 | | - } |
151 | | - } |
| 119 | + assert.True(ct, |
| 120 | + managerDeployment.Status.UpdatedReplicas == *managerDeployment.Spec.Replicas && |
| 121 | + managerDeployment.Status.Replicas == *managerDeployment.Spec.Replicas && |
| 122 | + managerDeployment.Status.AvailableReplicas == *managerDeployment.Spec.Replicas && |
| 123 | + managerDeployment.Status.ReadyReplicas == *managerDeployment.Spec.Replicas, |
| 124 | + ) |
| 125 | + }, time.Minute, time.Second) |
152 | 126 |
|
153 | | - return false, scanner.Err() |
| 127 | + var managerPods corev1.PodList |
| 128 | + t.Log("Waiting for only one Pod to remain") |
| 129 | + require.EventuallyWithT(t, func(ct *assert.CollectT) { |
| 130 | + assert.NoError(ct, c.List(ctx, &managerPods, client.MatchingLabelsSelector{Selector: deploymentLabelSelector})) |
| 131 | + assert.Len(ct, managerPods.Items, 1) |
| 132 | + }, time.Minute, time.Second) |
154 | 133 | } |
155 | 134 |
|
| 135 | +//func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container string, substrings ...string) (bool, error) { |
| 136 | +// podLogOpts := corev1.PodLogOptions{ |
| 137 | +// Follow: true, |
| 138 | +// Container: container, |
| 139 | +// } |
| 140 | +// |
| 141 | +// req := kclientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts) |
| 142 | +// podLogs, err := req.Stream(ctx) |
| 143 | +// if err != nil { |
| 144 | +// return false, err |
| 145 | +// } |
| 146 | +// defer podLogs.Close() |
| 147 | +// |
| 148 | +// scanner := bufio.NewScanner(podLogs) |
| 149 | +// for scanner.Scan() { |
| 150 | +// line := scanner.Text() |
| 151 | +// |
| 152 | +// foundCount := 0 |
| 153 | +// for _, substring := range substrings { |
| 154 | +// if strings.Contains(line, substring) { |
| 155 | +// foundCount++ |
| 156 | +// } |
| 157 | +// } |
| 158 | +// if foundCount == len(substrings) { |
| 159 | +// return true, nil |
| 160 | +// } |
| 161 | +// } |
| 162 | +// |
| 163 | +// return false, scanner.Err() |
| 164 | +//} |
| 165 | + |
156 | 166 | // getArtifactsOutput gets all the artifacts from the test run and saves them to the artifact path. |
157 | 167 | // Currently it saves: |
158 | 168 | // - clusterextensions |
|
0 commit comments