@@ -48,7 +48,7 @@ import (
48
48
"sigs.k8s.io/controller-runtime/pkg/predicate"
49
49
"sigs.k8s.io/controller-runtime/pkg/reconcile"
50
50
51
- "github.com/fluxcd/cli-utils/pkg/kstatus/polling"
51
+ "github.com/fluxcd/cli-utils/pkg/kstatus/polling/engine "
52
52
"github.com/fluxcd/cli-utils/pkg/object"
53
53
apiacl "github.com/fluxcd/pkg/apis/acl"
54
54
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
@@ -92,7 +92,7 @@ type KustomizationReconciler struct {
92
92
93
93
Mapper apimeta.RESTMapper
94
94
APIReader client.Reader
95
- PollingOpts polling. Options
95
+ ClusterReader engine. ClusterReaderFactory
96
96
ControllerName string
97
97
statusManager string
98
98
NoCrossNamespaceRefs bool
@@ -223,7 +223,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
223
223
}
224
224
225
225
// Configure custom health checks.
226
- pollingOpts , err := r . getPollerOptions (ctx , obj )
226
+ statusReaders , err := cel . PollerWithCustomHealthChecks (ctx , obj . Spec . HealthCheckExprs )
227
227
if err != nil {
228
228
const msg = "Reconciliation failed terminally due to configuration error"
229
229
errMsg := fmt .Sprintf ("%s: %v" , msg , err )
@@ -280,7 +280,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
280
280
}
281
281
282
282
// Reconcile the latest revision.
283
- reconcileErr := r .reconcile (ctx , obj , artifactSource , patcher , pollingOpts )
283
+ reconcileErr := r .reconcile (ctx , obj , artifactSource , patcher , statusReaders )
284
284
285
285
// Requeue at the specified retry interval if the artifact tarball is not found.
286
286
if errors .Is (reconcileErr , fetch .ErrFileNotFound ) {
@@ -311,7 +311,7 @@ func (r *KustomizationReconciler) reconcile(
311
311
obj * kustomizev1.Kustomization ,
312
312
src sourcev1.Source ,
313
313
patcher * patch.SerialPatcher ,
314
- pollingOpts polling. Options ) error {
314
+ statusReaders [] func (apimeta. RESTMapper ) engine. StatusReader ) error {
315
315
log := ctrl .LoggerFrom (ctx )
316
316
317
317
// Update status with the reconciliation progress.
@@ -378,15 +378,20 @@ func (r *KustomizationReconciler) reconcile(
378
378
}
379
379
380
380
// 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 ... )
390
395
391
396
// Create the Kubernetes client that runs under impersonation.
392
397
kubeClient , statusPoller , err := impersonation .GetClient (ctx )
@@ -1007,15 +1012,19 @@ func (r *KustomizationReconciler) finalize(ctx context.Context,
1007
1012
obj .Status .Inventory .Entries != nil {
1008
1013
objects , _ := inventory .List (obj .Status .Inventory )
1009
1014
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 ... )
1019
1028
if impersonation .CanImpersonate (ctx ) {
1020
1029
kubeClient , _ , err := impersonation .GetClient (ctx )
1021
1030
if err != nil {
@@ -1156,21 +1165,3 @@ func getOriginRevision(src sourcev1.Source) string {
1156
1165
}
1157
1166
return a .Metadata [OCIArtifactOriginRevisionAnnotation ]
1158
1167
}
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