refactor: Extract apply and update_status steps - #772
Open
maltesander wants to merge 4 commits into
Open
Conversation
Makes KubernetesResources generic over a marker that records how far the resources have progressed through the reconciliation. The build step now returns KubernetesResources<Prepared>, meaning built but not yet applied.
Moves resource application out of the reconcile function into a dedicated controller/apply.rs. The Applier owns the ClusterResources handle, applies every resource kind in a defined order and deletes orphaned resources, returning KubernetesResources<Applied> so that later steps can rely on the resources having reached the API server. The ServiceAccount and RoleBinding are applied first because the Pods reference them at creation time, and the StatefulSets and Deployments last so that every ConfigMap and Secret they mount already exists (see commons-operator#111). The resource bundle is destructured without a rest pattern, so a resource kind added later fails to compile here rather than silently never being applied. The SECRET_KEY Secret handling (random creation plus the temporary 26.3 migration) moves along with it, since it is a client-side concern that has to happen before the resources mounting it are applied. The owner reference of the migrated Secret is now derived from the ValidatedCluster, which yields the same reference but is infallible.
Moves the cluster status computation out of the reconcile function into a dedicated controller/update_status.rs. The function takes the resources as KubernetesResources<Applied>, so the compiler enforces that the conditions are derived from what the API server returned rather than from what was merely built. The Node role contributes StatefulSet conditions and the Worker and Beat Celery roles contribute Deployment conditions, as before. With this the reconcile function is pure orchestration: dereference, validate, build, ensure secrets, apply, update status. Its doc comment now lists those steps and records which of them need a Kubernetes client.
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
controller/apply.rs). TheApplierowns theClusterResourceshandle, applies every resource kind in a defined order and deletes orphaned resources. The ServiceAccount and RoleBinding go first (the Pods reference them at creation time), the StatefulSets and Deployments last (so every ConfigMap and Secret they mount already exists, see StatefulSet restarter always restarts replica 0 immediately after initial rollout commons-operator#111).controller/update_status.rs).KubernetesResources. The build step returnsPrepared, the applier returnsApplied, andupdate_statusonly acceptsApplied, so the compiler proves that the cluster status is derived from the resources the API server returned rather than from the ones that were merely built. The applier destructures the bundle without a rest pattern, so a resource kind added later fails to compile instead of silently never being applied.Author
Reviewer
Acceptance
type/deprecationlabel & add to the deprecation scheduletype/experimentallabel & add to the experimental features tracker