Automatically Updating Helm Charts Referenced by Argo CD with Renovate
Tags: argocd, renovate, devops, kubernetes
Published: 2023-05-04 12:48:58

**You can define it more easily in the new article.**

{% embed https://dev.to/corrupt952/automatically-updating-helm-chart-referenced-in-argo-cd-using-renovate-part-2-37nb %}

## Introduction

The manifests repo for my home k8s cluster, [home-apps](https://github.com/corrupt952/home-apps), is managed by Argo CD, and each application creates resources using Helm Charts.

However, it is a hassle to manually update them during updates.  
Therefore, I will use Renovate to automate the updates.

## Setting up Renovate

You can automatically update applications using Renovate.

Refer to the official documentation to set up Renovate.

{% embed https://docs.renovatebot.com/getting-started/installing-onboarding/ %}

You will need to:

1. Install and configure Renovate's GitHub App
2. Merge the PR for the added Renovate configuration file

Once installed, you can check it on [Renovate's dashboard](https://app.renovatebot.com/dashboard).

![menda renovate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x90ji6lowbo39azwhc8s.png)

## Manifest Configuration

Before moving on to automatic upgrades, let me briefly introduce the configuration of the manifests repo.
Each manifest in the repo is configured as follows.

```sh
argocd-config
└── base
    ├── argocd.yaml
    ├── ingress-nginx.yaml
    ├── kustomization.yaml
    ├── metallb.yaml
    └── sealed-secrets.yaml
```

Each file defines resources using Helm Charts.
The following is an excerpt from `argocd.yaml`.

```yaml
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: argocd
spec:
  ...
  source:
    chart: argo-cd
    repoURL: https://argoproj.github.io/argo-helm
    targetRevision: 5.31.0
    helm:
    ...
```

## Automatic Upgrade

You can use Renovate's regexManagers to upgrade.

I don't like to write regexManagers for each application, so I specify the target repository and the release tag format as follows.

```yaml
targetRevision: 5.31.0 # renovate: depName=argoproj/argo-helm extractVersion=^argo-cd-(?<version>.+)$
```

- Target repository
- Release tag format

Specify them as Renovate's update targets.

### Release Tag Format

Since many Helm Charts managed by each repository have a prefix, the release tag of each repository contains not only the version string specified in targetRevision, but also a prefix.

The format of the release tags for each repository is as follows.

- [Argo CD](https://github.com/argoproj/argo-helm/releases) … `argo-cd-{VERSION}`
- [Ingress NGINX Controller](https://github.com/kubernetes/ingress-nginx/releases) … `helm-chart-{VERSION}`
- [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets/releases) … `helm-v{VERSION}`
- [MetalLB](https://github.com/metallb/metallb/releases) … `metallb-chart-{VERSION}`

### Define regexManagers

Based on this information, define regexManagers.

```javascript
  "regexManagers": [
    {
      "datasourceTemplate": "github-releases",
      "fileMatch": [
        "argocd-config/base/.*\\.yaml"
      ],
      "matchStrings": [
        " +targetRevision: +(?<currentValue>[^'\" ]+) +# renovate: depName=(?<depName>[^ \\n]+) +(extractVersion=(?<extractVersion>[^\\n]+))?",
      ],
    },
  ]
```

Simply adding this definition will make the version of the Helm Charts in the manifest automatically updated.

### Created PRs

The following PRs were created by the regexManagers defined this time and became as expected.

{% github https://github.com/corrupt952/home-apps/pull/24 %}

{% github https://github.com/corrupt952/home-apps/pull/23 %}

{% github https://github.com/corrupt952/home-apps/pull/22 %}

{% github https://github.com/corrupt952/home-apps/pull/21 %}

## Conclusion

Those were the steps to automatically update the Argo CD application with Renovate.

You can use this for other things, so please try it out.

## Reference

I referred to aqua-renovate-config for the definition of regexManagers.

https://github.com/aquaproj/aqua-renovate-config/blob/2f978289de753b39cb1053dc8ca44e0d6e911640/base.json

{% github https://github.com/aquaproj/aqua-renovate-config %}