Skip to content

Commit

Permalink
Merge pull request #8 from karlderkaefer/add-helm-chart
Browse files Browse the repository at this point in the history
feat: add initial helm chart
  • Loading branch information
karlderkaefer authored Nov 7, 2022
2 parents f57de67 + 726a12f commit f0b335b
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
# depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions
# see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
31 changes: 31 additions & 0 deletions .github/workflows/helm-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: helm-test
on:
pull_request:
branches:
- main
paths:
- charts/**
- .github/workflows/helm-test.yaml

permissions: read-all

jobs:
helm-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0

- name: Unshallow
run: git fetch --prune --unshallow

- uses: actions/setup-python@f38219332975fe8f9c04cca981d674bf22aea1d3 # v2.3.1
with:
python-version: 3.7

- name: Set up chart-testing
uses: helm/chart-testing-action@b0d4458c71155b54fcf33e11dd465dc923550009 # v2.0.1

- name: Run chart-testing (lint)
# run: ct lint --target-branch=main --check-version-increment=false
run: ct lint --check-version-increment=false --charts charts/argocd-ecr-updater
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ COPY . .
RUN CGO_ENABLED=0 go build -o /bin/argocd-ecr-updater

FROM gcr.io/distroless/base-debian11
EXPOSE 8080
WORKDIR /app
COPY --from=BASE /bin/argocd-ecr-updater .
CMD ["./argocd-ecr-updater"]
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ArgoCD ECR updater

If you are using a private [AWS ECR repository](https://docs.aws.amazon.com/AmazonECR/latest/userguide/push-oci-artifact.html)
to store helm charts, the stored password will become at latest in `12h`.
to store helm charts, the stored password will become expired at latest in `12h`.
The argocd-ecr-updater will refresh the token in defined interval.

The updater will only consider secrets with these labels for update.
Expand All @@ -14,6 +14,33 @@ metadata:
```
The data field `password` will be updated with a fresh token from AWS ECR.

To give ArgoCD permission to get the ECR token create [IRSA role](https://github.com/terraform-aws-modules/terraform-aws-iam/tree/v5.5.5/modules/iam-assumable-role-with-oidc) with following permissions
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:DescribeRepositories"
],
"Resource": "*"
}
]
}
```
This token is valid to authenticate against any registry id, the user has access.
Depending on how you set the trust relationship on ECR repository policy.

Finally annotate the service account with your role arn
```yaml
serviceAccount:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::123456:role/argocd-ecr-updater
```

## Usage CLI
```bash
Usage:
Expand All @@ -29,6 +56,13 @@ Flags:
* `--interval`: defined in which interval the token will refreshed
* `--namespace`: if empty, then mutate secrets from all namespaces matching the label

You can also set these values by providing environment variable with prefix `ARGOCD_ECR_UPDATER`
```bash
ARGOCD_ECR_UPDATER_NAMESPACE="argocd"
ARGOCD_ECR_UPDATER_INTERVAL="6h0m0s"
ARGOCD_ECR_UPDATER_KUBECONFIG="/home/user/.kube/config"
```

## Related GitHub Issues
* https://github.com/argoproj/argo-cd/issues/8097
* https://github.com/argoproj/argo-cd/issues/8952
23 changes: 23 additions & 0 deletions charts/argocd-ecr-updater/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
11 changes: 11 additions & 0 deletions charts/argocd-ecr-updater/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: argocd-ecr-updater
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "main"
sources:
- https://github.com/karlderkaefer/argocd-ecr-update
maintainers:
- name: karlderkaefer
url: https://github.com/karlderkaefer/argocd-ecr-update
62 changes: 62 additions & 0 deletions charts/argocd-ecr-updater/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "argocd-ecr-updater.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "argocd-ecr-updater.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "argocd-ecr-updater.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "argocd-ecr-updater.labels" -}}
helm.sh/chart: {{ include "argocd-ecr-updater.chart" . }}
{{ include "argocd-ecr-updater.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "argocd-ecr-updater.selectorLabels" -}}
app.kubernetes.io/name: {{ include "argocd-ecr-updater.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "argocd-ecr-updater.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "argocd-ecr-updater.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
67 changes: 67 additions & 0 deletions charts/argocd-ecr-updater/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "argocd-ecr-updater.fullname" . }}
labels:
{{- include "argocd-ecr-updater.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "argocd-ecr-updater.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "argocd-ecr-updater.selectorLabels" . | nindent 8 }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "argocd-ecr-updater.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.containerSecurityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: ARGOCD_ECR_UPDATER_NAMESPACE
value: {{ .Values.namespace }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 30
readinessProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 30
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/argocd-ecr-updater/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.rbac.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "argocd-ecr-updater.fullname" . }}
labels:
{{- include "argocd-ecr-updater.labels" . | nindent 4 }}
rules:
- apiGroups:
- ''
resources:
- secrets
verbs:
- get
- list
- watch
- patch
- update
{{- end }}
15 changes: 15 additions & 0 deletions charts/argocd-ecr-updater/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.rbac.enabled }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "argocd-ecr-updater.fullname" . }}
labels:
{{- include "argocd-ecr-updater.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "argocd-ecr-updater.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "argocd-ecr-updater.fullname" . }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/argocd-ecr-updater/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "argocd-ecr-updater.serviceAccountName" . }}
labels:
{{- include "argocd-ecr-updater.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit f0b335b

Please sign in to comment.