Skip to content

Commit

Permalink
upgrade test: wait until first reconcile completes after upgrade (ope…
Browse files Browse the repository at this point in the history
…rator-framework#1045)

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
  • Loading branch information
joelanford authored and Per Goncalves da Silva committed Aug 13, 2024
1 parent 585784a commit 1c7553d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ type Preflight interface {
// This has been taken from rukpak, and an issue was created before to discuss it: https://github.com/operator-framework/rukpak/issues/800.
func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
l := log.FromContext(ctx).WithName("operator-controller")
l.V(1).Info("starting")
defer l.V(1).Info("ending")
l.V(1).Info("reconcile starting")
defer l.V(1).Info("reconcile ending")

var existingExt = &ocv1alpha1.ClusterExtension{}
if err := r.Client.Get(ctx, req.NamespacedName, existingExt); err != nil {
Expand Down
17 changes: 13 additions & 4 deletions test/upgrade-e2e/post_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
// Make sure that after we upgrade OLM itself we can still reconcile old objects without any changes
logCtx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
substring := fmt.Sprintf(`"ClusterExtension": {"name":"%s"}`, testClusterExtensionName)
found, err := watchPodLogsForSubstring(logCtx, &managerPods.Items[0], "manager", substring)
substrings := []string{
"reconcile ending",
fmt.Sprintf(`"ClusterExtension": {"name":"%s"}`, testClusterExtensionName),
}
found, err := watchPodLogsForSubstring(logCtx, &managerPods.Items[0], "manager", substrings...)
require.NoError(t, err)
require.True(t, found)

Expand Down Expand Up @@ -109,7 +112,7 @@ func TestClusterExtensionAfterOLMUpgrade(t *testing.T) {
}, time.Minute, time.Second)
}

func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container, substring string) (bool, error) {
func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container string, substrings ...string) (bool, error) {
podLogOpts := corev1.PodLogOptions{
Follow: true,
Container: container,
Expand All @@ -126,7 +129,13 @@ func watchPodLogsForSubstring(ctx context.Context, pod *corev1.Pod, container, s
for scanner.Scan() {
line := scanner.Text()

if strings.Contains(line, substring) {
foundCount := 0
for _, substring := range substrings {
if strings.Contains(line, substring) {
foundCount++
}
}
if foundCount == len(substrings) {
return true, nil
}
}
Expand Down

0 comments on commit 1c7553d

Please sign in to comment.