From cac7550537015adeba670ccecff5d6607b3f35b0 Mon Sep 17 00:00:00 2001 From: Dheeraj Date: Mon, 20 Jan 2025 14:19:06 +0530 Subject: [PATCH] fix(STONEINTG-1087): longer wait for App * There are some case where the App and ITS are created almost at the same time. This causes problem when the App is not found while the controllers reconcile ITS. * To fix this, we increased the retry time from 10 ms to 10 seconds. * This should give enough time to fetch the App. * And if we're still unable to find App, we stop reconciling, since there's no point in reconciling an ITS without any parent. Signed-off-by: Dheeraj --- .../scenario/scenario_controller.go | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/internal/controller/scenario/scenario_controller.go b/internal/controller/scenario/scenario_controller.go index 76ddacd2e..ea0193f3d 100644 --- a/internal/controller/scenario/scenario_controller.go +++ b/internal/controller/scenario/scenario_controller.go @@ -18,7 +18,9 @@ package scenario import ( "context" + "time" + h "github.com/konflux-ci/integration-service/helpers" "github.com/konflux-ci/integration-service/loader" "github.com/go-logr/logr" @@ -29,6 +31,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/retry" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -75,15 +78,31 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu } var application *applicationapiv1alpha1.Application - err = retry.OnError(retry.DefaultRetry, func(_ error) bool { return true }, func() error { + var CustomRetry = wait.Backoff{ + Steps: 5, + Duration: 10 * time.Second, // Default was 10 milliseconds + Factor: 1.0, + Jitter: 0.1, + } + err = retry.OnError(CustomRetry, func(_ error) bool { return true }, func() error { application, err = r.getApplicationFromScenario(ctx, scenario) if err != nil { - logger.Info("Failed to get Application from the IntegrationTestScenario, try again", "error:", err) + logger.Info("Failed to get Application from the IntegrationTestScenario, trying again", "error:", err) } return err }) if err != nil { - logger.Error(err, "Failed to get Application from the IntegrationTestScenario after retry", "application", scenario.Spec.Application) + errString := "Failed to get Application from the IntegrationTestScenario even after retrying" + logger.Error(err, errString, "application", scenario.Spec.Application) + patch := client.MergeFrom(scenario.DeepCopy()) + h.SetScenarioIntegrationStatusAsInvalid(scenario, errString) + err := r.Client.Status().Patch(ctx, scenario, patch) + if err != nil { + logger.Error(err, "Failed to update Scenario as Invalid") + return ctrl.Result{}, err + } + logger.Info("Marked the IntegrationTestScenario as Invalid, will stop processing it", "error:", err) + return ctrl.Result{}, nil } adapter := NewAdapter(ctx, application, scenario, logger, loader, r.Client)