Skip to content

Commit

Permalink
feat: add qemu-guest-agent helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
robinelfrink committed Aug 12, 2022
1 parent f523f6f commit b554720
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 16 deletions.
69 changes: 56 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@ name: Release

on:
push:
paths:
- .github/workflows/release.yml
- Dockerfile
branches:
- main

jobs:
release:
name: Release

tag:
name: Bump tag
runs-on: ubuntu-latest
outputs:
changelog: ${{ steps.tag.outputs.changelog }}
version: ${{ steps.tag.outputs.new_version }}
tag: ${{ steps.tag.outputs.new_tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Bump version and tag
uses: mathieudutour/github-tag-action@v6.0
id: version
id: tag
with:
github_token: ${{ secrets.github_token }}

container:
name: Build and push container
runs-on: ubuntu-latest
needs: tag
steps:
- name: Checkout
uses: actions/checkout@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true
fetch-depth: 0
- name: Name
uses: ashley-taylor/regex-property-action@1.2
id: name
Expand All @@ -35,20 +46,52 @@ jobs:
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ secrets.github_token }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: |
ghcr.io/${{ steps.name.outputs.value }}:${{ steps.version.outputs.new_tag }}
ghcr.io/${{ steps.name.outputs.value }}:${{ needs.tag.outputs.tag }}
ghcr.io/${{ steps.name.outputs.value }}:latest
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ needs.tag.outputs.tag }}
org.opencontainers.image.revision=${{ github.sha }}
chart:
name: Publish chart
runs-on: ubuntu-latest
needs: tag
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Name
id: name
run: echo "::set-output name=chart::$(ls charts/)"
- name: Publish chart
uses: stefanprodan/helm-gh-pages@v1.5.0
with:
token: ${{ secrets.github_token }}
app_version: ${{ needs.tag.outputs.tag }}
chart_version: ${{ needs.tag.outputs.version }}

release:
name: Create tag and release
runs-on: ubuntu-latest
needs:
- tag
- container
- chart
steps:
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.version.outputs.new_tag }}
name: Release ${{ steps.version.outputs.new_tag }}
body: ${{ steps.version.outputs.changelog }}
tag: ${{ needs.tag.outputs.tag }}
name: Release ${{ needs.tag.outputs.tag }}
body: ${{ needs.tag.outputs.changelog }}
47 changes: 44 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Test
name: Test

on: pull_request

jobs:
test:
name: Test

build:
name: Build container
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -19,4 +20,44 @@ jobs:
tags: |
ghcr.io/test:test
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
lint:
name: Lint Helm chart
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.9.2
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.2.1
- name: Run chart-testing
run: ct lint --all --check-version-increment=false --target-branch ${{ github.event.pull_request.base.ref }}

unittest:
name: Run chart unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.9.2
- name: Run unit tests
run: |
helm plugin install https://github.com/quintush/helm-unittest
for chart in charts/*; do
helm unittest --helm3 ${chart}
done
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ docker-compose up --detach qemu-guest-agent
kubectl apply --filename \
https://raw.githubusercontent.com/robinelfrink/docker-qemu-guest-agent/main/manifests/daemonset.yaml
```

## Kubernetes Helm chart

See [charts/qemu-guest-agent/README.md](charts/qemu-guest-agent/README.md) how
to install `qemu-guest-agent` using [Helm](https://helm.sh/).
23 changes: 23 additions & 0 deletions charts/qemu-guest-agent/.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/
10 changes: 10 additions & 0 deletions charts/qemu-guest-agent/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: qemu-guest-agent
description: A Helm chart for qemu-guest-agent
type: application
version: 0.0.0
appVersion: "v0.0.0"
home: https://github.com/robinelfrink/docker-qemu-guest-agent
icon: https://gitlab.com/qemu-project/qemu/-/raw/master/ui/icons/qemu.svg
maintainers:
- name: robinelfrink
33 changes: 33 additions & 0 deletions charts/qemu-guest-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# QEMU Guest Agent

Guest-side qemu-system agent

This chart installs the QEMU guest agent as a `DaemonSet` on all nodes on a
[Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

## Add Chart Repository

```console
helm repo add qemu-guest-agent https://robinelfrink.github.io/docker-qemu-guest-agent
```

## Install Chart

```console
helm install qemu-guest-agent qemu-guest-agent/qemu-guest-agent
```

## Uninstall Chart

```console
helm uninstall qemu-guest-agent
```

This removes all the Kubernetes components associated with the chart and deletes the release.

## Upgrading Chart

```console
helm upgrade qemu-guest-agent qemu-guest-agent/qemu-guest-agent
```

1 change: 1 addition & 0 deletions charts/qemu-guest-agent/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Congratulations, qemu-guest-agent has been installed.
62 changes: 62 additions & 0 deletions charts/qemu-guest-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "qemu-guest-agent.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 "qemu-guest-agent.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 "qemu-guest-agent.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "qemu-guest-agent.selectorLabels" -}}
app.kubernetes.io/name: {{ include "qemu-guest-agent.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "qemu-guest-agent.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "qemu-guest-agent.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
56 changes: 56 additions & 0 deletions charts/qemu-guest-agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "qemu-guest-agent.fullname" . }}
labels:
{{- include "qemu-guest-agent.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "qemu-guest-agent.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "qemu-guest-agent.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "qemu-guest-agent.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- mountPath: /dev/virtio-ports/org.qemu.guest_agent.0
name: virtio-port
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
volumes:
- name: virtio-port
hostPath:
path: /dev/virtio-ports/org.qemu.guest_agent.0
12 changes: 12 additions & 0 deletions charts/qemu-guest-agent/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 "qemu-guest-agent.serviceAccountName" . }}
labels:
{{- include "qemu-guest-agent.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/qemu-guest-agent/tests/daemonset_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
suite: qemu-guest-agent
templates:
- daemonset.yaml
tests:
- it: should pass
release:
name: qemu-guest-agent
namespace: kube-system
asserts:
- hasDocuments:
count: 1
- isAPIVersion:
of: apps/v1
- isKind:
of: DaemonSet
- equal:
path: metadata.name
value: qemu-guest-agent
Loading

0 comments on commit b554720

Please sign in to comment.