diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 28a3b76..126245e 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -44,6 +44,7 @@ func main() { enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("false").Envar("ENABLE_MANAGEMENT_POLICIES").Bool() maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("10").Int() pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("1m").Duration() + reconciliationTimeout = app.Flag("reconciliation-timeout", "The timeout duration for the reconciliation process. In case the deadline exceeds, necessary calls to report errors will still be made.").Default("1m").Duration() ) kingpin.MustParse(app.Parse(os.Args[1:])) @@ -91,6 +92,6 @@ func main() { kingpin.FatalIfError(err, "Cannot create controller manager") kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add argocd APIs to scheme") - kingpin.FatalIfError(controller.Setup(mgr, o), "Cannot setup argocd controllers") + kingpin.FatalIfError(controller.Setup(mgr, o, *reconciliationTimeout), "Cannot setup argocd controllers") kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager") } diff --git a/pkg/controller/applications/controller.go b/pkg/controller/applications/controller.go index e838d1d..f6f586a 100644 --- a/pkg/controller/applications/controller.go +++ b/pkg/controller/applications/controller.go @@ -18,6 +18,7 @@ package applications import ( "context" + "time" "github.com/argoproj/argo-cd/v2/pkg/apiclient" "github.com/argoproj/argo-cd/v2/pkg/apiclient/application" @@ -52,7 +53,7 @@ const ( ) // SetupApplication adds a controller that reconciles applications. -func SetupApplication(mgr ctrl.Manager, o xpcontroller.Options) error { +func SetupApplication(mgr ctrl.Manager, o xpcontroller.Options, reconciliationTimeout time.Duration) error { name := managed.ControllerName(v1alpha1.ApplicationKind) cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())} @@ -64,6 +65,7 @@ func SetupApplication(mgr ctrl.Manager, o xpcontroller.Options) error { managed.WithLogger(o.Logger.WithValues("controller", name)), managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))), managed.WithConnectionPublishers(cps...), + managed.WithTimeout(reconciliationTimeout), } if o.Features.Enabled(features.EnableBetaManagementPolicies) { diff --git a/pkg/controller/argocd.go b/pkg/controller/argocd.go index c689bc6..bd40524 100644 --- a/pkg/controller/argocd.go +++ b/pkg/controller/argocd.go @@ -19,6 +19,7 @@ package controller import ( xpcontroller "github.com/crossplane/crossplane-runtime/pkg/controller" ctrl "sigs.k8s.io/controller-runtime" + "time" "github.com/crossplane-contrib/provider-argocd/pkg/controller/applications" "github.com/crossplane-contrib/provider-argocd/pkg/controller/applicationsets" @@ -30,13 +31,17 @@ import ( // Setup creates all argocd API controllers with the supplied logger and adds // them to the supplied manager. -func Setup(mgr ctrl.Manager, o xpcontroller.Options) error { +func Setup(mgr ctrl.Manager, o xpcontroller.Options, reconciliationTimeout time.Duration) error { + setupApplicationWithTimeout := func(mgr ctrl.Manager, o xpcontroller.Options) error { + return applications.SetupApplication(mgr, o, reconciliationTimeout) + } + for _, setup := range []func(ctrl.Manager, xpcontroller.Options) error{ config.Setup, repositories.SetupRepository, projects.SetupProject, cluster.SetupCluster, - applications.SetupApplication, + setupApplicationWithTimeout, applicationsets.SetupApplicationSet, } { if err := setup(mgr, o); err != nil {