ArgoCD, Jsonnet and Tanka in 2024


A few years ago, I got to know Jsonnet and I loved it at first sight. I used a nice little tool called tanka to manage my Jsonnet manifests and I got them working together with ArgoCD, and finally I re-deployed my blog using this combo. Everything worked like a charm, until…

Recently I upgraded my ArgoCD to the latest(2.9.3 at this moment) and suddenly my blog is in unknown state. I almost panicked. After some searching and reading, so the good old ways ArgoCD handling plugins have been deprecated and finally removed since version 2.8. In the linked doc there’s also a path for upgrading, so here we go.

First, the tanka plugin will have its own plugin.yaml, which will be mounted to the plugin’s sidecar container via a ConfigMap. The init and generate parts look very familiar, only I need pay attention to the changed path – now plugin executables will be in /home/argocd/cmp-server/plugins directory.

apiVersion: argoproj.io/v1alpha1
kind: ConfigManagementPlugin
metadata:
  name: tanka
  namespace: argocd

spec:
  version: v0.25.0
  init:
    command: [ "sh", "-c", "/home/argocd/cmp-server/plugins/jb install" ]
  generate:
    command: [ "sh", "-c", "/home/argocd/cmp-server/plugins/tk show environments/${ARGOCD_ENV_TK_ENV} --dangerous-allow-redirect" ]
  discover:
    fileName: "./environments/*/main.jsonnet"

The next step is to create a sidecar container, which can install the needed jb and tk binaries at the /home/argocd/cmp-server/plugins location, then according to the specification it will run the argocd-cmp-server binary to integrate it into the argocd-repo-server. I use kustomize for my ArgoCD manifests so this will be a patch file for the extra container:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: argocd-repo-server
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-repo-server
  template:
    metadata:
      labels:
        app.kubernetes.io/name: argocd-repo-server
    spec:
      containers:
      # for tanka plugin
      - name: cmp
        image: curlimages/curl:latest
        # install jb and tk then start the argocd-cmp-server
        command:
          - sh
          - -c
          - |
            cd /home/argocd/cmp-server/plugins && \
            curl -Lo jb "https://github.com/jsonnet-bundler/jsonnet-bundler/releases/download/v0.5.1/jb-linux-amd64" && \
            curl -Lo tk "https://github.com/grafana/tanka/releases/download/v0.25.0/tk-linux-amd64" && \
            chmod +x jb tk && \
            /var/run/argocd/argocd-cmp-server
        securityContext:
          runAsNonRoot: true
          runAsUser: 999
        volumeMounts:
          - mountPath: /var/run/argocd
            name: var-files
          - mountPath: /home/argocd/cmp-server/plugins
            name: plugins
          - mountPath: /home/argocd/cmp-server/config/plugin.yaml
            subPath: plugin.yaml
            name: cmp-tanka
      volumes:
      # configMap containing the plugin.yaml
      - name: cmp-tanka
        configMap:
          name: cmp-tanka
          
# other customisations of argo can also be here 

Finally, let’s put things together in kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: argocd

# argocd manifest can be found at https://argo-cd.readthedocs.io/en/stable/getting_started/#1-install-argo-cd
resources:
  - upstream.yaml

# a configMap containing the plugin.yaml file
configMapGenerator:
  - name: cmp-tanka
    files:
      - plugin.yaml

patches:
  - path: patch.yaml

After I re-deployed ArgoCD with the above enhancements, sadly, my blog was still in unknown state. ArgoCD complains: plugin named tanka not found, which is not very helpful. I had a look at the official guide again and it’s just 1 thing I missed, in the argo application:

apiVersion: argoproj.io/v1alpha1
kind: Application
...
spec:
...
    targetRevision: HEAD
    plugin:
      name: tanka # <--- this line is no longer needed
      env:
        - name: TK_ENV
          value: raynix

It now works without that line 🙂

Ref.
https://argo-cd.readthedocs.io/en/stable/operator-manual/config-management-plugins/
https://hodovi.cc/blog/gitops-argocd-and-tanka/