A library for modifying Kubernetes manifests and other json-like objects.
Project description
ArgoCD Kit
A toolkit for building services for ArgoCD
Configuration Management Plugins
ArgoCD CMPs let ArgoCD run your code to generate the manifests for Applications. You can use this to run custom templating tools or even implement your own.
- Create a subclass of
CMP
from alpacloud.argocdkit.cmp import CMP, App, T, S
class HelmPostRendererCMP(CMP):
...
- Define a CMP spec
from alpacloud.argocdkit.spec import Plugin, Metadata, Spec, Command
class HelmPostRendererCMP(CMP):
@property
def spec(self) -> Plugin:
return Plugin(
metadata=Metadata(name="helm-and-python"),
spec=Spec(
version="0.0.1",
generate=Command(
command=["/bin/alpacloud-argocdkit"], # this is the path to the entrypoint for this file
),
)
)
-
Implement the logic of your plugin in the
generatemethod. You can also use the hooksparse_paramsandparse_envto parse those attributes on the Application's definition into normal Python classes.
import sh
from pydantic import BaseModel
from alpacloud.argocdkit.cmp import CMP, App, T, S
from alpacloud.lens.util.type import JSONT
class HelmParameters(BaseModel):
valueFiles: list[str] = []
valuesObject: dict = {}
values: str | None = None
postRenderers: list[str] = []
class HelmPostRendererCMP(CMP):
def parse_params(self, params: JSONT) -> HelmParameters:
params = super().parse_params(params)
return HelmParameters.model_validate(params)
# helper methods for running Helm
def generate(self, app: App, params: HelmParameters, plugin_env: S):
argv = []
argv.extend(self.values_argv(params.valuesObject, params.values, params.valueFiles))
argv.append(f"--namespace={app.namespace}")
argv.extend(self.postrenderers_argv(params.postRenderers))
return sh.Command("helm")(["template", app.name, ".", *argv])
- Run your plugin on startup
#!/usr/bin/env python3
if __name__ == "__main__":
entrypoint(HelmPostRendererCMP())()
- To generate the CMP plugin config file, run the cmp with the argument "gen-cfg". This will put it in the correct directory for a container, although you can also specify the output file as the second argument.
./my_cmp "gen-cfg"
- Register your plugin with ArgoCD following their documentation
Helm post-renderer
Sometimes a Helm chart doesn't have an option for a feature that you need. You can write a post-renderer to run your code on the rendered files of a Helm chart to do whatever you want. You can convert a BoundLens from the alpacloud.lens library or any function into a postrederer with the postrenderer function.
#!/usr/bin/env python3
from alpacloud.argocdkit.postrender import postrenderer
from alpacloud.lens.k8s import labels
from alpacloud.lens.models import CombinedBoundLens, Const, ForeachLens, korn
p = postrenderer(CombinedBoundLens((
ForeachLens(labels / korn("my-label")) @ Const("my-label-value"),
)))
if __name__ == "__main__":
p()
#!/usr/bin/env python3
from alpacloud.argocdkit.postrender import postrenderer
from alpacloud.lens.util.type import JSONT
def add_note(manifests: list[JSONT]) -> list[JSONT]:
for manifest in manifests:
manifest["metadata"].get("labels", {})["my-label"] = "my-label-value"
return manifests
p = postrenderer(add_note)
if __name__ == "__main__":
p()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alpacloud_argocdkit-0.1.0.tar.gz.
File metadata
- Download URL: alpacloud_argocdkit-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1dc4cf5f248290e03c6b1ee563070082789cfc89700329ba0037fc7417d193
|
|
| MD5 |
54b00ee0aa14aec1e5740a415ad372d8
|
|
| BLAKE2b-256 |
29925abab242f5faf201161cb9bea26b87c7c4c715415461035acfb4ee62f96e
|
File details
Details for the file alpacloud.argocdkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alpacloud.argocdkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3df4c1a93c2ea243b03281f786c05f2876dbb981a805701e25e22708609ef55c
|
|
| MD5 |
c76191ee1deef7990b3c73b321f6f31f
|
|
| BLAKE2b-256 |
5f879aa059100746d4282c2daa5c19b7b9485853027a7ec752baed53b03854dc
|