Skip to content

Commit

Permalink
mitigate upgrade-e2e flakiness
Browse files Browse the repository at this point in the history
Signed-off-by: Per Goncalves da Silva <[email protected]>
  • Loading branch information
Per Goncalves da Silva committed Jan 16, 2025
1 parent b26fb46 commit fb6f8b2
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions test/upgrade-e2e/post_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,13 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
ctx := context.Background()
defer utils.CollectTestArtifacts(t, artifactName, c, cfg)

managerLabelSelector := labels.Set{"control-plane": "operator-controller-controller-manager"}
// wait for catalogd deployment to finish
t.Log("Wait for catalogd deployment to be ready")
catalogdManagerPod := waitForDeployment(t, ctx, "catalogd-controller-manager")

t.Log("Checking that the controller-manager deployment is updated")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
var managerDeployments appsv1.DeploymentList
assert.NoError(ct, c.List(ctx, &managerDeployments, client.MatchingLabelsSelector{Selector: managerLabelSelector.AsSelector()}))
assert.Len(ct, managerDeployments.Items, 1)
managerDeployment := managerDeployments.Items[0]

assert.True(ct,
managerDeployment.Status.UpdatedReplicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.Replicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.AvailableReplicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.ReadyReplicas == *managerDeployment.Spec.Replicas,
)
}, time.Minute, time.Second)

var managerPods corev1.PodList
t.Log("Waiting for only one controller-manager Pod to remain")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
assert.NoError(ct, c.List(ctx, &managerPods, client.MatchingLabelsSelector{Selector: managerLabelSelector.AsSelector()}))
assert.Len(ct, managerPods.Items, 1)
}, time.Minute, time.Second)
// wait for operator-controller deployment to finish
t.Log("Wait for operator-controller deployment to be ready")
managerPod := waitForDeployment(t, ctx, "operator-controller-controller-manager")

t.Log("Reading logs to make sure that ClusterExtension was reconciled by operator-controller before we update it")
// Make sure that after we upgrade OLM itself we can still reconcile old objects without any changes
Expand All @@ -64,28 +48,42 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
"reconcile ending",
fmt.Sprintf(`ClusterExtension=%q`, testClusterExtensionName),
}
found, err := watchPodLogsForSubstring(logCtx, &managerPods.Items[0], "manager", substrings...)
found, err := watchPodLogsForSubstring(logCtx, managerPod, "manager", substrings...)
require.NoError(t, err)
require.True(t, found)

t.Log("Checking that the ClusterCatalog is serving")
t.Log("Checking that the ClusterCatalog is unpacked")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
var clusterCatalog catalogd.ClusterCatalog
assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: testClusterCatalogName}, &clusterCatalog))

// check serving condition
cond := apimeta.FindStatusCondition(clusterCatalog.Status.Conditions, catalogd.TypeServing)
if !assert.NotNil(ct, cond) {
if assert.Nil(ct, cond) {
return
}
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
assert.Equal(ct, catalogd.ReasonAvailable, cond.Reason)

// mitigation for upgrade-e2e flakiness caused by the following bug
// https://github.com/operator-framework/operator-controller/issues/1626
// wait until the unpack time > than the catalogd controller pod creation time
cond = apimeta.FindStatusCondition(clusterCatalog.Status.Conditions, catalogd.TypeProgressing)
if assert.Nil(ct, cond) {
return
}
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
assert.Equal(ct, catalogd.ReasonSucceeded, cond.Reason)

assert.True(ct, clusterCatalog.Status.LastUnpacked.After(catalogdManagerPod.CreationTimestamp.Time))
}, time.Minute, time.Second)

t.Log("Checking that the ClusterExtension is installed")
var clusterExtension ocv1.ClusterExtension
require.EventuallyWithT(t, func(ct *assert.CollectT) {
assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: testClusterExtensionName}, &clusterExtension))
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeInstalled)
if !assert.NotNil(ct, cond) {
if assert.Nil(ct, cond) {
return
}
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
Expand All @@ -107,7 +105,7 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
require.EventuallyWithT(t, func(ct *assert.CollectT) {
assert.NoError(ct, c.Get(ctx, types.NamespacedName{Name: testClusterExtensionName}, &clusterExtension))
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeInstalled)
if !assert.NotNil(ct, cond) {
if assert.Nil(ct, cond) {
return
}
assert.Equal(ct, ocv1.ReasonSucceeded, cond.Reason)
Expand All @@ -117,6 +115,33 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
}, time.Minute, time.Second)
}

func waitForDeployment(t *testing.T, ctx context.Context, controlPlaneLabel string) *corev1.Pod {
deploymentLabelSelector := labels.Set{"control-plane": controlPlaneLabel}.AsSelector()

t.Log("Checking that the deployment is updated")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
var managerDeployments appsv1.DeploymentList
assert.NoError(ct, c.List(ctx, &managerDeployments, client.MatchingLabelsSelector{Selector: deploymentLabelSelector}))
assert.Len(ct, managerDeployments.Items, 1)
managerDeployment := managerDeployments.Items[0]

assert.True(ct,
managerDeployment.Status.UpdatedReplicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.Replicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.AvailableReplicas == *managerDeployment.Spec.Replicas &&
managerDeployment.Status.ReadyReplicas == *managerDeployment.Spec.Replicas,
)
}, time.Minute, time.Second)

var managerPods corev1.PodList
t.Log("Waiting for only one Pod to remain")
require.EventuallyWithT(t, func(ct *assert.CollectT) {
assert.NoError(ct, c.List(ctx, &managerPods, client.MatchingLabelsSelector{Selector: deploymentLabelSelector}))
assert.Len(ct, managerPods.Items, 1)
}, time.Minute, time.Second)
return &managerPods.Items[0]
}

func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container string, substrings ...string) (bool, error) {
podLogOpts := corev1.PodLogOptions{
Follow: true,
Expand Down

0 comments on commit fb6f8b2

Please sign in to comment.