Skip to content

Commit

Permalink
feat: Add helm chart
Browse files Browse the repository at this point in the history
Signed-off-by: Joonas Bergius <[email protected]>
  • Loading branch information
joonas committed Mar 29, 2024
1 parent 3fa82d0 commit a4a0035
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: chart

env:
HELM_VERSION: v3.14.0

on:
push:
tags:
- 'chart-v[0-9].[0-9]+.[0-9]+'
pull_request:
paths:
- 'charts/**'
- '.github/workflows/chart.yml'

jobs:
validate:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch main branch for chart-testing
run: |
git fetch origin main:main
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}

# Used by helm chart-testing below
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.12.2'

- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.10.1
yamllint_version: 1.35.1
yamale_version: 5.0.0

- name: Run chart-testing (lint)
run: |
ct lint --config charts/wasmcloud-operator/ct.yaml
- name: Create kind cluster
uses: helm/[email protected]
with:
version: "v0.22.0"

- name: Run chart-testing (install)
run: |
ct install --config charts/wasmcloud-operator/ct.yaml
publish:
if: ${{ startsWith(github.ref, 'refs/tags/chart-v') }}
runs-on: ubuntu-22.04
needs: validate
permissions:
packages: write

steps:
- uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}

- name: Package
run: |
helm package chart -d .helm-charts
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Lowercase the organization name for ghcr.io
run: |
echo "GHCR_REPO_NAMESPACE=${GITHUB_REPOSITORY_OWNER,,}" >>${GITHUB_ENV}
- name: Publish
run: |
for chart in .helm-charts/*; do
if [ -z "${chart:-}" ]; then
break
fi
helm push "${chart}" "oci://ghcr.io/${{ env.GHCR_REPO_NAMESPACE }}"
done
23 changes: 23 additions & 0 deletions charts/wasmcloud-operator/.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/
16 changes: 16 additions & 0 deletions charts/wasmcloud-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v2
name: wasmcloud-operator
description: A Helm chart for deploying the wasmcloud-operator on Kubernetes

type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.1"
3 changes: 3 additions & 0 deletions charts/wasmcloud-operator/ct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
validate-maintainers: false
target-branch: main # TODO: Remove this once chart-testing 3.10.1+ is released
helm-extra-args: --timeout 60s
Empty file.
91 changes: 91 additions & 0 deletions charts/wasmcloud-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "wasmcloud-operator.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 "wasmcloud-operator.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 "wasmcloud-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Namespace that's used for setting up cluster role bindings and such
*/}}
{{- define "wasmcloud-operator.namespace" -}}
{{- default "default" .Release.Namespace }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "wasmcloud-operator.labels" -}}
helm.sh/chart: {{ include "wasmcloud-operator.chart" . }}
{{ include "wasmcloud-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "wasmcloud-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "wasmcloud-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "wasmcloud-operator.service-account" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "wasmcloud-operator.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create the name of the cluster role to use
*/}}
{{- define "wasmcloud-operator.cluster-role" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "wasmcloud-operator.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/*
Create the name of the cluster role binding to use
*/}}
{{- define "wasmcloud-operator.cluster-role-binding" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "wasmcloud-operator.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
106 changes: 106 additions & 0 deletions charts/wasmcloud-operator/templates/cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "wasmcloud-operator.cluster-role" . }}
labels:
{{- include "wasmcloud-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- secrets
- services
- configmaps
- serviceaccounts
verbs:
- get
- list
- watch
- create
- delete
- patch
- update
- apiGroups:
- apps
resources:
- deployments
- daemonsets
verbs:
- get
- list
- watch
- create
- delete
- patch
- update
- apiGroups:
- rbac.authorization.k8s.io
resources:
- rolebindings
- roles
verbs:
- get
- list
- watch
- create
- delete
- patch
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- watch
- create
- delete
- patch
- apiGroups:
- apiregistration.k8s.io
resources:
- apiservices
verbs:
- create
- delete
- get
- list
- patch
- update
- apiGroups:
- k8s.wasmcloud.dev
resources:
- wasmcloudhostconfigs
- wasmcloudhostconfigs/status
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "wasmcloud-operator.cluster-role-binding" . }}
labels:
{{- include "wasmcloud-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "wasmcloud-operator.cluster-role" . }}
subjects:
- apiGroup: ""
kind: ServiceAccount
name: {{ include "wasmcloud-operator.service-account" . }}
namespace: {{ include "wasmcloud-operator.namespace" . }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "wasmcloud-operator.cluster-role-binding" . }}-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- apiGroup: ""
kind: ServiceAccount
name: {{ include "wasmcloud-operator.service-account" . }}
namespace: {{ include "wasmcloud-operator.namespace" . }}
Loading

0 comments on commit a4a0035

Please sign in to comment.