@@ -184,26 +184,47 @@ let
184184 # pre-process the CRD with a crude python script to flatten it before running
185185 # the generator. See: crd2jsonschema.py
186186 #
187+ # Resolve a renamed argument: prefer the new name, fall back to the
188+ # deprecated `crds` alias (emitting a warning that points at the new name),
189+ # else the supplied default. `default` is only forced when neither is given,
190+ # so passing a `throw` makes the new argument effectively required.
191+ renamedArg =
192+ {
193+ fn ,
194+ old ? "crds" ,
195+ new ,
196+ newVal ,
197+ oldVal ,
198+ default ,
199+ } :
200+ if newVal != null then
201+ newVal
202+ else if oldVal != null then
203+ lib . warn "${ fn } : argument `${ old } ` is deprecated, use `${ new } ` instead" oldVal
204+ else
205+ default ;
206+
187207 # This Python parse is the one unavoidable IFD; both the file generator
188208 # (`fromCRD`) and the native module generator (`fromCRDModule`) share it.
189209 crdSchema =
190210 {
191211 name ,
192212 src ,
193- crds ,
213+ crdFiles ,
194214 namePrefix ? "" ,
195215 attrNameOverrides ? { } ,
196216 # Optional list of CRD `kind` names to generate. When empty (the
197- # default) every CustomResourceDefinition found in `crds ` is generated.
198- # Useful when `crds ` points at a multi-document stream (e.g. raw
199- # `helm template` output) containing more kinds than you want.
217+ # default) every CustomResourceDefinition found in `crdFiles ` is
218+ # generated. Useful when `crdFiles ` points at a multi-document stream
219+ # (e.g. raw `helm template` output) containing more kinds than you want.
200220 kindFilter ? [ ] ,
201221 } :
202222 let
203223 options = pkgs . writeText "${ name } -crd2jsonschema-options.json" (
204224 builtins . toJSON {
225+ # crd2jsonschema.py reads this under the JSON key `crds`.
226+ crds = crdFiles ;
205227 inherit
206- crds
207228 namePrefix
208229 attrNameOverrides
209230 kindFilter
236257 {
237258 name ,
238259 src ,
239- crds ,
260+ # List of CRD YAML files (relative to `src`) to generate types from.
261+ crdFiles ? null ,
262+ # Deprecated alias for `crdFiles`.
263+ crds ? null ,
240264 namePrefix ? "" ,
241265 attrNameOverrides ? { } ,
242266 skipCoerceToList ? { } ,
@@ -254,11 +278,17 @@ let
254278 inherit
255279 name
256280 src
257- crds
258281 namePrefix
259282 attrNameOverrides
260283 kindFilter
261284 ;
285+ crdFiles = renamedArg {
286+ fn = "fromCRD" ;
287+ new = "crdFiles" ;
288+ newVal = crdFiles ;
289+ oldVal = crds ;
290+ default = throw "fromCRD: `crdFiles` is required" ;
291+ } ;
262292 } ;
263293 } ;
264294
272302 {
273303 name ,
274304 src ,
275- crds ,
305+ # List of CRD YAML files (relative to `src`) to generate types from.
306+ crdFiles ? null ,
307+ # Deprecated alias for `crdFiles`.
308+ crds ? null ,
276309 namePrefix ? "" ,
277310 attrNameOverrides ? { } ,
278311 skipCoerceToList ? { } ,
@@ -291,30 +324,47 @@ let
291324 inherit
292325 name
293326 src
294- crds
295327 namePrefix
296328 attrNameOverrides
297329 kindFilter
298330 ;
331+ crdFiles = renamedArg {
332+ fn = "fromCRDModule" ;
333+ new = "crdFiles" ;
334+ newVal = crdFiles ;
335+ oldVal = crds ;
336+ default = throw "fromCRDModule: `crdFiles` is required" ;
337+ } ;
299338 } ;
300339 } ;
301340
302341 # Extract the raw CustomResourceDefinition objects from a set of CRD YAML
303- # files. The objects counterpart to `fromCRD`: same `src`/`crds ` inputs, but
304- # returns the CRD manifests as values (e.g. to apply them to a cluster)
342+ # files. The objects counterpart to `fromCRD`: same `src`/`crdFiles ` inputs,
343+ # but returns the CRD manifests as values (e.g. to apply them to a cluster)
305344 # instead of generating resource option modules. Deployment-agnostic — what
306345 # you do with the objects is up to you.
307346 #
308347 # `kindFilter`, when non-empty, keeps only CRDs whose `spec.names.kind` is in
309- # the list (mirrors `fromCRD`'s `kindFilter` and `fromChartCRD`'s `crds `).
348+ # the list (mirrors `fromCRD`'s and `fromChartCRD`'s `kindFilter `).
310349 crdObjects =
311350 {
312351 src ,
313- crds ,
352+ # List of CRD YAML files (relative to `src`) to read.
353+ crdFiles ? null ,
354+ # Deprecated alias for `crdFiles`.
355+ crds ? null ,
314356 kindFilter ? [ ] ,
315357 } :
316358 let
317- objects = lib . concatMap ( f : klib . fromYAML ( builtins . readFile "${ src } /${ f } " ) ) crds ;
359+ files = renamedArg {
360+ fn = "crdObjects" ;
361+ new = "crdFiles" ;
362+ newVal = crdFiles ;
363+ oldVal = crds ;
364+ default = throw "crdObjects: `crdFiles` is required" ;
365+ } ;
366+
367+ objects = lib . concatMap ( f : klib . fromYAML ( builtins . readFile "${ src } /${ f } " ) ) files ;
318368
319369 isWanted =
320370 obj :
331381 chartAttrs ? { } ,
332382 chart ? null ,
333383 values ? { } ,
334- crds ? [ ] ,
384+ # Optional list of CRD `kind` names to keep. Empty/unset = every CRD.
385+ kindFilter ? null ,
386+ # Deprecated alias for `kindFilter`.
387+ crds ? null ,
335388 namePrefix ? "" ,
336389 attrNameOverrides ? { } ,
337390 skipCoerceToList ? { } ,
342395 kubeVersion ? "v${ pkgs . kubernetes . version } " ,
343396 } :
344397 let
398+ kindFilter' = renamedArg {
399+ fn = "fromChartCRD" ;
400+ new = "kindFilter" ;
401+ newVal = kindFilter ;
402+ oldVal = crds ;
403+ default = [ ] ;
404+ } ;
405+
345406 _chart = if chart != null then chart else klib . downloadHelmChart chartAttrs ;
346407
347408 objects = klib . fromHelm {
359420 obj :
360421 obj ? kind
361422 && obj . kind == "CustomResourceDefinition"
362- && ( crds == [ ] || ( lib . any ( x : obj . spec . names . kind == x ) crds ) ) ;
423+ && ( kindFilter' == [ ] || ( lib . any ( x : obj . spec . names . kind == x ) kindFilter' ) ) ;
363424
364425 filtered = lib . filter isWanted objects ;
365426
383444 skipCoerceToList
384445 ;
385446
386- crds = [
447+ crdFiles = [
387448 "crds.yaml"
388449 ] ;
389450 } ;
@@ -427,15 +488,18 @@ let
427488 '' ;
428489
429490 # Chart counterpart to `fromCRDModule`: template a chart's CRDs and return a
430- # module value (resource type options). `crds `, when non-empty, narrows the
431- # generated types to those CRD kinds (mirrors `fromChartCRD`).
491+ # module value (resource type options). `kindFilter `, when non-empty, narrows
492+ # the generated types to those CRD kinds (mirrors `fromChartCRD`).
432493 fromChartCRDModule =
433494 {
434495 name ,
435496 chart ? null ,
436497 chartAttrs ? { } ,
437498 values ? { } ,
438- crds ? [ ] ,
499+ # Optional list of CRD `kind` names to keep. Empty/unset = every CRD.
500+ kindFilter ? null ,
501+ # Deprecated alias for `kindFilter`.
502+ crds ? null ,
439503 extraOpts ? [ ] ,
440504 kubeVersion ? "v${ pkgs . kubernetes . version } " ,
441505 namePrefix ? "" ,
@@ -459,19 +523,29 @@ let
459523 kubeVersion
460524 ;
461525 } ;
462- crds = [ "crds.yaml" ] ;
463- kindFilter = crds ;
526+ crdFiles = [ "crds.yaml" ] ;
527+ kindFilter = renamedArg {
528+ fn = "fromChartCRDModule" ;
529+ new = "kindFilter" ;
530+ newVal = kindFilter ;
531+ oldVal = crds ;
532+ default = [ ] ;
533+ } ;
464534 } ;
465535
466536 # Chart counterpart to `crdObjects`: template a chart's CRDs and return the
467- # raw CustomResourceDefinition manifests as values. `crds` empty = every CRD.
537+ # raw CustomResourceDefinition manifests as values. `kindFilter` empty = every
538+ # CRD.
468539 crdObjectsFromChart =
469540 {
470541 name ,
471542 chart ? null ,
472543 chartAttrs ? { } ,
473544 values ? { } ,
474- crds ? [ ] ,
545+ # Optional list of CRD `kind` names to keep. Empty/unset = every CRD.
546+ kindFilter ? null ,
547+ # Deprecated alias for `kindFilter`.
548+ crds ? null ,
475549 extraOpts ? [ ] ,
476550 kubeVersion ? "v${ pkgs . kubernetes . version } " ,
477551 } :
486560 kubeVersion
487561 ;
488562 } ;
489- crds = [ "crds.yaml" ] ;
490- kindFilter = crds ;
563+ crdFiles = [ "crds.yaml" ] ;
564+ kindFilter = renamedArg {
565+ fn = "crdObjectsFromChart" ;
566+ new = "kindFilter" ;
567+ newVal = kindFilter ;
568+ oldVal = crds ;
569+ default = [ ] ;
570+ } ;
491571 } ;
492572in
493573{
509589 rev = "v3.0.0" ;
510590 hash = "sha256-g401mpNEhCNe8H6lk2HToAEZlZa16Py8ozK2z5/UozA=" ;
511591 } ;
512- crds = [
592+ crdFiles = [
513593 "manifests/crds/application-crd.yaml"
514594 "manifests/crds/applicationset-crd.yaml"
515595 "manifests/crds/appproject-crd.yaml"
0 commit comments