Skip to content

Commit 767675c

Browse files
author
Per Goncalves da Silva
committed
assert that last unpacked > progressing last transitioned
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 171af61 commit 767675c

File tree

1 file changed

+72
-62
lines changed

1 file changed

+72
-62
lines changed

test/upgrade-e2e/post_upgrade_test.go

Lines changed: 72 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package upgradee2e
22

33
import (
4-
"bufio"
54
"context"
65
"fmt"
76
"io"
@@ -37,52 +36,37 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
3736
ctx := context.Background()
3837
defer getArtifactsOutput(t)
3938

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")
4142

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")
4846

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")
7748
require.EventuallyWithT(t, func(ct *assert.CollectT) {
7849
var clusterCatalog catalogd.ClusterCatalog
7950
assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: testClusterCatalogName}, &clusterCatalog))
51+
52+
// check serving condition
8053
cond := apimeta.FindStatusCondition(clusterCatalog.Status.Conditions, catalogd.TypeServing)
8154
if !assert.NotNil(ct, cond) {
8255
return
8356
}
8457
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
8558
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))
8670
}, time.Minute, time.Second)
8771

8872
t.Log("Checking that the ClusterExtension is installed")
@@ -122,37 +106,63 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
122106
}, time.Minute, time.Second)
123107
}
124108

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()
130111

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]
141118

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)
152126

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)
154133
}
155134

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+
156166
// getArtifactsOutput gets all the artifacts from the test run and saves them to the artifact path.
157167
// Currently it saves:
158168
// - clusterextensions

0 commit comments

Comments
 (0)