nyl 0.7.1__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. nyl-0.7.2/.changelog/0.7.2.toml +31 -0
  2. {nyl-0.7.1 → nyl-0.7.2}/PKG-INFO +1 -1
  3. {nyl-0.7.1 → nyl-0.7.2}/docs/content/changelog.md +29 -1
  4. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/components.md +1 -1
  5. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/inlining/helmcharts.md +75 -2
  6. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/inlining/overview.md +1 -1
  7. {nyl-0.7.1 → nyl-0.7.2}/pyproject.toml +1 -1
  8. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/__init__.py +2 -0
  9. nyl-0.7.2/src/nyl/commands/add.py +118 -0
  10. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/template.py +2 -2
  11. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/__init__.py +2 -1
  12. {nyl-0.7.1 → nyl-0.7.2}/uv.lock +1 -1
  13. {nyl-0.7.1 → nyl-0.7.2}/.changelog/0.7.0.toml +0 -0
  14. {nyl-0.7.1 → nyl-0.7.2}/.changelog/0.7.1.toml +0 -0
  15. {nyl-0.7.1 → nyl-0.7.2}/.envrc +0 -0
  16. {nyl-0.7.1 → nyl-0.7.2}/.github/workflows/docker.yaml +0 -0
  17. {nyl-0.7.1 → nyl-0.7.2}/.github/workflows/docs.yaml +0 -0
  18. {nyl-0.7.1 → nyl-0.7.2}/.github/workflows/python.yaml +0 -0
  19. {nyl-0.7.1 → nyl-0.7.2}/.github/workflows/update-flake-lock.yaml +0 -0
  20. {nyl-0.7.1 → nyl-0.7.2}/.gitignore +0 -0
  21. {nyl-0.7.1 → nyl-0.7.2}/README.md +0 -0
  22. {nyl-0.7.1 → nyl-0.7.2}/argocd-cmp/Dockerfile +0 -0
  23. {nyl-0.7.1 → nyl-0.7.2}/argocd-cmp/README.md +0 -0
  24. {nyl-0.7.1 → nyl-0.7.2}/argocd-cmp/plugin.yaml +0 -0
  25. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/.envrc +0 -0
  26. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/.secrets.yaml +0 -0
  27. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/.sops.yaml +0 -0
  28. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/README.md +0 -0
  29. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/argocd.yaml +0 -0
  30. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/nyl-project.yaml +0 -0
  31. {nyl-0.7.1 → nyl-0.7.2}/argocd-with-nyl/nyl-secrets.yaml +0 -0
  32. {nyl-0.7.1 → nyl-0.7.2}/docs/content/index.md +0 -0
  33. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/applysets.md +0 -0
  34. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/argocd-plugin.md +0 -0
  35. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/cluster-connectivity.md +0 -0
  36. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration/environment.md +0 -0
  37. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration/profiles.md +0 -0
  38. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration/projects.md +0 -0
  39. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration/secrets.md +0 -0
  40. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration-api/profiles.md +0 -0
  41. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/configuration-api/secrets.md +0 -0
  42. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/glossary.md +0 -0
  43. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/basics.md +0 -0
  44. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/inlining/postprocessor.md +0 -0
  45. {nyl-0.7.1 → nyl-0.7.2}/docs/content/reference/templating/secrets.md +0 -0
  46. {nyl-0.7.1 → nyl-0.7.2}/docs/mkdocs.yml +0 -0
  47. {nyl-0.7.1 → nyl-0.7.2}/docs/pyproject.toml +0 -0
  48. {nyl-0.7.1 → nyl-0.7.2}/docs/uv.lock +0 -0
  49. {nyl-0.7.1 → nyl-0.7.2}/example/manifests/postgres.yaml +0 -0
  50. {nyl-0.7.1 → nyl-0.7.2}/example/nyl-profiles.yaml +0 -0
  51. {nyl-0.7.1 → nyl-0.7.2}/example/nyl-secrets.yaml +0 -0
  52. {nyl-0.7.1 → nyl-0.7.2}/example/secrets.yaml +0 -0
  53. {nyl-0.7.1 → nyl-0.7.2}/flake.lock +0 -0
  54. {nyl-0.7.1 → nyl-0.7.2}/flake.nix +0 -0
  55. {nyl-0.7.1 → nyl-0.7.2}/nix/uv.nix +0 -0
  56. {nyl-0.7.1 → nyl-0.7.2}/renovate.json +0 -0
  57. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/README.md +0 -0
  58. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/__init__.pyi +0 -0
  59. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/dynamic/__init__.pyi +0 -0
  60. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/dynamic/client.pyi +0 -0
  61. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/dynamic/discovery.pyi +0 -0
  62. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/dynamic/exceptions.pyi +0 -0
  63. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/dynamic/resource.pyi +0 -0
  64. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/watch/__init__.pyi +0 -0
  65. {nyl-0.7.1 → nyl-0.7.2}/src/kubernetes/watch/watch.pyi +0 -0
  66. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/__init__.py +0 -0
  67. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/argocd.py +0 -0
  68. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/crds.py +0 -0
  69. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/new.py +0 -0
  70. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/profile.py +0 -0
  71. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/run.py +0 -0
  72. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/secrets.py +0 -0
  73. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/tools/__init__.py +0 -0
  74. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/tools/bcrypt.py +0 -0
  75. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/tools/sops.py +0 -0
  76. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/commands/tun.py +0 -0
  77. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/__init__.py +0 -0
  78. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/components.py +0 -0
  79. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/dispatch.py +0 -0
  80. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/dispatch_test.py +0 -0
  81. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/helmchart.py +0 -0
  82. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/generator/statefulsecret.py +0 -0
  83. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/profiles/__init__.py +0 -0
  84. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/profiles/config.py +0 -0
  85. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/profiles/config_test.py +0 -0
  86. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/profiles/kubeconfig.py +0 -0
  87. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/profiles/tunnel.py +0 -0
  88. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/project/config.py +0 -0
  89. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/applyset.py +0 -0
  90. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/applyset_test.py +0 -0
  91. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/helmchart.py +0 -0
  92. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/helmchart_test.py +0 -0
  93. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/placeholder.py +0 -0
  94. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/postprocessor.py +0 -0
  95. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/postprocessor_test.py +0 -0
  96. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/resources/statefulsecret.py +0 -0
  97. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/__init__.py +0 -0
  98. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/config.py +0 -0
  99. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/config_test.py +0 -0
  100. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/kubernetes.py +0 -0
  101. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/null.py +0 -0
  102. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/sops.py +0 -0
  103. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/secrets/sops_test.py +0 -0
  104. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/templating.py +0 -0
  105. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/templating_test.py +0 -0
  106. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/di.py +0 -0
  107. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/fs.py +0 -0
  108. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/fs_test.py +0 -0
  109. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/kubectl.py +0 -0
  110. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/kubernetes.py +0 -0
  111. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/kvstore.py +0 -0
  112. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/loads.py +0 -0
  113. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/logging.py +0 -0
  114. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/shell.py +0 -0
  115. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/testing.py +0 -0
  116. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/typer.py +0 -0
  117. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/types.py +0 -0
  118. {nyl-0.7.1 → nyl-0.7.2}/src/nyl/tools/yaml.py +0 -0
  119. {nyl-0.7.1 → nyl-0.7.2}/tests/__init__.py +0 -0
  120. {nyl-0.7.1 → nyl-0.7.2}/tests/conftest.py +0 -0
@@ -0,0 +1,31 @@
1
+ release-date = "2025-01-17"
2
+
3
+ [[entries]]
4
+ id = "00755f35-1e28-4946-9cbb-eccb2735b9fb"
5
+ type = "feature"
6
+ description = "Add `nyl add namespace` command"
7
+ author = "@NiklasRosenstein"
8
+
9
+ [[entries]]
10
+ id = "1a17887c-ed8a-40a9-9ff5-11b594c20dd4"
11
+ type = "docs"
12
+ description = "Fix links in docs and add information on how to use the `HelmChart.spec.chart` field"
13
+ author = "@NiklasRosenstein"
14
+
15
+ [[entries]]
16
+ id = "3f471926-8529-4e46-8d73-41c2825a3578"
17
+ type = "feature"
18
+ description = "Add `nyl add chart` command"
19
+ author = "@NiklasRosenstein"
20
+
21
+ [[entries]]
22
+ id = "242fa8b1-225f-42f4-bf7f-fe6af806f0b5"
23
+ type = "docs"
24
+ description = "Add note to discurage from using `{{ .Release.Namespace }}` in Helm charts"
25
+ author = "@NiklasRosenstein"
26
+
27
+ [[entries]]
28
+ id = "a09f0665-99a6-4a54-b0eb-afe4f719a320"
29
+ type = "breaking change"
30
+ description = "Rename annotation `nyl.io/default-namespace` to `nyl.io/is-default-namespace`"
31
+ author = "@NiklasRosenstein"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nyl
3
- Version: 0.7.1
3
+ Version: 0.7.2
4
4
  Summary: Advanced templating engine for Kubernetes and GitOps.
5
5
  Author-email: Niklas Rosenstein <rosensteinniklas@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,34 @@
1
1
  # Changelog
2
2
 
3
- ## 0.7.0
3
+ ## 0.7.2 (2025-01-17)
4
+
5
+ <table><tr><th>Type</th><th>Description</th><th>PR</th><th>Issues</th><th>Author</th></tr>
6
+ <tr><td>Feature</td><td>
7
+
8
+ Add `nyl add namespace` command</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
9
+ <tr><td>Docs</td><td>
10
+
11
+ Fix links in docs and add information on how to use the `HelmChart.spec.chart` field</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
12
+ <tr><td>Feature</td><td>
13
+
14
+ Add `nyl add chart` command</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
15
+ <tr><td>Docs</td><td>
16
+
17
+ Add note to discurage from using `{{ .Release.Namespace }}` in Helm charts</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
18
+ <tr><td>Breaking change</td><td>
19
+
20
+ Rename annotation `nyl.io/default-namespace` to `nyl.io/is-default-namespace`</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
21
+ </table>
22
+
23
+ ## 0.7.1 (2025-01-17)
24
+
25
+ <table><tr><th>Type</th><th>Description</th><th>PR</th><th>Issues</th><th>Author</th></tr>
26
+ <tr><td>Fix</td><td>
27
+
28
+ Fixed a bug where pulling two different charts with the same version number from the same repository conflated the cache key and ended up with Nyl using the wrong chart (that which has been pulled first).</td><td></td><td></td><td>@NiklasRosenstein</td></tr>
29
+ </table>
30
+
31
+ ## 0.7.0 (2025-01-17)
4
32
 
5
33
  <table><tr><th>Type</th><th>Description</th><th>PR</th><th>Issues</th><th>Author</th></tr>
6
34
  <tr><td>Breaking change</td><td>
@@ -8,7 +8,7 @@ Nyl components are effectively templates that you can instantiate them similar t
8
8
  are treated in a way similar to CRDs, only that they will never to pushed to the Kubernetes API server and instead be
9
9
  replaced throuhg a first reconcilation phase during `nyl template`.
10
10
 
11
- Components are built on top of Helm chart [inlining](./inlining.md#helm-charts).
11
+ Components are built on top of Helm chart [inlining](./inlining/helmcharts.md).
12
12
 
13
13
  ## How Nyl looks for components
14
14
 
@@ -5,12 +5,12 @@ weight: 5
5
5
  # HelmChart
6
6
 
7
7
  Nyl allows you to inline Helm charts by specifying a `HelmChart` resource in your manifest. Just like any other
8
- resource, the Helm chart resource values can be templated using Nyl's [structured templating](../templating/basics.md)
8
+ resource, the Helm chart resource values can be templated using Nyl's [structured templating](../basics.md)
9
9
  (for example to inject secrets), and are then rendered to Kubernetes resources that are inlined in your configuration.
10
10
 
11
11
  __Example__
12
12
 
13
- ```yaml
13
+ ```yaml
14
14
  apiVersion: inline.nyl.io/v1
15
15
  kind: HelmChart
16
16
  metadata:
@@ -27,6 +27,79 @@ spec:
27
27
  type: LoadBalancer
28
28
  ```
29
29
 
30
+ When writing Helm charts, we discourage from using `namespace: {{ .Release.Namespace }}`. This is because when you
31
+ instantiate a `HelmChart` in Nyl without specifying a `.metadata.namespace`, the Helm chart will be templated without
32
+ the `--namespace` option. This will have Helm assume `.Release.Namespace == "default"`, thus all `namespace` fields
33
+ in the generated resource will be set to `default`. This is not what you want, as it will prevent Nyl from injecting the
34
+ appropriate namespace based on the context of your local manifest file.
35
+
36
+ If you are dealing with a Helm chart that does use `namespace: {{ .Release.Namespace }}`, be sure to set the `.metadata.namespace` field of your Nyl `HelmChart` resource.
37
+
38
+ ## ChartRef
39
+
40
+ The `.spec.chart` field defines the source of the Helm chart. You can source charts from a Helm HTTP(S) or OCI repository, a Git repository or a local directory. Local chart paths are first resolved in the Nyl search path that can be defined in the [Project settings](../../configuration/projects.md).
41
+
42
+ !!! note
43
+ We highly recommend to add a as a comment the link to <artifacthub.io>, if available. This allows you to easily
44
+ look up the chart version, values and documentation.
45
+
46
+ === "HTTP(S) repository"
47
+
48
+ ```yaml
49
+ # ...
50
+ spec:
51
+ chart:
52
+ # https://artifacthub.io/packages/helm/bitnami/nginx
53
+ repository: https://charts.bitnami.com/bitnami
54
+ name: nginx
55
+ version: 18.3.5 # 1.27.3
56
+ ```
57
+
58
+ === "OCI repository"
59
+
60
+ ```yaml
61
+ # ...
62
+ spec:
63
+ chart:
64
+ # https://artifacthub.io/packages/helm/bitnami/nginx
65
+ repository: oci://registry-1.docker.io/bitnamicharts
66
+ name: nginx
67
+ version: 18.3.5 # 1.27.3
68
+ ```
69
+
70
+ Note how the OCI URL does not contain the chart name. It is specified separately in the `name` field.
71
+
72
+ === "Git repository"
73
+
74
+ ```yaml
75
+ # ...
76
+ spec:
77
+ chart:
78
+ # This can be any valid URL that can be used with `git clone`, plus an optional URL query parameter that is
79
+ # either `ref` (for a Git reF) or `rev` (or a Git commit SHA).
80
+ git: https://github.com/bitnami/charts?rev=e808ba0
81
+
82
+ # If the chart is not located at the root of the repository, point to its subdirectory.
83
+ path: bitnami/nginx
84
+ ```
85
+
86
+ === "Local directory"
87
+
88
+ ```yaml
89
+ # ...
90
+ spec:
91
+ chart:
92
+ # Explicitly relative paths (e.g. starting with `./`) are resolved relative to the manifest source file that
93
+ # defines the `HelmChart` resource.
94
+ path: ./charts/nginx
95
+
96
+ # Absolute paths are resolved absolute in the local filesystem. This is not usually useful except for testing.
97
+ path: /path/to/chart
98
+
99
+ # Any other path is resolved in the Nyl project search path.
100
+ path: nginx
101
+ ```
102
+
30
103
  ### Comparison to native ArgoCD Helm applications
31
104
 
32
105
  Nyl may look similar to Helm in the sense that it allows for templating YAML files. However, there are some important
@@ -6,5 +6,5 @@ title: Overview
6
6
 
7
7
  Nyl supports inlining of Kubernetes resources generated from templates in your configuration. Resources that are
8
8
  inlined by Nyl are typically in the `inline.nyl.io/v1` API group, however Nyl also has the concept of
9
- [components](./components.md) which effectively allow you to define your own API groups and resource kinds for
9
+ [components](../components.md) which effectively allow you to define your own API groups and resource kinds for
10
10
  inlined resources.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nyl"
7
- version = "0.7.1"
7
+ version = "0.7.2"
8
8
  description = "Advanced templating engine for Kubernetes and GitOps."
9
9
  authors = [
10
10
  {name = "Niklas Rosenstein", email = "rosensteinniklas@gmail.com"},
@@ -121,6 +121,7 @@ def version() -> None:
121
121
  sys.exit(0)
122
122
 
123
123
 
124
+ from . import add # noqa: E402
124
125
  from . import argocd # noqa: E402
125
126
  from . import crds # noqa: F401,E402
126
127
  from . import new # noqa: E402
@@ -131,6 +132,7 @@ from . import template # noqa: F401,E402
131
132
  from . import tools # noqa: E402
132
133
  from . import tun # noqa: E402
133
134
 
135
+ app.add_typer(add.app)
134
136
  app.add_typer(argocd.app)
135
137
  app.add_typer(new.app)
136
138
  app.add_typer(profile.app)
@@ -0,0 +1,118 @@
1
+ """
2
+ Convenient CLI for making ammends to Kubernetes manifest files.
3
+ """
4
+
5
+ from pathlib import Path
6
+ import sys
7
+ from typing import Any
8
+ from typer import Argument, Option, Typer
9
+ from loguru import logger
10
+ import yaml
11
+
12
+ from nyl.commands.template import (
13
+ DEFAULT_NAMESPACE_ANNOTATION,
14
+ ManifestsWithSource,
15
+ is_namespace_resource,
16
+ load_manifests,
17
+ )
18
+ from nyl.resources import ObjectMetadata
19
+ from nyl.resources.helmchart import ChartRef, HelmChart, HelmChartSpec
20
+ from nyl.tools.typer import new_typer
21
+ from nyl.tools.types import Manifests
22
+
23
+ app: Typer = new_typer(name="add", help=__doc__)
24
+
25
+ MANIFEST_OPTION = Option(..., "-m", "--manifest", help="The manifest YAML file to add the namespace to.")
26
+
27
+
28
+ @app.command()
29
+ def namespace(
30
+ manifest: Path = MANIFEST_OPTION,
31
+ name: str = Argument(help="Name of the namespace to add."),
32
+ ) -> None:
33
+ """
34
+ Add a Kubernetes `Namespace` resource definition to the top of the specified manifest file.
35
+
36
+ If this is the first namespace defined in the manifest, it will be annotated with `nyl.io/is-default-namespace`.
37
+ """
38
+
39
+ if manifest.exists():
40
+ content = manifest.read_text()
41
+ resources = load_manifests([manifest])[0]
42
+ else:
43
+ content = ""
44
+ resources = ManifestsWithSource(Manifests([]), manifest)
45
+
46
+ if any(is_namespace_resource(x) and x["metadata"]["name"] == name for x in resources.manifests):
47
+ logger.error("Namespace '{}' already exists in {}.", name, manifest)
48
+ sys.exit(1)
49
+
50
+ namespace: dict[str, Any] = {
51
+ "apiVersion": "v1",
52
+ "kind": "Namespace",
53
+ "metadata": {
54
+ "name": name,
55
+ },
56
+ }
57
+
58
+ as_default = not any(is_namespace_resource(x) for x in resources.manifests)
59
+ if as_default:
60
+ namespace["metadata"]["annotations"] = {DEFAULT_NAMESPACE_ANNOTATION: "true"}
61
+
62
+ if not content.lstrip().startswith("---"):
63
+ content = f"---\n{content}"
64
+ content = f"---\n{yaml.safe_dump(namespace, sort_keys=False)}\n{content}"
65
+ manifest.write_text(content)
66
+
67
+ logger.info("Added {}namespace '{}' to {}.", "default " if as_default else "", name, manifest)
68
+
69
+
70
+ @app.command()
71
+ def chart(
72
+ manifest: Path = MANIFEST_OPTION,
73
+ name: str = Argument(help="The release name."),
74
+ namespace: str | None = Option(None, "-n", "--namespace", help="The release namespace."),
75
+ repository: str | None = Option(None, "--repo", "--repository", help="The chart repository."),
76
+ chart: str | None = Option(None, "--chart", help="The chart name."),
77
+ version: str | None = Option(None, "--version", help="The chart version."),
78
+ path: str | None = Option(None, "--path", help="The chart path if consumed from disk."),
79
+ git: str | None = Option(None, "--git", help="Git URL of the chart."),
80
+ ) -> None:
81
+ """
82
+ Append a Nyl `HelmChart` resource to the specified manifest file.
83
+ """
84
+
85
+ if repository or chart or version:
86
+ if not repository or not chart or not version:
87
+ logger.error("If any of --repo, --chart, or --version are specified, all must be specified.")
88
+ sys.exit(1)
89
+
90
+ if path or git:
91
+ logger.error("If --repo is specified, --path and --git must not be specified.")
92
+ sys.exit(1)
93
+
94
+ if git:
95
+ if repository:
96
+ logger.error("If --git is specified, --repo must not be specified.")
97
+ sys.exit(1)
98
+
99
+ resource = HelmChart(
100
+ metadata=ObjectMetadata(name=name, namespace=namespace),
101
+ spec=HelmChartSpec(
102
+ chart=ChartRef(
103
+ path=path,
104
+ git=git,
105
+ repository=repository,
106
+ name=chart,
107
+ version=version,
108
+ ),
109
+ values={},
110
+ ),
111
+ )
112
+
113
+ content = manifest.read_text() if manifest.exists() else ""
114
+ if not content.rstrip().endswith("---"):
115
+ content += "\n---\n"
116
+ content += yaml.safe_dump(resource.dump())
117
+
118
+ manifest.write_text(content)
@@ -29,7 +29,7 @@ from nyl.tools.logging import lazy_str
29
29
  from nyl.tools.types import Manifest, Manifests
30
30
 
31
31
  DEFAULT_PROFILE = "default"
32
- DEFAULT_NAMESPACE_ANNOTATION = "nyl.io/default-namespace"
32
+ DEFAULT_NAMESPACE_ANNOTATION = "nyl.io/is-default-namespace"
33
33
 
34
34
 
35
35
  # Need an enum for typer
@@ -431,7 +431,7 @@ def get_default_namespace_for_manifest(source: ManifestsWithSource, fallback: st
431
431
  fallback.
432
432
 
433
433
  - If there are multiple `v1/Namespace` resources declared in the manifest, we pick the one with the
434
- `nyl.io/default-namespace` label. If there is no such namespace, a warning is logged and we pick the first one
434
+ `nyl.io/is-default-namespace` label. If there is no such namespace, a warning is logged and we pick the first one
435
435
  alphabetically.
436
436
 
437
437
  Returns:
@@ -6,6 +6,7 @@ from abc import ABC
6
6
  from dataclasses import dataclass
7
7
  from typing import ClassVar, Collection, cast
8
8
 
9
+ from databind.core import SerializeDefaults
9
10
  from databind.json import dump as ser
10
11
  from databind.json import load as deser
11
12
  from typing_extensions import Self
@@ -107,7 +108,7 @@ class NylResource(ABC):
107
108
  Dump the resource to a manifest.
108
109
  """
109
110
 
110
- manifest = cast(Manifest, ser(self, type(self)))
111
+ manifest = cast(Manifest, ser(self, type(self), settings=[SerializeDefaults(False)]))
111
112
  manifest["apiVersion"] = self.API_VERSION
112
113
  manifest["kind"] = self.KIND
113
114
  return Manifest(manifest)
@@ -384,7 +384,7 @@ wheels = [
384
384
 
385
385
  [[package]]
386
386
  name = "nyl"
387
- version = "0.7.0"
387
+ version = "0.7.1"
388
388
  source = { editable = "." }
389
389
  dependencies = [
390
390
  { name = "bcrypt" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes