Package: make-argocd-fly
Descriptionmake-argocd-flyis a tool to generate Kubernetes manifests that can be deployed with ArgoCD in a multi cluster environments. It makes it easier to develop and maintain ArgoCD applications by providing a way to render Jinja2 and Kustomize files, run yaml and kube linters and automatically generate ArgoCDApplicationresources.The idea is that you write your resources in YAML, Jinja2 or Kustomize (including helmCharts), write a configuration file that describes where to deploy then and then runmake-argocd-flyto generate the final manifests. This way it is transparent what is being deployed and where, it is easier to maintain and develop the resources and it is easier to debug them.FeaturesJinja2 and Kustomize renderingArgoCDApplicationresources are generated automaticallyApp-of-appspattern is natively supportedUseincludeorinclude_rawin Jinja2 templates to render content of external filesGlobal, per environment and per application Jinja2 variablesSource resources can reside in subdirectoriesUsagepython3 -m venv .venv
. .venv/bin/activate
pip install make-argocd-fly

make-argocd-flyConfigurationconfig.ymlExample: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_3With this configuration file you can have kustomize overlays fordev/prodand use jinja2 variables like{{ var_1.var_2 }} and {{ var_3 }}in your source files.app parametersapp_deployer- name of the application that will deploy this applicationproject- ArgoCD project namedestination_namespace- namespace where the application will be deployedapp_deployer_env- (OPTIONAL) environment of the application that will deploy this applicationvars- (OPTIONAL) application specific jinja2 variablesJinja2 extensionsTo include an external template in a jinja2 template, use the following block:{%- filter indent(width=4) %}
{% include 'app_4/files/file.json.j2' %}
{% 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/CaveatsRequirementskustomizeis expected to be installed locally.kube-linteris expected to be installed locally (https://github.com/stackrox/kube-linter).libyamlis expected to be installed locally for speeding up YAMLs generation.
Comments are not rendered in the final output manifests.Currently supported directory structurerepo
  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 namedbase, overlay directories shall be named after the corresponding environments names.kustomization.ymlFiles referenced in theresourcessection shall be named after Kubernetes resource type +_+ resource name. Example:resources:
  - Deployment_nginx.yml
  - ServiceAccount_nginx-prod.ymlInitial app-of-apps applicationbootstrapapplication shall be deployed externallyVariable namesThe folloving variable names are resenved:__applicationExpected variablesThe folloving variables are expected to be present:argocd.api_serverargocd.namespaceargocd.repo_urlargocd.target_revisionOptional variablesargocd.sync_policyargocd.finalizersargocd.ignoreDifferencesFor developersBuild instructionshttps://setuptools.pypa.io/en/latest/userguide/quickstart.htmlhttps://setuptools.pypa.io/en/latest/userguide/pyproject_config.htmlhttps://setuptools.pypa.io/en/latest/userguide/datafiles.htmlhttps://packaging.python.org/en/latest/tutorials/packaging-projects/https://packaging.python.org/en/latest/guides/single-sourcing-package-version/#single-sourcing-the-versionhttps://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/Preparationpython -m venv .venv
. .venv/bin/activate
python3 -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev_requirements.txtExecutionpython main.py --root-dir <path>Packaging<tag HEAD>
python -m build
python -m twine upload  dist/*Profilingpython -m cProfile -o profile.pstats main.py --root-dir <path>
gprof2dot log.pstats [-z <function>] | dot -Tsvg -o profile.svg