Skip to main content

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.

  1. Create a subclass of CMP
from alpacloud.argocdkit.cmp import CMP, App, T, S

class HelmPostRendererCMP(CMP):
    ...
  1. 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
                ),
            )
)
  1. Implement the logic of your plugin in the generate method. You can also use the hooks parse_params and parse_env to 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])
  1. Run your plugin on startup
#!/usr/bin/env python3

if __name__ == "__main__":
	entrypoint(HelmPostRendererCMP())()
  1. 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"
  1. 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()

Metadata

Release files for alpacloud.argocdkit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpacloud.argocdkit 0.1.0
File Size Uploaded Provenance Actions
alpacloud_argocdkit-0.1.0.tar.gz 5.9 kB Without provenance Details for alpacloud_argocdkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for alpacloud.argocdkit 0.1.0
File Interpreter ABI Platform Actions
alpacloud.argocdkit-0.1.0-py3-none-any.whl Python 3 none any Details for alpacloud.argocdkit-0.1.0-py3-none-any.whl

Total release size: 13.1 kB

Release files / alpacloud_argocdkit-0.1.0.tar.gz

Download URL alpacloud_argocdkit-0.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1c1dc4cf5f248290e03c6b1ee563070082789cfc89700329ba0037fc7417d193
BLAKE2b-256 checksum
How to use checksums
29925abab242f5faf201161cb9bea26b87c7c4c715415461035acfb4ee62f96e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / alpacloud.argocdkit-0.1.0-py3-none-any.whl

Download URL alpacloud.argocdkit-0.1.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3df4c1a93c2ea243b03281f786c05f2876dbb981a805701e25e22708609ef55c
BLAKE2b-256 checksum
How to use checksums
5f879aa059100746d4282c2daa5c19b7b9485853027a7ec752baed53b03854dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for alpacloud.argocdkit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page