Skip to content

Commit 0c46d3d

Browse files
committed
fix: Force apply the CRD in the CRD maintainer
This ensures the operator will be the sole manager of the CRD (and all its fields) going forward. This avoids running into conflicts when CRDs were previously deployed by helm or stackablectl.
1 parent 7cb637b commit 0c46d3d

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

crates/stackable-webhook/src/maintainer.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,28 @@ impl<'a> CustomResourceDefinitionMaintainer<'a> {
213213

214214
// Deploy the updated CRDs using a server-side apply.
215215
let patch = Patch::Apply(&crd);
216-
let patch_params = PatchParams::apply(field_manager);
216+
217+
// We force apply here, because we want to become the sole manager of the CRD. This
218+
// avoids any conflicts from previous deployments via helm or stackablectl which are
219+
// reported with the following error message:
220+
//
221+
// Apply failed with 2 conflicts: conflicts with "stackablectl" using apiextensions.k8s.io/v1:
222+
// - .spec.versions
223+
// - .spec.conversion.strategy: Conflict
224+
//
225+
// The official Kubernetes documentation provides three options on how to solve
226+
// these conflicts. Option 1 is used, which is described as follows:
227+
//
228+
// Overwrite value, become sole manager: If overwriting the value was intentional
229+
// (or if the applier is an automated process like a controller) the applier should
230+
// set the force query parameter to true [...], and make the request again. This
231+
// forces the operation to succeed, changes the value of the field, and removes the
232+
// field from all other managers' entries in managedFields.
233+
//
234+
// See https://kubernetes.io/docs/reference/using-api/server-side-apply/#conflicts
235+
let patch_params = PatchParams::apply(field_manager).force();
236+
237+
// Finally apply the patch
217238
crd_api
218239
.patch(&crd_name, &patch_params, &patch)
219240
.await

0 commit comments

Comments
 (0)