@@ -48,7 +48,7 @@ import (
4848 "sigs.k8s.io/controller-runtime/pkg/predicate"
4949 "sigs.k8s.io/controller-runtime/pkg/reconcile"
5050
51- "github.com/fluxcd/cli-utils/pkg/kstatus/polling"
51+ "github.com/fluxcd/cli-utils/pkg/kstatus/polling/engine "
5252 "github.com/fluxcd/cli-utils/pkg/object"
5353 apiacl "github.com/fluxcd/pkg/apis/acl"
5454 eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
@@ -92,7 +92,7 @@ type KustomizationReconciler struct {
9292
9393 Mapper apimeta.RESTMapper
9494 APIReader client.Reader
95- PollingOpts polling. Options
95+ ClusterReader engine. ClusterReaderFactory
9696 ControllerName string
9797 statusManager string
9898 NoCrossNamespaceRefs bool
@@ -223,7 +223,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
223223 }
224224
225225 // Configure custom health checks.
226- pollingOpts , err := r . getPollerOptions (ctx , obj )
226+ statusReaders , err := cel . PollerWithCustomHealthChecks (ctx , obj . Spec . HealthCheckExprs )
227227 if err != nil {
228228 const msg = "Reconciliation failed terminally due to configuration error"
229229 errMsg := fmt .Sprintf ("%s: %v" , msg , err )
@@ -280,7 +280,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
280280 }
281281
282282 // Reconcile the latest revision.
283- reconcileErr := r .reconcile (ctx , obj , artifactSource , patcher , pollingOpts )
283+ reconcileErr := r .reconcile (ctx , obj , artifactSource , patcher , statusReaders )
284284
285285 // Requeue at the specified retry interval if the artifact tarball is not found.
286286 if errors .Is (reconcileErr , fetch .ErrFileNotFound ) {
@@ -311,7 +311,7 @@ func (r *KustomizationReconciler) reconcile(
311311 obj * kustomizev1.Kustomization ,
312312 src sourcev1.Source ,
313313 patcher * patch.SerialPatcher ,
314- pollingOpts polling. Options ) error {
314+ statusReaders [] func (apimeta. RESTMapper ) engine. StatusReader ) error {
315315 log := ctrl .LoggerFrom (ctx )
316316
317317 // Update status with the reconciliation progress.
@@ -378,15 +378,20 @@ func (r *KustomizationReconciler) reconcile(
378378 }
379379
380380 // Configure the Kubernetes client for impersonation.
381- impersonation := runtimeClient .NewImpersonator (
382- r .Client ,
383- pollingOpts ,
384- obj .Spec .KubeConfig ,
385- r .KubeConfigOpts ,
386- r .DefaultServiceAccount ,
387- obj .Spec .ServiceAccountName ,
388- obj .GetNamespace (),
389- )
381+ var impersonatorOpts []runtimeClient.ImpersonatorOption
382+ if r .DefaultServiceAccount != "" || obj .Spec .ServiceAccountName != "" {
383+ impersonatorOpts = append (impersonatorOpts ,
384+ runtimeClient .WithServiceAccount (r .DefaultServiceAccount , obj .Spec .ServiceAccountName , obj .GetNamespace ()))
385+ }
386+ if obj .Spec .KubeConfig != nil {
387+ impersonatorOpts = append (impersonatorOpts ,
388+ runtimeClient .WithKubeConfig (obj .Spec .KubeConfig , r .KubeConfigOpts , obj .GetNamespace ()))
389+ }
390+ if r .ClusterReader != nil || len (statusReaders ) > 0 {
391+ impersonatorOpts = append (impersonatorOpts ,
392+ runtimeClient .WithPolling (r .ClusterReader , statusReaders ... ))
393+ }
394+ impersonation := runtimeClient .NewImpersonator (r .Client , impersonatorOpts ... )
390395
391396 // Create the Kubernetes client that runs under impersonation.
392397 kubeClient , statusPoller , err := impersonation .GetClient (ctx )
@@ -1007,15 +1012,19 @@ func (r *KustomizationReconciler) finalize(ctx context.Context,
10071012 obj .Status .Inventory .Entries != nil {
10081013 objects , _ := inventory .List (obj .Status .Inventory )
10091014
1010- impersonation := runtimeClient .NewImpersonator (
1011- r .Client ,
1012- r .PollingOpts ,
1013- obj .Spec .KubeConfig ,
1014- r .KubeConfigOpts ,
1015- r .DefaultServiceAccount ,
1016- obj .Spec .ServiceAccountName ,
1017- obj .GetNamespace (),
1018- )
1015+ var impersonatorOpts []runtimeClient.ImpersonatorOption
1016+ if r .DefaultServiceAccount != "" || obj .Spec .ServiceAccountName != "" {
1017+ impersonatorOpts = append (impersonatorOpts ,
1018+ runtimeClient .WithServiceAccount (r .DefaultServiceAccount , obj .Spec .ServiceAccountName , obj .GetNamespace ()))
1019+ }
1020+ if obj .Spec .KubeConfig != nil {
1021+ impersonatorOpts = append (impersonatorOpts ,
1022+ runtimeClient .WithKubeConfig (obj .Spec .KubeConfig , r .KubeConfigOpts , obj .GetNamespace ()))
1023+ }
1024+ if r .ClusterReader != nil {
1025+ impersonatorOpts = append (impersonatorOpts , runtimeClient .WithPolling (r .ClusterReader ))
1026+ }
1027+ impersonation := runtimeClient .NewImpersonator (r .Client , impersonatorOpts ... )
10191028 if impersonation .CanImpersonate (ctx ) {
10201029 kubeClient , _ , err := impersonation .GetClient (ctx )
10211030 if err != nil {
@@ -1156,21 +1165,3 @@ func getOriginRevision(src sourcev1.Source) string {
11561165 }
11571166 return a .Metadata [OCIArtifactOriginRevisionAnnotation ]
11581167}
1159-
1160- // getPollerOptions returns the status poller options
1161- // based on the healthcheck expressions defined in the Kustomization
1162- // object spec.
1163- func (r * KustomizationReconciler ) getPollerOptions (ctx context.Context ,
1164- obj * kustomizev1.Kustomization ) (polling.Options , error ) {
1165- opts := r .PollingOpts
1166-
1167- if hc := obj .Spec .HealthCheckExprs ; len (hc ) > 0 {
1168- var err error
1169- opts , err = cel .PollerWithCustomHealthChecks (ctx , opts , hc , r .Mapper )
1170- if err != nil {
1171- return polling.Options {}, err
1172- }
1173- }
1174-
1175- return opts , nil
1176- }
0 commit comments