Skip to content

An ArgoCD Plugin Generator application and deployment to support application deployment patterns

Notifications You must be signed in to change notification settings

tal-hason/argocd-plugin-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArgoCD Plugin Generator example

Argo

ArgoCD Plugin Generator Operator Page


What you need to make it work


Please Fork this repo and update/change it to fit your deployment and needs

the Application generated from the ApplicationSet can be found here, please also fork

What we have here

Let's explian nodeJS folder

under it, we have:

  • src folder, with the app.js file that contains our web application server
  • src/config, here we store a default app.yaml file with basic config
  • argocd-plugin-app.postman_collection.json, Postman Collection to assist with testing the POST request.
  • automation.sh, script to assist with build, test, and push the application image.
  • Dockerfile, a Multi-stage Docker file to build the application container image.

Automation.sh file will make the working of running podman build/run/push more easy

The script accepts 2 running arguments the 1st is the commit message, and the 2nd is the desired operation

  • test, this will build and run the application image
  • push, this will build and push the application image to the image registry, after it prompts to either update the HELM chart values file or not with the new image tag. to work with the file create an environment variable named IMAGE_NAME with your image.registry/repo_name/image, if you forget the script will ask you for the image name in the first run.

Dockerfile

the Docker file builds the application based on the registry.access.redhat.com/ubi9/nodejs-18 as builder and registry.access.redhat.com/ubi9/nodejs-18-minimal as the final running container.

During the build it will create a default token for the argocd plugin with 12345678 as its value.

Swagger-UI

The application exposes Swagger-UI at the /api-docs (i.e. https://plugin-argo-plugin-openshift-gitops.apps-crc.testing/api-docs). To be able to see the JSON of the Web Application you need to authorize the Swagger with the Auto-Generated token from the application secret

To Get the secret:

oc get secrets plugin-argocd-app-set-plugin-token -n openshift-gitops -o yaml | yq eval '.data.token' | base64 -d

After you have the Secret Click Authorize Button on the top right of the screen Swagger

After clicking it a pop-up menu will open there enter the token from the secret login

Now you can see your plugin generator Payload converted to JSON.


GitOps Folder

Under our GItops Folder, we find 2 Sub Folders:

  • Argo-Plugin, Holds our HELM Chart with its values file to deploy our plugin web-application
  • ArgoApps, Holds all our argoCD objects with kustomaized.

Argo-Plugin Folder

Please read the README file to under stand the Chart

Some Tricks and Tips

Folders:

  • Certificates, paste your domain Certificate and it will be added to the route that will be generated by the ingress.
  • ApplcaitionFiles, This is the MOST Importent folder, under it we will put our app{n}.yaml files like the following, the application support multiple config files(i.e. batman.yaml, robin.yaml ,joker.yaml ...), and will merge them to single JSON Paylod:

example:

batman.yaml

GenerateApplication:
  name: batman
  project: gotham-demo
  image: quay.io/gotham/batman
  tag: 4a7050d
  repoURL: https://github.com
  branch: main
  gitopsRepo: gotham-cd

each new Object in the GenerateApplication key will generate an Argo application via the application Set you can add more or even change the schema, just adept the ApplicationSet.

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: plugin-applicationset
  namespace: openshift-gitops
spec:
  generators:
    - plugin:
        configMapRef:
          name: plugin-config
        requeueAfterSeconds: 30
  template:
    metadata:
      name: "{{name}}-{{project}}"
    spec:
      project: argocd-plugin
      source:
        helm:
          valueFiles:
            - '{{project}}/develop/values-{{name}}.yaml'
          parameters:
            - name: "image.name"
              value: '{{image}}'
            - name: "image.tag"
              value: '{{tag}}'
            - name: "global.namespace"
              value: 'plugin-test'
        repoURL: '{{repoURL}}/{{project}}/{{gitopsRepo}}.git'
        targetRevision: '{{branch}}'
        path: Application
      destination:
        server: https://kubernetes.default.svc
        namespace: plugin-test
      syncPolicy:
        automated:
          prune: true
          selfHeal: true
        syncOptions:
          - CreateNamespace=true
  • {{name}} - this is the name object from each item in the GenerateApplication array. (i.e. the name of the application or whatever you think is relevant)
  • {{project}} - this is the project object from each item in the GenerateApplication array. (i.e. the organization name in GitHub)
  • {{image}} - this is the image object from each item in the GenerateApplication array. (i.e. quay.io/gotham/batman)
  • {{tag}} - this is the tag object from each item in the GenerateApplication array. (i.e. v1.0.1)
  • {{repoURL}} - this is the repoURL object from each item in the GenerateApplication array (i.e. http://www.github.com).
  • {{branch}} - this is the branch object from each item in the GenerateApplication array. (i.e. the branch name for the GitOps Repo)
  • {{gitopsRepo}} - this is the gitopsRepo object from each item in the GenerateApplication array. (i.e. the Repository name for the GitOps Repo)

All those fields are for my example you can create any fields you want or need just remember they all have to be consistent in all the files.

Secrets: we have 2 secrets in the template:

  1. secret-ca-cert.yaml, which will be generate with the ingress (i.e. deploy.ingress.enabled=true)
  2. header-secret.yaml, this secret auto-generate the bearer Token for the web application and the application set
apiVersion: v1
kind: Secret
metadata:
  name: 'argocd-app-set-plugin-token'
  labels:
    {{- include "app.labels" . | nindent 4 }}
    app.kubernetes.io/part-of: argocd
  annotations:
    helm.sh/hook: "pre-install"
    helm.sh/hook-delete-policy: "before-hook-creation"
type: Opaque
data:
  token: '{{ randAlphaNum 14 | b64enc }}'

Notes:

  • the secret will generate a new token each time a new commit is created, so always double-check your token if you testing with the swagger of Postman
  • if the Secret has been changed the Deployment will rollout and reload the new token. The name of the token is part of the plugin config in the ConfigMap plugin-config

ArgoApps Folder

Under the ArgoApps folder have the following:

  • Plugin folder, that holds the plugin Argo Application that directs to the git repo to the HELM Chart folder.
  • Project.yaml, an Argo Project.
  • AppofApps.yaml, An app of apps application to bootstrap the plugin and application set
  • kustomization.yaml, an easy way to deploy all YAMLs in one command.

after we have installed all our needed tools Here to bootstrap the plugin generator just run the following command, from the root of the repo:

oc apply -k GitOps/ArgoApps 

this will install the Argo Project and the app of apps and then the Plugin application and the applicationSet

Argo-UI


To create multiple schema support

  • you need to duplicate the Argo-Plugin folder under GitOps Folder, rename it
  • update the Chart.yaml with the new folder name under name:
  • Under ArgoApps/Plugin Duplicate the ApplicationSet-Plugin.yaml and the Plugin-Application.yaml, rename them, and update the paths to your new plugin deployment under GitOps folder.
  • update the values.yaml file under you new created folder with golbal.serviceName={new name}
  • In the application set adjust the template to the new schema that you apply in the new config files, and update the config name to the new config, ConfigMap name (Tip: the configMap name has the service name at the beginning)
  • sync the app of apps and a new plugin will be created with a new applicationSet

Please Feel free to Open Issues or Create Pull request for any features

About

An ArgoCD Plugin Generator application and deployment to support application deployment patterns

Topics

Resources

Stars

Watchers

Forks