Skip to content

Commit 65cea87

Browse files
committed
fix: nixidy apply CRDs with server-side apply and no pruning
Large CRDs exceed the client-side apply annotation size limit, and server-side apply is incompatible with label-based pruning. Apply CRDs with --server-side --force-conflicts and drop --prune for the crds class only while namespaces and manifests keep their existing prune behavior. Fixes #83
1 parent deb28dc commit 65cea87

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

modules/build.nix

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,22 @@ let
136136
if f.rules == [ ] then labeled else "${labeled} | ${chainOf f.path f.resource f.rules}";
137137

138138
applyClass =
139-
class: pruneAllowlist:
139+
class:
140+
{
141+
pruneAllowlist ? null,
142+
prune ? true,
143+
serverSide ? false,
144+
forceConflicts ? false,
145+
}:
140146
let
141147
files = lib.filter (f: f.class == class) applyFiles;
142148
allowlistFlag = lib.optionalString (
143149
pruneAllowlist != null
144150
) ''--prune-allowlist "${pruneAllowlist}"'';
151+
pruneFlags = lib.optionalString prune ''--prune --selector "${labelPrefix}/${class}=${env}" ${allowlistFlag}'';
152+
serverSideFlags = lib.optionalString serverSide (
153+
"--server-side" + lib.optionalString forceConflicts " --force-conflicts"
154+
);
145155
stream =
146156
if files == [ ] then
147157
"printf -- '---\\n'"
@@ -153,7 +163,7 @@ let
153163
{
154164
${stream}
155165
} | ${pkgs.kubectl}/bin/kubectl apply -f - \
156-
--prune --selector "${labelPrefix}/${class}=${env}" ${allowlistFlag}
166+
${pruneFlags} ${serverSideFlags}
157167
'';
158168

159169
# The generated `apply` script body (consumes environmentPackage, runs
@@ -166,9 +176,13 @@ let
166176
167177
${applyPostProcessNotice}
168178
169-
${applyClass "crds" "apiextensions.k8s.io/v1/CustomResourceDefinition"}
170-
${applyClass "namespaces" "core/v1/Namespace"}
171-
${applyClass "manifests" null}
179+
${applyClass "crds" {
180+
serverSide = true;
181+
forceConflicts = true;
182+
prune = false;
183+
}}
184+
${applyClass "namespaces" { pruneAllowlist = "core/v1/Namespace"; }}
185+
${applyClass "manifests" { }}
172186
'';
173187

174188
# Per-app post-process entries: one { path; resource; rules; } per

tests/object-transforms-apply-parity.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ in
105105
lib.hasInfix "set -eo pipefail" s
106106
&& lib.hasInfix "kubectl apply -f -" s
107107
&& lib.hasInfix ''--prune --selector "apps.nixidy.dev/manifests='' s
108+
&& lib.hasInfix "--server-side --force-conflicts" s
109+
&& !(lib.hasInfix ''--prune --selector "apps.nixidy.dev/crds='' s)
108110
&& lib.hasInfix "SopsSecret-x-y.yaml" s
109111
&& !(lib.hasInfix "crds.yml" s)
110112
&& !(lib.hasInfix "namespaces.yml" s)

0 commit comments

Comments
 (0)