Skip to content

Commit 1bf94ae

Browse files
authored
Merge pull request #1403 from fluxcd/backport-1401-to-release/v1.5.x
[release/v1.5.x] Update `fluxcd/pkg/runtime` to v0.58.0
2 parents 34837b9 + edb28cf commit 1bf94ae

File tree

7 files changed

+42
-240
lines changed

7 files changed

+42
-240
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/fluxcd/pkg/apis/meta v1.10.0
2525
github.com/fluxcd/pkg/http/fetch v0.15.0
2626
github.com/fluxcd/pkg/kustomize v1.16.0
27-
github.com/fluxcd/pkg/runtime v0.54.0
27+
github.com/fluxcd/pkg/runtime v0.58.0
2828
github.com/fluxcd/pkg/ssa v0.45.1
2929
github.com/fluxcd/pkg/tar v0.11.0
3030
github.com/fluxcd/pkg/testserver v0.10.0
@@ -40,7 +40,7 @@ require (
4040
k8s.io/apimachinery v0.32.2
4141
k8s.io/client-go v0.32.2
4242
k8s.io/utils v0.0.0-20241210054802-24370beab758
43-
sigs.k8s.io/controller-runtime v0.20.2
43+
sigs.k8s.io/controller-runtime v0.20.4
4444
sigs.k8s.io/kustomize/api v0.19.0
4545
sigs.k8s.io/yaml v1.4.0
4646
)

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ github.com/fluxcd/pkg/http/fetch v0.15.0 h1:AJ1JuE2asuK4QMfbHjxctFURke5FvZtyljjI
187187
github.com/fluxcd/pkg/http/fetch v0.15.0/go.mod h1:feTESfETKU14jq+e/Ce8QnMBTCh9O79bLMSMe5t55fQ=
188188
github.com/fluxcd/pkg/kustomize v1.16.0 h1:UBOeIvkrC6y4owYs7vZwG5PUVFeqnRoDFN9eaNhuNPI=
189189
github.com/fluxcd/pkg/kustomize v1.16.0/go.mod h1:6yQkAZaG+w3nXY30LbyWRYHimjRcLRwlYkrwG0ygMSI=
190-
github.com/fluxcd/pkg/runtime v0.54.0 h1:H7zSW8mTIZIkXaOdxzvi+oK0cH3jccyLoCBbXDPIGjg=
191-
github.com/fluxcd/pkg/runtime v0.54.0/go.mod h1:PC73Yn/AaBQXnd2YYq0cnQqF3RmQKoM265crrjFJnKI=
190+
github.com/fluxcd/pkg/runtime v0.58.0 h1:aic88k/PUqEOzq62nxav9XEyUicAbT+fiDcJ7dzWhqc=
191+
github.com/fluxcd/pkg/runtime v0.58.0/go.mod h1:ZRlEHAHhlP3gPl7/+kZ8i8nimZ+/mSnpURlexBJULnI=
192192
github.com/fluxcd/pkg/sourceignore v0.11.0 h1:xzpYmc5/t/Ck+/DkJSX3r+VbahDRIAn5kbv04fynWUo=
193193
github.com/fluxcd/pkg/sourceignore v0.11.0/go.mod h1:ri2FvlzX8ep2iszOK5gF/riYq2TNgpVvsfJ2QY0dLWI=
194194
github.com/fluxcd/pkg/ssa v0.45.1 h1:ISl84TJwRP/GuZXrKiR9Tf8JOnG5XFgtjcYoR4XQYf4=
@@ -580,8 +580,8 @@ k8s.io/kubectl v0.32.2 h1:TAkag6+XfSBgkqK9I7ZvwtF0WVtUAvK8ZqTt+5zi1Us=
580580
k8s.io/kubectl v0.32.2/go.mod h1:+h/NQFSPxiDZYX/WZaWw9fwYezGLISP0ud8nQKg+3g8=
581581
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
582582
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
583-
sigs.k8s.io/controller-runtime v0.20.2 h1:/439OZVxoEc02psi1h4QO3bHzTgu49bb347Xp4gW1pc=
584-
sigs.k8s.io/controller-runtime v0.20.2/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
583+
sigs.k8s.io/controller-runtime v0.20.4 h1:X3c+Odnxz+iPTRobG4tp092+CvBU9UK0t/bRf+n0DGU=
584+
sigs.k8s.io/controller-runtime v0.20.4/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
585585
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
586586
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
587587
sigs.k8s.io/kustomize/api v0.19.0 h1:F+2HB2mU1MSiR9Hp1NEgoU2q9ItNOaBJl0I4Dlus5SQ=

internal/controller/kustomization_configuration_error_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ data: {}
119119
for _, cond := range []string{meta.ReadyCondition, meta.StalledCondition} {
120120
g.Expect(conditions.GetReason(resultK, cond)).To(Equal(meta.InvalidCELExpressionReason))
121121
g.Expect(conditions.GetMessage(resultK, cond)).To(ContainSubstring(
122-
"failed to create custom status reader for healthchecks[0]: failed to parse the expression InProgress: failed to parse the CEL expression 'foo.': ERROR: <input>:1:5: Syntax error: no viable alternative at input '.'"))
122+
"failed to create custom status evaluator for healthchecks[0]: failed to parse the expression InProgress: failed to parse the CEL expression 'foo.': ERROR: <input>:1:5: Syntax error: no viable alternative at input '.'"))
123123
}
124124
}

internal/controller/kustomization_controller.go

+32-41
Original file line numberDiff line numberDiff line change
@@ -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-
}

internal/statusreaders/job.go

-118
This file was deleted.

internal/statusreaders/job_test.go

-65
This file was deleted.

main.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
ctrlcfg "sigs.k8s.io/controller-runtime/pkg/config"
3535
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3636

37-
"github.com/fluxcd/cli-utils/pkg/kstatus/polling"
3837
"github.com/fluxcd/cli-utils/pkg/kstatus/polling/clusterreader"
3938
"github.com/fluxcd/cli-utils/pkg/kstatus/polling/engine"
4039
"github.com/fluxcd/pkg/runtime/acl"
@@ -54,7 +53,6 @@ import (
5453
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
5554
"github.com/fluxcd/kustomize-controller/internal/controller"
5655
"github.com/fluxcd/kustomize-controller/internal/features"
57-
"github.com/fluxcd/kustomize-controller/internal/statusreaders"
5856
// +kubebuilder:scaffold:imports
5957
)
6058

@@ -220,13 +218,9 @@ func main() {
220218
os.Exit(1)
221219
}
222220

223-
jobStatusReader := statusreaders.NewCustomJobStatusReader(restMapper)
224-
pollingOpts := polling.Options{
225-
CustomStatusReaders: []engine.StatusReader{jobStatusReader},
226-
}
227-
221+
var clusterReader engine.ClusterReaderFactory
228222
if ok, _ := features.Enabled(features.DisableStatusPollerCache); ok {
229-
pollingOpts.ClusterReaderFactory = engine.ClusterReaderFactoryFunc(clusterreader.NewDirectClusterReader)
223+
clusterReader = engine.ClusterReaderFactoryFunc(clusterreader.NewDirectClusterReader)
230224
}
231225

232226
failFast := true
@@ -259,7 +253,7 @@ func main() {
259253
FailFast: failFast,
260254
ConcurrentSSA: concurrentSSA,
261255
KubeConfigOpts: kubeConfigOpts,
262-
PollingOpts: pollingOpts,
256+
ClusterReader: clusterReader,
263257
DisallowedFieldManagers: disallowedFieldManagers,
264258
StrictSubstitutions: strictSubstitutions,
265259
GroupChangeLog: groupChangeLog,

0 commit comments

Comments
 (0)