Commit 6683898
committed
feat: migrate to Server-Side Apply (SSA) and enforce controller ownership
Fixes: #258
Migrate resource creation and updates from client-side POST/PUT to
Server-Side Apply (SSA) where appropriate, and strengthen ownership
semantics with controller references throughout.
This commit establishes ownership of various fields and CRD's, to prevent accidental overwrites or race conditions by other controllers
It doesn't migrate all patches to SSA, if we plan to migrate completely to SSA, there would be significant code rework, and honestly, its not necessary for now.
All resources created by the operator now use `controller: true` in
ownerReferences, enabling Kubernetes garbage collection:
- TEC owns: Deployments, Services, ConfigMaps, Jobs, ApprovedImages
- Machine owns: AttestationKey (transferred from TEC via merge patch once its approved automatically).
- AttestationKey owns: Secret (with controller: true + finalizer)
`generate_owner_reference` renamed to `generate_owner_controller_reference`
to reflect that all owner refs are now controller refs with
`blockOwnerDeletion: true`.
All controllers are owners, but not all owners have to be controllers. Kubernetes mandates only one controller.
Multiple owners are fine for Garbage Collection and delete cascades.
New `apply_resource!` macro replaces `create_or_info_if_exists!` for
idempotent resource creation via SSA (PATCH with Patch::Apply).
`update_reference_values`: uses full-data SSA patch on trustee-data
ConfigMap (includes all keys: kbs-config.toml, policy.rego,
reference-values.json) to prevent the field manager from implicitly
relinquishing keys not in a partial patch.
If a field manager (controller owning a field of a CRD) makes a SSA patch, all fields of that patch are considered owned, and any previously owned fields not part of the patch are released from its control.
`update_attestation_keys`: uses full-object SSA patch on the Deployment
(sends entire deployment.spec) to avoid stripping required fields like
spec.selector. Metadata fields (managedFields, resourceVersion, uid)
are excluded from the SSA body to prevent 400 errors.
`do_mount_secret`: kept as GET+mutate+replace (PUT) since it follows a
read-modify-write pattern on the same field manager. Migrating this is significant code rework.
Owner transfer in `approve_ak` uses Merge patch (not SSA) because SSA
would upsert into the ownerReferences array, leaving stale references of both TEC. In the end TEC and Machine would co-exist as controllers, which we don't want.
Merge patch replaces the entire ownerReferences field atomically.
Single field manager `trusted-cluster-operator` used consistently via
`FIELD_MANAGER` constant. register-server uses its own `register-server`
field manager for Machine creation (POST with fieldManager query param,
not SSA).
`update_status!` macro now requires explicit type and field manager
parameters, enabling force-apply on the status subresource where
multiple writers exist (e.g. ApprovedImage status).
- Duplicate volume entries: `do_mount_secret` now checks for existing
volumes before adding, preventing 422 errors on reconciler retry.
- Secret controller filtering: `update_attestation_keys` and
`secret_reconcile` now require `controller: true` on AttestationKey
owner refs, not just `kind == "AttestationKey"`.
- ConfigMap data loss: full-data SSA patch on trustee-data prevents
kbs-config.toml and policy.rego from being garbage-collected when
only reference-values.json is updated.
Added unit tests validating SSA body content, ownership, idempotency,
field manager usage, and filtering logic across trustee, reference
values, attestation key register, and register server modules.
Commit message co-authored-by: Cursor <cursoragent@cursor.com>1 parent 04e7986 commit 6683898
13 files changed
Lines changed: 928 additions & 187 deletions
File tree
- attestation-key-register/src
- compute-pcrs/src
- lib/src
- operator/src
- register-server/src
- test_utils/src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
| |||
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
107 | | - | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| |||
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
117 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
118 | 131 | | |
119 | 132 | | |
120 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
81 | 93 | | |
82 | 94 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
38 | 56 | | |
39 | | - | |
| 57 | + | |
40 | 58 | | |
41 | 59 | | |
42 | 60 | | |
| |||
108 | 126 | | |
109 | 127 | | |
110 | 128 | | |
111 | | - | |
112 | | - | |
| 129 | + | |
| 130 | + | |
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
0 commit comments