Skip to content

Commit

Permalink
Comment code generation stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arnarg committed Jun 28, 2024
1 parent 45ba30a commit ea395e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkgs/generators/crd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
src,
crds,
}: let
# The nix code generator is slightly modified from kubenix's
# generator and as it kind of depends on the jsonschema to be
# flattened with `$ref`s we first pre-process the CRD with
# a crude python script to flatten it before running the
# generator.
# See: crd2jsonschema.py
schema = let
pythonWithYaml = pkgs.python3.withPackages (ps: [ps.pyyaml]);
in
Expand Down
5 changes: 5 additions & 0 deletions pkgs/generators/crd2jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def flatten_ref(definition, key, root=True):
newProps = {}

for prop, val in definition['properties'].items():
# CRDs never have the type information for metadata and
# as we already have this type information from kubenix's
# generated options we create a special `$ref` with
# '#/global' prefix that we handle specially in our code
# generator.
if root and prop == 'metadata':
newProps[prop] = {
'description': 'Standard object\'s metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata',
Expand Down
3 changes: 3 additions & 0 deletions pkgs/generators/jsonschema.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ with lib; let
# but if other definition does not have properties, then just take it's type
if hasAttr "$ref" property
then
# Handle our special "#/global" ref prefix, used exclusively to get typed
# metadata from CRDs.
# See: crd2jsonschema.py
if hasPrefix "#/global" property."$ref"
then {
type = requiredOrNot (globalSubmoduleOf definitions (refDefinition property));
Expand Down

0 comments on commit ea395e6

Please sign in to comment.