Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

feat(helm): initial try at making a helm chart #62

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions hack/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apiVersion: v2
name: hnc
description: A Helm chart to install hnc on Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on what this is supposed to be. E.g. if we update HNC from v0.8.0 to v0.9.0, should this go from v0.1.0 to v0.2.0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding which could be incorrect:

  • chart version changes when the helm chart itself changes
  • app version changes when the application itself changes

so appVersion should be part of the release process to auto bump it. I guess chart version bumps handled in the PR template as process(?)

Copy link
Contributor

@adrianludwin adrianludwin Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really have an "auto bump" anywhere but it's fine to just document the process and expect the releaser to follow it. That's what we do for the version numbers in our docs.

As for when we increase the minor vs patch version of the chart, I'm happy to just explain it in the comments right here. E.g.: the chart major/minor/patch versions must increment whenever the corresponding app major/minor/patch version changes, but never needs to be the same as those numbers. For example, if we have chart=0.1.0 and app=0.8.0, and we change the app to 0.9.0, we should change the chart to 0.2.0. But if we change it to 0.8.1, we should change the chart to 0.1.1. In addition, we can increment that chart versions for any other reason at any time.


# 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.
appVersion: 0.8.0
66 changes: 66 additions & 0 deletions hack/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of interest, is there a canonical version of this file? If so, it might be useful to link to it in a comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the current latest that gets generated by helm create chart

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah got it. Maybe add a "Generated by 'helm create chart'" comment unless that'll be overwritten in the future?

File gernated by the `helm create` command
*/}}

{{/*
Expand the name of the chart.
*/}}
{{- define "hnc.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 "hnc.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 "hnc.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "hnc.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "hnc.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions hack/helm/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "hnc.fullname" . }}
labels:
{{- include "hnc.labels" . | nindent 4 }}
annotations:
helm.sh/hook: pre-install,post-delete
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- nonResourceURLs:
- '*'
verbs:
- '*'
17 changes: 17 additions & 0 deletions hack/helm/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "hnc.fullname" . }}
labels:
{{- include "hnc.labels" . | nindent 4 }}
annotations:
helm.sh/hook: pre-install,post-delete
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "hnc.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "hnc.fullname" . }}
namespace: {{ .Release.Namespace }}
55 changes: 55 additions & 0 deletions hack/helm/templates/hnc-installation-jobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "hnc.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "hnc.labels" . | nindent 4 }}
annotations:
helm.sh/hook-weight: "1"
helm.sh/hook: pre-install
spec:
template:
spec:
containers:
{{- range .Values.hncExcludeNamespaces }}
- name: labeler-{{ . }}
image: gcr.io/google_containers/hyperkube:v1.9.7
command:
- kubectl
- label
- ns
- {{ . }}
- hnc.x-k8s.io/excluded-namespace=true
- --overwrite
{{- end }}
restartPolicy: Never
serviceAccountName: {{ include "hnc.fullname" . }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: hnc
namespace: {{ .Release.Namespace }}
labels:
{{- include "hnc.labels" . | nindent 4 }}
annotations:
helm.sh/hook-weight: "1"
helm.sh/hook: post-delete
spec:
template:
spec:
containers:
{{- range .Values.hncExcludeNamespaces }}
- name: labeler-{{ . }}
image: gcr.io/google_containers/hyperkube:v1.9.7
command:
- kubectl
- label
- ns
- {{ . }}
- hnc.x-k8s.io/excluded-namespace-
{{- end }}
restartPolicy: Never
serviceAccountName: {{ include "hnc.fullname" . }}
Loading