-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Server-side reconciliation for the v1beta2 API #426
Conversation
const ( | ||
KustomizationController = "kustomize-controller" | ||
KustomizationKind = "Kustomization" | ||
KustomizationFinalizer = "finalizers.fluxcd.io" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have had a discussion about this in the past, but I think it would be wise if we would make the finalizers domain specific. Reason for this is that the pattern of using various finalizers to control the garbage collection process of an object if multiple reconcilers are dealing with an object has become more common.
I think your objection in the past was that removing "all Flux reconcilers" in cases where they get stuck would become more difficult, but if we would nest all under a sub(domain)name, you could still loop over all that match that suffix. E.g. applier.finalizers.fluxcd.io
, source.finalizers.fluxcd.io
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change this now, wouldn't result in orphan resources after a Flux upgrade? I would introduce this change into a followup PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up PR (e.g. bundled with the other refactoring efforts) is fine with me, just wanted to have it noted given it showed up again :-)
8791fc7
to
6012183
Compare
Tested this PR on kubernetes version
This is likely due to k/k#91748 |
207005d
to
c5b3161
Compare
Is that field ignored or removed, and if the latter, does this mean a v1beta1 resource won't validate as v1beta2? |
I haven't bumped the API version in the e2e tests to prove that the v1beta1 CRs work as expected. What happens is that the Kubernetes API drops all unknown fields before validating the CR, so validation works since |
In the linked issue, it's explained that waiting on everything wouldn't work because some resource types are incompatible with kstatus (and this is the motivation for suggesting an allow-list or patterns). The change quoted above would make the controller wait on everything -- so is it the case that
|
@squaremo all Kubernetes builtin kinds are compatible with kstatus. As for custom resources, if the those have no status, or no ready condition in status, or no observed generation in status, then kstatus instead of crashing will report those resources as ready. |
db2b536
to
6b0be25
Compare
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
In suite test, the context created by SetupSignalHandler() watches for shutdown signal to cancel the context. This makes it possible to stop the controllers by sending a kill signal that cancels the context. This change allows controller context cancellation by creating another context from SetupSignalHandler() context with a CancelFunc that's called at the end of the test, instead of sending a kill signal. Signed-off-by: Sunny <darkowlzz@protonmail.com>
envtest: Add cancellable context to stop controllers
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the PR seems to be immense in LOC, most of the changes turned out to actually be tests.
All looks sensible to me @stefanprodan, nice work 🥇💯
testenv now supports provisioning users. Replace envtest with testenv. Also, reorder the cleanup to stop the test environment before stopping the file server to avoid anything in the cluster trying to connect to the file server after it's stopped. Signed-off-by: Sunny <darkowlzz@protonmail.com>
Replace envtest with testenv
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
Fixes for Flux breaking changes fluxcd/kustomize-controller#426
Why can't we have the option to disable the dry-run behavior? The implicit behavior fails for me when deploying a
It fails because the service account mentioned is only created during the actual reconciliation. |
@dsogari Please take your inquiry to a new issue, or https://github.com/fluxcd/flux2/discussions It is not likely to get positive attention here (necro-bumped a PR that is several months old), and there is not enough information in your post to help you, nor this is not the forum. |
This PR introduces a new reconciler based on Kubernetes server-side apply and graduates the API to v1beta2. Part of fluxcd/flux2#1889.
💡 Motivation
flux diff -k
command TBA).⏳ Background
When we started Flux v2, we've set a goal to stop relying on 3rd party binaries for core features. While we've successfully replaced the Git CLI shell execs with Go libraries (go-git, git2go) and C libraries (libgit2, libssh2), the kustomize CLI with Go libraries (kustomize/api, kustomize/kyaml), we're still depending on the kubectl CLI for the 3-way-merge apply feature. With Kubernetes server-side apply being promoted to GA, we can finally get rid of kubectl and drive the reconciliation using exclusively the controller-runtime Go client.
💥 Breaking changes
metadata.namespace
, defaulting to thedefault
namespace is no longer supported.Kind/Namespace/Name
format instead ofKind/Name
e.g.:v1.16
>= 1.16.11
v1.17
>= 1.17.7
v1.18
>= 1.18.4
v1.19
and later>= 1.19.0
All the versions above fix a regression in the managed fields and field type.
API changes
The
kustomize.toolkit.fluxcd.io/v1beta2
API is backwards compatible withv1beta1
.Additions and deprecations:
.spec.validation
deprecated (server-side validation is implicit).spec.patchesStrategicMerge
deprecated in favour of.spec.patches
.spec.patchesJson6902
deprecated in favour of.spec.patches
.status.snapshot
replaced by.status.inventory
.spec.wait
added (when enabled the controller will wait for all the reconciled resources to become ready)Reconciler changes
The server-side reconciler comes with the following behavioural changes:
.status.inventory
).Fixes: Cope when syncing a CRD and resources using the CRD flux2#1425
Fixes Detect changes/drift through a filtered diff of the apply/prune #352
Ref Dry-run support #213
Fixes When webhooks block kubectl apply and the command times-out, flux should log it as a timeout instead of an empty error #311
Fixes Kustomization: garbage collection website#498
Ref Garbage Collection deleting Endpoint resources created by Service resource #415
Fixes Kustomize applies and notifies when no changes occur #413
Fixes The log shows that the resource is configured, but in fact it is not so #403
Fixes Notifications - information content and filtering of info alerts flux2#710
Fixes Slack notification is misleading flux2#626
Supersedes Detect changes/drift through a filtered diff of the apply #379
Fixes Writing an invalid health assessment seems to break kustomize controller #405
Fixes Incorrect state in health check event #191
.spec.wait
istrue
, the controller runs the health assessment for all resources ignoring the ones inspec.healthChecks
.Fixes Health assessment for all resources of a given kind. #197
Ref kustomize-controller: ability to automatically health check all resources flux2#324
Fixes Reconciler error - Unable to prune for finalizer - failed to build kube client for Kustomization: ServiceAccount not found flux2#997
Fixes kustomization.yaml with no resources fails #391
Fixes Garbage collection step is skipped if there are no manifests in the repo #187
Fixes Notification controller secrets leakage on patch operation flux2#1887
Ref Breaking changes in Flux due to Kustomize v4 flux2#1522
Testing
The SSA reconciler and its controller are tested using Go stdlib, gomega and controller-runtime envtest:
Due to the controller-runtime envtest limitations (no kube-controller-manager), Kubernetes Kind e2e tests where added to the GitHub Actions workflow to cover features such as waiting for deployments rollout and CRDs+CRs staged apply.
Feedback
Please comment on this PR and let us know your thoughts about this.
If you want to try out the v1beta2 API on your own test cluster:
kubectl apply -k https://github.com/fluxcd/kustomize-controller/config/crd?ref=v1beta2
kubectl -n flux-system set image deployment/kustomize-controller \ manager=ghcr.io/fluxcd/kustomize-controller:v1beta2-50c71354
What's next?
Move the SSA resource manager tofluxcd/pkg/ssa
Use the SSA manager in Flux CLI to replace kubectl shell execs forflux bootstrap
andflux install
Bump the minimum Kubernetes version to 1.18.8 influx check --pre