nyl 0.0.7__tar.gz → 0.0.8__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 (39) hide show
  1. {nyl-0.0.7 → nyl-0.0.8}/PKG-INFO +1 -1
  2. {nyl-0.0.7 → nyl-0.0.8}/pyproject.toml +1 -1
  3. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/__init__.py +2 -0
  4. nyl-0.0.8/src/nyl/commands/argocd.py +35 -0
  5. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/template.py +17 -6
  6. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/resources/__init__.py +8 -3
  7. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/secrets/config.py +3 -2
  8. {nyl-0.0.7 → nyl-0.0.8}/README.md +0 -0
  9. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/__init__.py +0 -0
  10. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/crds.py +0 -0
  11. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/new.py +0 -0
  12. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/profile.py +0 -0
  13. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/secrets.py +0 -0
  14. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/commands/tun.py +0 -0
  15. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/generator/__init__.py +0 -0
  16. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/generator/dispatch.py +0 -0
  17. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/generator/dispatch_test.py +0 -0
  18. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/generator/helmchart.py +0 -0
  19. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/generator/statefulsecret.py +0 -0
  20. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/profiles/__init__.py +0 -0
  21. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/profiles/config.py +0 -0
  22. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/profiles/kubeconfig.py +0 -0
  23. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/profiles/tunnel.py +0 -0
  24. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/project/config.py +0 -0
  25. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/resources/applyset.py +0 -0
  26. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/resources/applyset_test.py +0 -0
  27. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/resources/helmchart.py +0 -0
  28. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/resources/statefulsecret.py +0 -0
  29. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/secrets/__init__.py +0 -0
  30. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/secrets/null.py +0 -0
  31. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/secrets/sops.py +0 -0
  32. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/secrets/sops_test.py +0 -0
  33. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/fs.py +0 -0
  34. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/kubectl.py +0 -0
  35. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/kvstore.py +0 -0
  36. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/shell.py +0 -0
  37. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/typer.py +0 -0
  38. {nyl-0.0.7 → nyl-0.0.8}/src/nyl/tools/types.py +0 -0
  39. {nyl-0.0.7 → nyl-0.0.8}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nyl
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Summary: Default template for PDM package
5
5
  Author-Email: Niklas Rosenstein <rosensteinniklas@gmail.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nyl"
3
- version = "0.0.7"
3
+ version = "0.0.8"
4
4
  description = "Default template for PDM package"
5
5
  authors = [
6
6
  { name = "Niklas Rosenstein", email = "rosensteinniklas@gmail.com" },
@@ -15,6 +15,7 @@ from nyl.tools.typer import new_typer
15
15
  app = new_typer(help=__doc__)
16
16
 
17
17
 
18
+ from . import argocd # noqa: E402
18
19
  from . import crds # noqa: F401,E402
19
20
  from . import new # noqa: E402
20
21
  from . import profile # noqa: E402
@@ -22,6 +23,7 @@ from . import secrets # noqa: E402
22
23
  from . import template # noqa: F401,E402
23
24
  from . import tun # noqa: E402
24
25
 
26
+ app.add_typer(argocd.app)
25
27
  app.add_typer(new.app)
26
28
  app.add_typer(profile.app)
27
29
  app.add_typer(secrets.app)
@@ -0,0 +1,35 @@
1
+ """
2
+ Helper commands for the ArgoCD integration.
3
+ """
4
+
5
+ import sys
6
+
7
+ from loguru import logger
8
+ from nyl.project.config import ProjectConfig
9
+ from nyl.secrets.config import SecretsConfig
10
+ from nyl.tools.typer import new_typer
11
+
12
+
13
+ app = new_typer(name="argocd", help=__doc__)
14
+
15
+
16
+ @app.command()
17
+ def discovery() -> None:
18
+ """
19
+ Discover whether the current working directory uses Nyl. This is when either a `nyl-project.yaml` or
20
+ `nyl-secrets.yaml` file is present in the directory or any of its parent directories.
21
+ """
22
+
23
+ found = False
24
+ if (file := ProjectConfig.load().file) is not None:
25
+ print(file.absolute())
26
+ found = True
27
+ if (file := SecretsConfig.load().file) is not None:
28
+ print(file.absolute())
29
+ found = True
30
+
31
+ if not found:
32
+ logger.info("No Nyl project or secrets configuration found.")
33
+ else:
34
+ logger.info("Found Nyl project and/or secrets configuration.")
35
+ sys.exit(0 if found else 1)
@@ -13,6 +13,7 @@ from kubernetes.config.incluster_config import load_incluster_config
13
13
  from kubernetes.config.kube_config import load_kube_config
14
14
  from kubernetes.client.api_client import ApiClient
15
15
  from nyl.project.config import ProjectConfig
16
+ from nyl.resources import API_VERSION_INLINE, NylResource
16
17
  from nyl.resources.applyset import APPLYSET_LABEL_PART_OF, ApplySet
17
18
  from nyl.secrets.config import SecretsConfig
18
19
  from nyl.tools.kubectl import Kubectl
@@ -59,6 +60,7 @@ def template(
59
60
  "This option must be disabled when passing the generated manifests to `kubectl apply --applyset=...`, as it "
60
61
  "would otherwise cause an error due to the label being present on the input data.",
61
62
  ),
63
+ inline: bool = Option(True, help="Evaluate Nyl inlined resources."),
62
64
  ) -> None:
63
65
  """
64
66
  Render a package template into full Kubernetes resources.
@@ -128,11 +130,12 @@ def template(
128
130
  logger.opt(ansi=True).info("Rendering manifests from <blue>{}</>.", source.file)
129
131
 
130
132
  source.manifests = cast(Manifests, template_engine.evaluate(source.manifests))
131
- source.manifests = reconcile_generator(
132
- generator,
133
- source.manifests,
134
- on_generated=lambda m: cast(Manifest, template_engine.evaluate(m)),
135
- )
133
+ if inline:
134
+ source.manifests = reconcile_generator(
135
+ generator,
136
+ source.manifests,
137
+ on_generated=lambda m: cast(Manifest, template_engine.evaluate(m)),
138
+ )
136
139
 
137
140
  # Find the namespaces that are defined in the file. If we find any manifests without a namespace, we will
138
141
  # inject that namespace name into them.
@@ -193,6 +196,12 @@ def template(
193
196
  # Find all manifests without a namespace and inject the namespace name into them.
194
197
  # If there is an applyset, ensure they are marked as part of the applyset.
195
198
  for manifest in source.manifests:
199
+ # Inline resources often don't have metadata and they are not persisted to the cluster, hence
200
+ # we don't need to process them here.
201
+ if NylResource.matches(manifest, API_VERSION_INLINE):
202
+ assert not inline, "Inline resources should have been processed by this timepdm lint."
203
+ continue
204
+
196
205
  if applyset is not None and applyset_part_of:
197
206
  if APPLYSET_LABEL_PART_OF not in (labels := manifest["metadata"].setdefault("labels", {})):
198
207
  labels[APPLYSET_LABEL_PART_OF] = applyset.id
@@ -231,7 +240,9 @@ def template(
231
240
  manifest["metadata"]["namespace"],
232
241
  )
233
242
 
234
- if not apply:
243
+ if not apply:
244
+ # If we're not going to be applying the manifests immediately via `kubectl`, we print them to stdout.
245
+ for manifest in source.manifests:
235
246
  print("---")
236
247
  print(yaml.safe_dump(manifest))
237
248
 
@@ -4,7 +4,7 @@ This package contains Nyl's own Kubernetes-esque resources.
4
4
 
5
5
  from abc import ABC
6
6
  from dataclasses import dataclass
7
- from typing import ClassVar, cast
7
+ from typing import ClassVar, Collection, cast
8
8
  from typing_extensions import Self
9
9
  from databind.json import load as deser, dump as ser
10
10
 
@@ -81,13 +81,18 @@ class NylResource(ABC):
81
81
  return None
82
82
 
83
83
  @classmethod
84
- def matches(cls, manifest: Manifest) -> bool:
84
+ def matches(cls, manifest: Manifest, apiVersion: str | Collection[str] | None = None) -> bool:
85
85
  """
86
86
  Check if the manifest is a NylResource of the correct `apiVersion` and possibly `kind` (if called on a
87
87
  `NylResource` subclass).
88
88
  """
89
89
 
90
- if manifest.get("apiVersion") not in (API_VERSION_K8S, API_VERSION_INLINE):
90
+ if apiVersion is None:
91
+ apiVersion = {API_VERSION_K8S, API_VERSION_INLINE}
92
+ elif isinstance(apiVersion, str):
93
+ apiVersion = {apiVersion}
94
+
95
+ if manifest.get("apiVersion") not in apiVersion:
91
96
  return False
92
97
 
93
98
  if cls is not NylResource and manifest["kind"] != cls.KIND:
@@ -51,6 +51,7 @@ class SecretProvider(ABC):
51
51
  class SecretsConfig:
52
52
  FILENAME = "nyl-secrets.yaml"
53
53
 
54
+ file: Path | None
54
55
  provider: SecretProvider
55
56
 
56
57
  @staticmethod
@@ -67,9 +68,9 @@ class SecretsConfig:
67
68
  if file is None:
68
69
  file = find_config_file(SecretsConfig.FILENAME, required=False)
69
70
  if file is None:
70
- return SecretsConfig(NullSecretsProvider())
71
+ return SecretsConfig(None, NullSecretsProvider())
71
72
  else:
72
73
  logger.debug("Loading secrets configuration from '{}'", file)
73
74
  provider = deser(safe_load(file.read_text()), SecretProvider, filename=str(file))
74
75
  provider.init(file)
75
- return SecretsConfig(provider)
76
+ return SecretsConfig(file, provider)
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