Skip to content

Commit

Permalink
Initial helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
mkilchhofer committed Feb 2, 2021
1 parent 00aa799 commit 93bb3a3
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 0 deletions.
6 changes: 6 additions & 0 deletions deploy/helm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.tgz
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions deploy/helm/.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/
6 changes: 6 additions & 0 deletions deploy/helm/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: https://charts.bitnami.com/bitnami
version: 10.2.0
digest: sha256:ffc74acdb2350c12e199b3cf080130440bb1e137d1cf10dec1fbdbe597d40510
generated: "2021-01-27T22:09:53.941520746+01:00"
21 changes: 21 additions & 0 deletions deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: nebraska
description: Nebraska is an update manager for Flatcar Container Linux.
type: application
keywords:
- nebraska
- kinvolk
- CoreOS
- update manager
- updates
- Omaha protocol
- flatcar
- Flatcar Container Linux
version: 0.1.0
appVersion: "2.3.0"

dependencies:
- name: postgresql
version: 10.2.6
repository: https://charts.bitnami.com/bitnami
condition: postgresql.enabled
20 changes: 20 additions & 0 deletions deploy/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "nebraska.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nebraska.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nebraska.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "nebraska.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
75 changes: 75 additions & 0 deletions deploy/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "nebraska.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 "nebraska.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 "nebraska.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "nebraska.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "nebraska.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create a default fully qualified postgresql name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "nebraska.postgresql.fullname" -}}
{{- $name := default "postgresql" .Values.postgresql.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "nebraska.ingressScheme" -}}
http{{ if $.Values.ingress.tls }}s{{ end }}
{{- end -}}
161 changes: 161 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nebraska.fullname" . }}
labels:
{{- include "nebraska.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "nebraska.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "nebraska.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "nebraska.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- "/nebraska/nebraska"
args:
{{- /* General settings */}}
{{- if .Values.config.app.title }}
- "-client-title={{ .Values.config.app.title }}"
{{- end }}
{{- if .Values.config.app.logoPath }}
- "-client-logo={{ .Values.config.app.logoPath }}"
{{- end }}
{{- if .Values.config.app.headerStyle }}
- "-client-header-style={{ .Values.config.app.headerStyle }}"
{{- end }}
{{- if .Values.config.app.httpStaticDir }}
- "-http-static-dir={{ .Values.config.app.httpStaticDir }}"
{{- end }}

{{- /* Syncer settings */}}
{{- if .Values.config.syncer.enabled }}
- "-enable-syncer"
{{- if .Values.config.syncer.interval }}
- "-sync-interval={{ .Values.config.syncer.interval }}"
{{- end }}
{{- if .Values.config.syncer.updateURL }}
- "-sync-update-url={{ .Values.config.syncer.updateURL }}"
{{- end }}
{{- end }}

{{- /* Host packages settings */}}
{{- if .Values.config.hostFlatcarPackages.enabled }}
- "-host-flatcar-packages"
- "-flatcar-packages-path={{ required "A valid 'packagesPath' is required when hosting Flatcar packages." .Values.config.hostFlatcarPackages.packagesPath }}"
{{- if .Values.ingress.enabled }}
- "-nebraska-url={{ printf "%s://%s" (include "nebraska.ingressScheme" .) (index .Values.ingress.hosts 0) }}"
{{- else if .Values.config.hostFlatcarPackages.nebraskaURL }}
- "-nebraska-url={{ .Values.config.hostFlatcarPackages.nebraskaURL }}"
{{- end }}
{{- end }}

{{- /* Auth settings */}}
{{- if .Values.config.auth.mode }}
- "-auth-mode={{ .Values.config.auth.mode }}"
{{- end }}
{{- if and .Values.config.auth.github.readWriteTeams (not (eq .Values.config.auth.mode "noop")) }}
- "-gh-rw-teams={{ .Values.config.auth.github.readWriteTeams }}"
{{- end }}
{{- if and .Values.config.auth.github.readOnlyTeams (not (eq .Values.config.auth.mode "noop")) }}
- "-gh-ro-teams={{ .Values.config.auth.github.readOnlyTeams }}"
{{- end }}
env:
- name: NEBRASKA_DB_URL
valueFrom:
secretKeyRef:
name: {{ include "nebraska.fullname" . }}
key: dbURL
{{- if or (eq .Values.config.auth.mode "github") (not .Values.config.auth.mode) }}
- name: "NEBRASKA_GITHUB_OAUTH_CLIENT_ID"
value: "{{ .Values.config.auth.github.clientID }}"
- name: "NEBRASKA_GITHUB_OAUTH_CLIENT_SECRET"
valueFrom:
secretKeyRef:
name: {{ include "nebraska.fullname" . }}
key: ghClientSecret
- name: "NEBRASKA_GITHUB_SESSION_SECRET"
valueFrom:
secretKeyRef:
name: {{ include "nebraska.fullname" . }}
key: ghSessionAuthKey
- name: "NEBRASKA_GITHUB_SESSION_CRYPT_KEY"
valueFrom:
secretKeyRef:
name: {{ include "nebraska.fullname" . }}
key: ghSessionCryptKey
- name: "NEBRASKA_GITHUB_WEBHOOK_SECRET"
valueFrom:
secretKeyRef:
name: {{ include "nebraska.fullname" . }}
key: ghWebhookSecret
{{- if .Values.config.auth.github.enterpriseURL }}
- name: "NEBRASKA_GITHUB_ENTERPRISE_URL"
value: "{{ .Values.config.auth.github.enterpriseURL }}"
{{- end }}
{{- end }}
{{- range $key, $value := .Values.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if .Values.config.hostFlatcarPackages.enabled }}
volumeMounts:
- mountPath: {{ .Values.config.hostFlatcarPackages.packagesPath }}
name: packages
{{- end }}
ports:
- name: http
containerPort: {{ .Values.env.PORT | default 8000 }}
protocol: TCP
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
{{- omit .Values.livenessProbe "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
{{- omit .Values.readinessProbe "enabled" | toYaml | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if .Values.config.hostFlatcarPackages.enabled }}
volumes:
- name: packages
{{- if .Values.config.hostFlatcarPackages.persistence.enabled}}
persistentVolumeClaim:
claimName: {{ include "nebraska.fullname" . }}-packages
{{- else }}
emptyDir: {}
{{- end }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
50 changes: 50 additions & 0 deletions deploy/helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "nebraska.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $kubeGitVersion := .Capabilities.KubeVersion.GitVersion -}}
{{- if semverCompare ">=1.19-0" $kubeGitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" $kubeGitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "nebraska.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . | quote }}
http:
paths:
- path: /
backend:
{{- if semverCompare ">=1.19-0" $kubeGitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
pathType: ImplementationSpecific
{{- else -}}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions deploy/helm/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.config.hostFlatcarPackages.persistence.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "nebraska.fullname" . }}-packages
labels:
{{- include "nebraska.labels" . | nindent 4 }}
spec:
accessModes: {{ .Values.config.hostFlatcarPackages.persistence.accessModes }}
resources:
requests:
storage: {{ .Values.config.hostFlatcarPackages.persistence.size }}
{{- if .Values.config.hostFlatcarPackages.persistence.storageClass }}
storageClassName: {{ .Values.config.hostFlatcarPackages.persistence.storageClass }}
{{- end }}
{{- end }}
Loading

0 comments on commit 93bb3a3

Please sign in to comment.