Connecting the self-hosted runner to Argo CD on the host cluster
Running argocd-diff-preview
on a self-hosted runner on a cluster that has Argo CD pre-installed combines maximum performance with enhanced security. This approach eliminates both cluster creation overhead and the need to store cluster credentials in your CI/CD pipeline.
Instead of creating a temporary cluster for each diff preview, your self-hosted GitHub Actions runner connects directly to a dedicated Argo CD instance running in the same cluster. This offers fast execution (no cluster creation overhead) and enhanced security (no credential sharing).
Imagine something like this:
How It Works
- Install Action Runner Controller (ARC) in your cluster alongside the dedicated Argo CD instance in the namespace
argocd-diff-preview
- The runner uses a service account to connect to the host cluster and access the Argo CD instance
- The tool runs exactly as before, but without any credential management complexity and without creating an ephemeral cluster
Setup Guide
This step-by-step guide walks you through setting up self-hosted runners with an existing Argo CD cluster.
Step 1: Prepare Your Cluster
If you already have a cluster with Argo CD installed, skip to Step 2. Otherwise, create a dedicated cluster:
# Create a kind cluster
kind create cluster --name argocd-diff-preview
# Add Argo CD Helm repository
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
# Install Argo CD
helm install argo-cd argo/argo-cd \
--version 8.0.3 \
--namespace argocd-diff-preview \
--create-namespace
Step 2: Install Action Runner Controller (ARC)
ARC Documentation
This guide may become outdated. For the latest ARC installation instructions, see the official GitHub documentation.
Install the ARC controller and runner scale set to enable self-hosted GitHub Actions runners:
Install the controller:
# Add the ARC Helm repository
helm repo add arc-systems https://actions-runner-controller.github.io/arc
helm repo update
# Install the controller
helm install arc arc-systems/gha-runner-scale-set-controller \
--version 0.12.1 \
--namespace arc-systems \
--create-namespace
Create authentication secret:
First, create a GitHub Personal Access Token (PAT) with repo
scope, then create the secret:
kubectl create secret generic arc-runner-auth \
--namespace arc-runners \
--from-literal=github_token="your-github-token-here"
Or using a YAML file:
apiVersion: v1
kind: Secret
metadata:
name: arc-runner-auth
namespace: arc-runners
type: Opaque
stringData:
github_token: "your-github-token-here"
Install the runner scale set:
Create a configuration file for the runner scale set:
githubConfigUrl: "https://github.com/<org>/<repo>" # Replace with your repo
githubConfigSecret: arc-runner-auth
controllerServiceAccount:
name: arc-gha-rs-controller
namespace: arc-systems
runnerScaleSetName: argocd-diff-runner # This name will be used in workflows
template:
spec:
serviceAccountName: arc-runner
automountServiceAccountToken: true
Install the runner scale set:
# Add the runner scale set Helm repository
helm repo add arc-runners https://actions-runner-controller.github.io/arc
# Install the runner scale set
helm install arc-runner-set arc-runners/gha-runner-scale-set \
--version 0.12.1 \
--namespace arc-runners \
--create-namespace \
-f arc-runner-set.yaml
Step 3: Configure RBAC
The runner service account needs permissions to access Argo CD resources (in the namespace argocd-diff-preview
). Create the following RBAC configuration:
apiVersion: v1
kind: ServiceAccount
metadata:
name: arc-runner
namespace: arc-runners
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: arc-runner-diff-preview
namespace: argocd-diff-preview
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: arc-runner-diff-preview
namespace: argocd-diff-preview
subjects:
- kind: ServiceAccount
name: arc-runner
namespace: arc-runners
roleRef:
kind: Role
name: arc-runner-diff-preview
apiGroup: rbac.authorization.k8s.io
Apply the RBAC configuration:
Usage
Step 4: Create GitHub Actions Workflow
Now create a workflow that uses your self-hosted runner. There are two approaches: using the binary directly or using Docker.
Option A: Using the Binary (Recommended)
This approach installs the argocd-diff-preview
binary directly on the runner:
Key configuration points:
runs-on: argocd-diff-runner
- Must match yourrunnerScaleSetName
from Step 2--argocd-namespace=argocd-diff-preview
- Change if your Argo CD uses a different namespace--create-cluster=false
- Critical flag that tells the tool to use a pre-provisioned cluster
Option B: Using Docker
If you prefer to use the Docker image (requires Docker installed on runner pods):
- name: Generate Diff
run: |
docker run \
--network host \
-v ~/.kube:/root/.kube \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd)/output:/output \
-v $(pwd)/base-branch:/base-branch \
-v $(pwd)/target-branch:/target-branch \
-e TARGET_BRANCH=refs/pull/${{ github.event.number }}/merge \
-e REPO=${{ github.repository }} \
dagandersen/argocd-diff-preview:v0.1.18 \
--argocd-namespace=argocd-diff-preview \
--create-cluster=false
Important Docker considerations:
--network host
- Allows the container to access the cluster using the runner's network-v ~/.kube:/root/.kube
- Mounts kubeconfig for cluster access-v /var/run/docker.sock:/var/run/docker.sock
- Required if using Docker-in-Docker features- Docker must be installed and accessible on the runner pods
Expected Output
When the workflow runs successfully, you'll see output similar to this in your GitHub Actions logs:
โจ Running with:
โจ - reusing cluster with Argo CD pre-installed
โจ - base-branch: main
โจ - target-branch: refs/pull/123/merge
โจ - output-folder: ./output
โจ - argocd-namespace: argocd-diff-runner
โจ - repo: your-org/your-repo
โจ - timeout: 180 seconds
๐ Unique ID for this run: 60993
๐ค Fetching all files for branch (branch: main)
๐ค Found 52 files in dir base-branch (branch: main)
...
๐ฆ Logging in to Argo CD through CLI...
๐ฆ Logged in to Argo CD successfully
๐ค Converting ApplicationSets to Applications in both branches
...
๐ค Patching 19 Applications (branch: main)
๐ค Patching 19 Applications (branch: refs/pull/123/merge)
๐ค Rendered 11 out of 38 applications (timeout in 175 seconds)
๐งผ Waiting for all application deletions to complete...
๐งผ All application deletions completed
๐ค Got all resources from 19 applications from base-branch and got 19 from target-branch in 7s
๐ฎ Generating diff between main and refs/pull/123/merge
๐ Please check the ./output/diff.md file for differences
โจ Total execution time: 10s