A project to generate ArgoCD application resources
Project description
Description
A tool to generate on the user side per environemnt Kubernetes manifests that can be deployed with ArgoCD.
ArcoCD resources of type Application
are generated automatically based on the provided configuration.
Motivation
Manifests that are written in kustomize/helm/jsonnet might easily become hard to read and debug. The development lifecycle becomes longer when after each change you need to commit, wait for ArgoCD to pick it up and deploy it. Only after that you see the actual end manifest in ArcoCD UI.
With this tool you can quickly render jinja2/kustomize files, run yaml linter and continuer development.
Features
- Jinja2 and Kustomize rendering
- ArgoCD
Application
resources are generated automatically - Use
include
orinclude_raw
in Jinja2 templates to render content of external files - Global and per environment Jinja2 variables
- Single line YAML comments are supported
- Applications in subdirectories are supported
Usage
python3 -m venv .venv
. .venv/bin/activate
pip install make-argocd-fly
make-argocd-fly
Configuration
config.yml
Expected file structure
source_dir: source
output_dir: output
tmp_dir: .tmp
envs:
dev:
apps:
bootstrap: {}
extra_app_deployer: {app_deployer: bootstrap, project: default, destination_namespace: namespace_1}
app_1:
app_deployer: bootstrap
project: default
destination_namespace: namespace_1
vars:
argocd:
target_revision: custom_branch
subdirectory/app_2: {app_deployer: extra_app_deployer, project: default, destination_namespace: namespace_2}
vars:
argocd:
api_server: dev-api-server
var_3: value_X
prod:
apps:
app_1: {app_deployer: bootstrap, project: default, destination_namespace: namespace_1}
vars:
argocd:
api_server: prod-api-server
vars:
argocd:
namespace: argocd
repo_url: https://example.com/repo.git
target_revision: HEAD
sync_policy:
automated:
selfHeal: true
prune: true
allowEmpty: true
# https://www.arthurkoziel.com/fixing-argocd-crd-too-long-error/
syncOptions:
- ServerSideApply=true
finalizers:
- resources-finalizer.argocd.argoproj.io
var_1:
var_2: value_2
var_3: value_3
With such configuration file you can have kustomize overlays for dev/prod
and use jinja2 variables like {{ var_1.var_2 }} and {{ var_3 }}
in your source files.
app parameters
app_deployer
- name of the application that will deploy this applicationapp_deployer_env
- (OPTIONAL) environment of the application that will deploy this applicationproject
- ArgoCD project namedestination_namespace
- namespace where the application will be deployedvars
- (OPTIONAL) application specific jinja2 variables
Jinja2 extensions
To include an external template in a jinja2 template, use the following block:
{%- filter indent(width=4) %}
{% include 'app_4/files/file.json' %}
{% endfilter %}
To include an external file without rendering it in a jinja2 template, use the following block:
{%- filter indent(width=4) %}
{% include_raw 'app_4/files/file.json' %}
{% endfilter %}
To perform a DNS lookup, use the following filter:
{{ 'example.com' | dig }}
Ansible filters are supported as well: https://pypi.org/project/jinja2-ansible-filters/
Caveats
Requirements
kubectl
is expected to be installed locally.
Currently supported directory structure
repo
source
(subdirectory/)app_1
base
yaml.yml(.j2)
kustomization.yml(.j2)
dev
yaml.yml(.j2)
kustomization.yml(.j2)
prod
yaml.yml(.j2)
kustomization.yml(.j2)
(subdirectory/)app_2
yaml.yml(.j2)
kustomization.yml(.j2)
(subdirectory/)app_3
yaml.yml(.j2)
(subdirectory/)app_4
yaml.yml(.j2)
files
file.json(.j2)
When kustomization overlays are used, kustomization base directory shall be called base
, overlay directories shall be named after the corresponding environments names.
kustomization.yml
Files referenced in the resources
section shall be named after Kubernetes resource type + _
+ resource name. Example:
resources:
- Deployment_nginx.yml
- ServiceAccount_nginx-prod.yml
Initial app-of-apps application
bootstrap
application shall be deployed externally
Variable names
The folloving variable names are resenved:
- __application
Expected variables
The folloving variables are expected to be present:
- argocd.api_server
- argocd.namespace
- argocd.repo_url
- argocd.target_revision
Optional variables
- argocd.sync_policy
- argocd.finalizers
For developers
Build instructions
https://setuptools.pypa.io/en/latest/userguide/quickstart.html https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html https://setuptools.pypa.io/en/latest/userguide/datafiles.html https://packaging.python.org/en/latest/tutorials/packaging-projects/
Preparation
python -m venv .venv
. .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev_requirements.txt
Execution
python main.py --root-dir <path>
Packaging
<change version in pyproject.toml>
python -m build
python -m twine upload dist/*
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
Hashes for make_argocd_fly-0.0.28-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4612654f54033bc1d292922e823177551d29f1444f46dc9cd035acc7ad2d1410 |
|
MD5 | 82a19c3b58155eee798381a345e1e9e1 |
|
BLAKE2b-256 | 1292b9d344bc162fa1f36a25d7ac7baf5917b59ec9c354275c398202f9cf3484 |