Skip to content

Commit d420925

Browse files
committed
(flaky text fix): GC CSV with wrong namespace annotation
The test was modifying the `olm.operatornamespace` to an incorrect value, and checking to make sure that the CSV was garbage collected as a result. However, the olm-controller was copying a fresh copy back into the namespace, so whenever the test was able to get a yes reply to the question "is the CSV gone", in the brief window before it was copied back again, the test was passing. This commit fixes that by making sure that if find a CSV that we expected to be garbage collected, it passes if it determines that the CSV is a fresh copy, and not the one modified before. Signed-off-by: Anik Bhattacharjee <[email protected]>
1 parent e2ea879 commit d420925

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

test/e2e/operator_groups_e2e_test.go

+28-15
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,7 @@ var _ = Describe("Operator Group", func() {
17991799

18001800
// Versions of OLM at 0.14.1 and older had a bug that would place the wrong namespace annotation on copied CSVs,
18011801
// preventing them from being GCd. This ensures that any leftover CSVs in that state are properly cleared up.
1802-
// issue: https://github.com/operator-framework/operator-lifecycle-manager/issues/2644
1803-
It("[FLAKE] cleanup csvs with bad owner operator groups", func() {
1802+
It("cleanup csvs with bad namespace annotation", func() {
18041803

18051804
csvName := genName("another-csv-") // must be lowercase for DNS-1123 validation
18061805

@@ -2013,18 +2012,28 @@ var _ = Describe("Operator Group", func() {
20132012
return false, nil
20142013
})
20152014
require.NoError(GinkgoT(), err)
2016-
2017-
// Give copied CSV a bad operatorgroup annotation
2018-
updateCSV := func() error {
2019-
fetchedCSV, err := crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Get(context.TODO(), csvName, metav1.GetOptions{})
2020-
require.NoError(GinkgoT(), err)
2015+
GinkgoT().Log("Copied CSV showed up in other namespace, giving copied CSV a bad OpertorGroup annotation")
2016+
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
2017+
fetchedCSV, fetchErr := crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Get(context.TODO(), csvName, metav1.GetOptions{})
2018+
if fetchErr != nil {
2019+
return false, fetchErr
2020+
}
20212021
fetchedCSV.Annotations[v1.OperatorGroupNamespaceAnnotationKey] = fetchedCSV.GetNamespace()
2022-
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
2023-
return err
2024-
}
2025-
require.NoError(GinkgoT(), retry.RetryOnConflict(retry.DefaultBackoff, updateCSV))
2026-
2027-
// wait for CSV to be gc'd
2022+
_, updateErr := crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
2023+
if updateErr != nil {
2024+
return false, updateErr
2025+
}
2026+
updatedCSV, updatedfetchErr := crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Get(context.TODO(), csvName, metav1.GetOptions{})
2027+
if updatedfetchErr != nil {
2028+
return false, updatedfetchErr
2029+
}
2030+
if updatedCSV.Annotations[v1.OperatorGroupNamespaceAnnotationKey] == fetchedCSV.GetNamespace() {
2031+
return true, nil
2032+
}
2033+
return false, nil
2034+
})
2035+
require.NoError(GinkgoT(), err)
2036+
GinkgoT().Log("Done updating copied CSV with bad annotation OperatorGroup, waiting for CSV to be gc'd")
20282037
err = wait.Poll(pollInterval, 2*pollDuration, func() (bool, error) {
20292038
csv, fetchErr := crc.OperatorsV1alpha1().ClusterServiceVersions(otherNamespaceName).Get(context.TODO(), csvName, metav1.GetOptions{})
20302039
if fetchErr != nil {
@@ -2034,8 +2043,12 @@ var _ = Describe("Operator Group", func() {
20342043
GinkgoT().Logf("Error (in %v): %v", opGroupNamespace, fetchErr.Error())
20352044
return false, fetchErr
20362045
}
2037-
GinkgoT().Logf("%#v", csv.Annotations)
2038-
GinkgoT().Logf(csv.GetNamespace())
2046+
// The CSV with the wrong annotation could have been replaced with a new copied CSV by this time
2047+
// If we find a CSV in the namespace, and it contains the correct annotation, it means the CSV
2048+
// with the wrong annotation was GCed
2049+
if csv.Annotations[v1.OperatorGroupNamespaceAnnotationKey] != csv.GetNamespace() {
2050+
return true, nil
2051+
}
20392052
return false, nil
20402053
})
20412054
require.NoError(GinkgoT(), err)

0 commit comments

Comments
 (0)