Skip to content

Commit 2ca7093

Browse files
committed
[RFC-0009] Add CEL custom healthchecks
Signed-off-by: Matheus Pimenta <[email protected]>
1 parent 5967686 commit 2ca7093

14 files changed

+268
-14
lines changed

api/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/fluxcd/kustomize-controller/api
33
go 1.23.0
44

55
require (
6-
github.com/fluxcd/pkg/apis/kustomize v1.8.0
6+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58
77
github.com/fluxcd/pkg/apis/meta v1.9.0
88
k8s.io/apiextensions-apiserver v0.32.0
99
k8s.io/apimachinery v0.32.0

api/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
55
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/fluxcd/pkg/apis/kustomize v1.8.0 h1:HH6YRa3SMS72KK4cUyb9m5sK/dZH+Eti1qhjWDCgwKg=
7-
github.com/fluxcd/pkg/apis/kustomize v1.8.0/go.mod h1:QCKIFj1ocdndaWSkrLs5JKvdGNYyTzQX1ZB3lYTwma0=
6+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58 h1:zhTfTbXKv+R+f1gwu2ekEu0b1Q5CjinCtj1prVEVbVo=
7+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58/go.mod h1:QCKIFj1ocdndaWSkrLs5JKvdGNYyTzQX1ZB3lYTwma0=
88
github.com/fluxcd/pkg/apis/meta v1.9.0 h1:wPgm7bWNJZ/ImS5GqikOxt362IgLPFBG73dZ27uWRiQ=
99
github.com/fluxcd/pkg/apis/meta v1.9.0/go.mod h1:pMea8eEZcsFSI7ngRnTHFtDZk2CEZGgtrueNgI6Iu70=
1010
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=

api/v1/kustomization_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ type KustomizationSpec struct {
179179
// Components specifies relative paths to specifications of other Components.
180180
// +optional
181181
Components []string `json:"components,omitempty"`
182+
183+
// HealthCheckExprs is a list of healthcheck expressions for evaluating the
184+
// health of custom resources using Common Expression Language (CEL).
185+
// +optional
186+
HealthCheckExprs []kustomize.CustomHealthCheck `json:"healthCheckExprs,omitempty"`
182187
}
183188

184189
// CommonMetadata defines the common labels and annotations.

api/v1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/kustomize.toolkit.fluxcd.io_kustomizations.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,41 @@ spec:
136136
Force instructs the controller to recreate resources
137137
when patching fails due to an immutable field change.
138138
type: boolean
139+
healthCheckExprs:
140+
description: |-
141+
HealthCheckExprs is a list of healthcheck expressions for evaluating the
142+
health of custom resources using Common Expression Language (CEL).
143+
items:
144+
description: CustomHealthCheck defines the health check for custom
145+
resources.
146+
properties:
147+
apiVersion:
148+
description: APIVersion of the custom resource under evaluation.
149+
type: string
150+
current:
151+
description: |-
152+
Current is the CEL expression that determines if the status
153+
of the custom resource has reached the desired state.
154+
type: string
155+
failed:
156+
description: |-
157+
Failed is the CEL expression that determines if the status
158+
of the custom resource has failed to reach the desired state.
159+
type: string
160+
inProgress:
161+
description: |-
162+
InProgress is the CEL expression that determines if the status
163+
of the custom resource has not yet reached the desired state.
164+
type: string
165+
kind:
166+
description: Kind of the custom resource under evaluation.
167+
type: string
168+
required:
169+
- apiVersion
170+
- current
171+
- kind
172+
type: object
173+
type: array
139174
healthChecks:
140175
description: A list of resources to be included in the health assessment.
141176
items:

docs/api/v1/kustomize.md

+30
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,21 @@ resources. When enabled, the HealthChecks are ignored. Defaults to false.</p>
395395
<p>Components specifies relative paths to specifications of other Components.</p>
396396
</td>
397397
</tr>
398+
<tr>
399+
<td>
400+
<code>healthCheckExprs</code><br>
401+
<em>
402+
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/kustomize#CustomHealthCheck">
403+
[]github.com/fluxcd/pkg/apis/kustomize.CustomHealthCheck
404+
</a>
405+
</em>
406+
</td>
407+
<td>
408+
<em>(Optional)</em>
409+
<p>HealthCheckExprs is a list of healthcheck expressions for evaluating the
410+
health of custom resources using Common Expression Language (CEL).</p>
411+
</td>
412+
</tr>
398413
</table>
399414
</td>
400415
</tr>
@@ -918,6 +933,21 @@ resources. When enabled, the HealthChecks are ignored. Defaults to false.</p>
918933
<p>Components specifies relative paths to specifications of other Components.</p>
919934
</td>
920935
</tr>
936+
<tr>
937+
<td>
938+
<code>healthCheckExprs</code><br>
939+
<em>
940+
<a href="https://godoc.org/github.com/fluxcd/pkg/apis/kustomize#CustomHealthCheck">
941+
[]github.com/fluxcd/pkg/apis/kustomize.CustomHealthCheck
942+
</a>
943+
</em>
944+
</td>
945+
<td>
946+
<em>(Optional)</em>
947+
<p>HealthCheckExprs is a list of healthcheck expressions for evaluating the
948+
health of custom resources using Common Expression Language (CEL).</p>
949+
</td>
950+
</tr>
921951
</tbody>
922952
</table>
923953
</div>

docs/spec/v1/kustomizations.md

+61
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,67 @@ reconciled resources as part of the Kustomization. If set to `true`,
351351
operation like building, applying, health checking, etc. performed during the
352352
reconciliation process.
353353

354+
### Health check expressions
355+
356+
`.spec.healthCheckExprs` can be used to define custom logic for performing
357+
health checks on custom resources. This is done through Common Expression
358+
Language (CEL) expressions. This field accepts a list of objects with the
359+
following fields:
360+
361+
- `apiVersion`: The API version of the custom resource. Required.
362+
- `kind`: The kind of the custom resource. Required.
363+
- `current`: A required CEL expression that returns `true` if the resource is ready.
364+
- `inProgress`: An optional CEL expression that returns `true` if the resource
365+
is still being reconciled.
366+
- `failed`: An optional CEL expression that returns `true` if the resource
367+
failed to reconcile.
368+
369+
The controller will evaluate the expressions in the following order:
370+
371+
1. `inProgress` if specified
372+
2. `failed` if specified
373+
3. `current`
374+
375+
The first expression that evaluates to `true` will determine the health
376+
status of the custom resource.
377+
378+
For example, to define a set of health check expressions for the `SealedSecret`
379+
custom resource:
380+
381+
```yaml
382+
apiVersion: kustomize.toolkit.fluxcd.io/v1
383+
kind: Kustomization
384+
metadata:
385+
name: sealed-secrets
386+
namespace: flux-system
387+
spec:
388+
interval: 5m
389+
path: ./path/to/sealed/secrets
390+
prune: true
391+
sourceRef:
392+
kind: GitRepository
393+
name: flux-system
394+
timeout: 1m
395+
wait: true # Tells the controller to wait for all resources to be ready by performing health checks.
396+
healthCheckExprs:
397+
- apiVersion: bitnami.com/v1alpha1
398+
kind: SealedSecret
399+
inProgress: has(status.observedGeneration) && status.observedGeneration != metadata.generation
400+
failed: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'False')
401+
current: status.conditions.filter(e, e.type == 'Synced').all(e, e.status == 'True')
402+
```
403+
404+
A common error is writing expressions that reference fields that do not
405+
exist in the custom resource. This will cause the controller to wait
406+
for the resource to be ready until the timeout is reached. To avoid this,
407+
make sure your CEL expressions are correct. The
408+
[CEL Playground](https://playcel.undistro.io/) is a useful resource for
409+
this task. The input passed to each expression is the custom resource
410+
object itself.
411+
412+
It's worth checking if [the library](/flux/cheatsheets/cel-healthchecks/)
413+
has expressions for the custom resources you are using.
414+
354415
### Dependencies
355416

356417
`.spec.dependsOn` is an optional list used to refer to other Kustomization

go.mod

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ require (
2020
github.com/fluxcd/kustomize-controller/api v1.4.0
2121
github.com/fluxcd/pkg/apis/acl v0.5.0
2222
github.com/fluxcd/pkg/apis/event v0.15.0
23-
github.com/fluxcd/pkg/apis/kustomize v1.8.0
23+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58
2424
github.com/fluxcd/pkg/apis/meta v1.9.0
2525
github.com/fluxcd/pkg/http/fetch v0.14.0
2626
github.com/fluxcd/pkg/kustomize v1.15.0
27-
github.com/fluxcd/pkg/runtime v0.52.0
27+
github.com/fluxcd/pkg/runtime v0.52.1-0.20250124073354-c595d8c1eb90
2828
github.com/fluxcd/pkg/ssa v0.43.0
2929
github.com/fluxcd/pkg/tar v0.10.0
3030
github.com/fluxcd/pkg/testserver v0.9.0
@@ -78,6 +78,7 @@ require (
7878
github.com/Microsoft/go-winio v0.6.2 // indirect
7979
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
8080
github.com/ProtonMail/go-crypto v1.1.3 // indirect
81+
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
8182
github.com/aws/aws-sdk-go-v2 v1.32.6 // indirect
8283
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
8384
github.com/aws/aws-sdk-go-v2/config v1.28.6 // indirect
@@ -141,6 +142,7 @@ require (
141142
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
142143
github.com/golang/protobuf v1.5.4 // indirect
143144
github.com/google/btree v1.1.2 // indirect
145+
github.com/google/cel-go v0.22.0 // indirect
144146
github.com/google/gnostic-models v0.6.8 // indirect
145147
github.com/google/go-cmp v0.6.0 // indirect
146148
github.com/google/gofuzz v1.2.0 // indirect
@@ -199,6 +201,7 @@ require (
199201
github.com/ryanuber/go-glob v1.0.0 // indirect
200202
github.com/sirupsen/logrus v1.9.3 // indirect
201203
github.com/spf13/cobra v1.8.1 // indirect
204+
github.com/stoewer/go-strcase v1.3.0 // indirect
202205
github.com/urfave/cli v1.22.16 // indirect
203206
github.com/x448/float16 v0.8.4 // indirect
204207
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect

go.sum

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV
6969
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
7070
github.com/ProtonMail/go-crypto v1.1.3 h1:nRBOetoydLeUb4nHajyO2bKqMLfWQ/ZPwkXqXxPxCFk=
7171
github.com/ProtonMail/go-crypto v1.1.3/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
72+
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
73+
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
7274
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
7375
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
7476
github.com/aws/aws-sdk-go-v2 v1.32.6 h1:7BokKRgRPuGmKkFMhEg/jSul+tB9VvXhcViILtfG8b4=
@@ -183,8 +185,8 @@ github.com/fluxcd/pkg/apis/acl v0.5.0 h1:+ykKezgerKUlZwSYFUy03lPMOIAyWlqvMNNLIWW
183185
github.com/fluxcd/pkg/apis/acl v0.5.0/go.mod h1:IVDZx3MAoDWjlLrJHMF9Z27huFuXAEQlnbWw0M6EcTs=
184186
github.com/fluxcd/pkg/apis/event v0.15.0 h1:k1suqIfVxnhEeKlGkvlHAbOYXjY8wRixT/OZcIuakqA=
185187
github.com/fluxcd/pkg/apis/event v0.15.0/go.mod h1:aRK2AONnjjSNW61B6Iy3SW4YHozACntnJeGm3fFqDqA=
186-
github.com/fluxcd/pkg/apis/kustomize v1.8.0 h1:HH6YRa3SMS72KK4cUyb9m5sK/dZH+Eti1qhjWDCgwKg=
187-
github.com/fluxcd/pkg/apis/kustomize v1.8.0/go.mod h1:QCKIFj1ocdndaWSkrLs5JKvdGNYyTzQX1ZB3lYTwma0=
188+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58 h1:zhTfTbXKv+R+f1gwu2ekEu0b1Q5CjinCtj1prVEVbVo=
189+
github.com/fluxcd/pkg/apis/kustomize v1.8.1-0.20250123112748-c55030369b58/go.mod h1:QCKIFj1ocdndaWSkrLs5JKvdGNYyTzQX1ZB3lYTwma0=
188190
github.com/fluxcd/pkg/apis/meta v1.9.0 h1:wPgm7bWNJZ/ImS5GqikOxt362IgLPFBG73dZ27uWRiQ=
189191
github.com/fluxcd/pkg/apis/meta v1.9.0/go.mod h1:pMea8eEZcsFSI7ngRnTHFtDZk2CEZGgtrueNgI6Iu70=
190192
github.com/fluxcd/pkg/envsubst v1.3.0 h1:84Ain+8EBvyzu6y0FsKRwNsvaSiKuqhTqeh/4yoGFFU=
@@ -193,8 +195,8 @@ github.com/fluxcd/pkg/http/fetch v0.14.0 h1:65iI38Vrl21v0YxT8IFCj/63I9/l43b7dPLa
193195
github.com/fluxcd/pkg/http/fetch v0.14.0/go.mod h1:/Ir27MZbgG11yN/npQwF32+oIETeJ+QdceoaxvvkLzQ=
194196
github.com/fluxcd/pkg/kustomize v1.15.0 h1:lII4FW9EJl0rI20dk+Glg5C2JZhP343FBov7HwW+SQo=
195197
github.com/fluxcd/pkg/kustomize v1.15.0/go.mod h1:e2SGi7cl28c9cnBVZ8YV8HAS4VBgUsiM6HMqv/AHJWQ=
196-
github.com/fluxcd/pkg/runtime v0.52.0 h1:bgYgXURy94MNbHzthJ8SRZJxuZB1X4atj/LLeR6AgDk=
197-
github.com/fluxcd/pkg/runtime v0.52.0/go.mod h1:66sowtjeLubCmwBTDC+2t41xgjs2eRlNzaWbPWN2nhk=
198+
github.com/fluxcd/pkg/runtime v0.52.1-0.20250124073354-c595d8c1eb90 h1:awrUaChnkZkBSkP3osz3oDB2mL7NiDg7knUvR83lVfk=
199+
github.com/fluxcd/pkg/runtime v0.52.1-0.20250124073354-c595d8c1eb90/go.mod h1:t67yJDmlO8PKVZ1AZsnUNUpL9Jguhnq2UBHKKbmM5oU=
198200
github.com/fluxcd/pkg/sourceignore v0.10.0 h1:z5Bhh0G990uLbwjKNj7SzYqbGkicpGcXxF/Z4ZSVB64=
199201
github.com/fluxcd/pkg/sourceignore v0.10.0/go.mod h1:d1d9hcFxf+grda6JL3k+mC09nVTtBb9kJVzQn6J77B0=
200202
github.com/fluxcd/pkg/ssa v0.43.0 h1:XmADD3C0erYZayKfGI0WTsMlW9TtS4bp5gy4Axo1dcA=
@@ -264,6 +266,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
264266
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
265267
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
266268
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
269+
github.com/google/cel-go v0.22.0 h1:b3FJZxpiv1vTMo2/5RDUqAHPxkT8mmMfJIrq1llbf7g=
270+
github.com/google/cel-go v0.22.0/go.mod h1:BuznPXXfQDpXKWQ9sPW3TzlAJN5zzFe+i9tIs0yC4s8=
267271
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
268272
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
269273
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -430,6 +434,8 @@ github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
430434
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
431435
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
432436
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
437+
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
438+
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
433439
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
434440
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
435441
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

internal/controller/kustomization_controller.go

+26-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/fluxcd/pkg/http/fetch"
5757
generator "github.com/fluxcd/pkg/kustomize"
5858
"github.com/fluxcd/pkg/runtime/acl"
59+
"github.com/fluxcd/pkg/runtime/cel"
5960
runtimeClient "github.com/fluxcd/pkg/runtime/client"
6061
"github.com/fluxcd/pkg/runtime/conditions"
6162
runtimeCtrl "github.com/fluxcd/pkg/runtime/controller"
@@ -89,6 +90,7 @@ type KustomizationReconciler struct {
8990
artifactFetchRetries int
9091
requeueDependency time.Duration
9192

93+
Mapper apimeta.RESTMapper
9294
APIReader client.Reader
9395
StatusPoller *polling.StatusPoller
9496
PollingOpts polling.Options
@@ -362,10 +364,11 @@ func (r *KustomizationReconciler) reconcile(
362364
}
363365

364366
// Configure the Kubernetes client for impersonation.
367+
statusPoller, pollingOpts := r.getPollerAndOptions(obj)
365368
impersonation := runtimeClient.NewImpersonator(
366369
r.Client,
367-
r.StatusPoller,
368-
r.PollingOpts,
370+
statusPoller,
371+
pollingOpts,
369372
obj.Spec.KubeConfig,
370373
r.KubeConfigOpts,
371374
r.DefaultServiceAccount,
@@ -475,7 +478,7 @@ func (r *KustomizationReconciler) reconcile(
475478
conditions.MarkTrue(obj,
476479
meta.ReadyCondition,
477480
meta.ReconciliationSucceededReason,
478-
fmt.Sprintf("Applied revision: %s", revision))
481+
"Applied revision: %s", revision)
479482

480483
return nil
481484
}
@@ -980,10 +983,11 @@ func (r *KustomizationReconciler) finalize(ctx context.Context,
980983
obj.Status.Inventory.Entries != nil {
981984
objects, _ := inventory.List(obj.Status.Inventory)
982985

986+
statusPoller, pollingOpts := r.getPollerAndOptions(obj)
983987
impersonation := runtimeClient.NewImpersonator(
984988
r.Client,
985-
r.StatusPoller,
986-
r.PollingOpts,
989+
statusPoller,
990+
pollingOpts,
987991
obj.Spec.KubeConfig,
988992
r.KubeConfigOpts,
989993
r.DefaultServiceAccount,
@@ -1130,3 +1134,20 @@ func getOriginRevision(src sourcev1.Source) string {
11301134
}
11311135
return a.Metadata[OCIArtifactOriginRevisionAnnotation]
11321136
}
1137+
1138+
// getPollerAndOptions returns the status poller and polling options
1139+
// based on the healthcheck expressions defined in the Kustomization
1140+
// object spec.
1141+
func (r *KustomizationReconciler) getPollerAndOptions(
1142+
obj *kustomizev1.Kustomization) (*polling.StatusPoller, polling.Options) {
1143+
1144+
poller := r.StatusPoller
1145+
opts := r.PollingOpts
1146+
1147+
if hc := obj.Spec.HealthCheckExprs; len(hc) > 0 {
1148+
opts = cel.PollerWithCustomHealthChecks(hc, r.Mapper, opts)
1149+
poller = polling.NewStatusPoller(r.Client, r.Mapper, opts)
1150+
}
1151+
1152+
return poller, opts
1153+
}

internal/controller/kustomization_fuzzer_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func Fuzz_Controllers(f *testing.F) {
125125
reconciler := &KustomizationReconciler{
126126
ControllerName: controllerName,
127127
Client: testEnv,
128+
Mapper: testEnv.GetRESTMapper(),
128129
}
129130
if err := (reconciler).SetupWithManager(ctx, testEnv, KustomizationReconcilerOptions{}); err != nil {
130131
panic(fmt.Sprintf("Failed to start GitRepositoryReconciler: %v", err))

0 commit comments

Comments
 (0)