Skip to content

Commit

Permalink
Add Guacamole chart
Browse files Browse the repository at this point in the history
  • Loading branch information
gabibbo97 committed Mar 14, 2020
1 parent 1613d08 commit 3e3113e
Show file tree
Hide file tree
Showing 16 changed files with 465 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/guacamole/.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/
21 changes: 21 additions & 0 deletions charts/guacamole/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: guacamole
description: A remote desktop frontend

# 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.
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.
appVersion: 1.1.0
63 changes: 63 additions & 0 deletions charts/guacamole/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "guacamole.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 "guacamole.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 "guacamole.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "guacamole.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "guacamole.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
15 changes: 15 additions & 0 deletions charts/guacamole/templates/daemon/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/*
Common labels
*/}}
{{- define "guacamole.labels.daemon" -}}
{{ include "guacamole.labels" . }}
app.kubernetes.io/component: guacd
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "guacamole.selectorLabels.daemon" -}}
{{ include "guacamole.selectorLabels" . }}
app.kubernetes.io/component: guacd
{{- end -}}
28 changes: 28 additions & 0 deletions charts/guacamole/templates/daemon/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "guacamole.fullname" . }}-daemon
labels: {{- include "guacamole.labels.daemon" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels: {{- include "guacamole.selectorLabels.daemon" . | nindent 6 }}
template:
metadata:
labels: {{- include "guacamole.selectorLabels.daemon" . | nindent 8 }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{- range $i, $name := .Values.imagePullSecrets }}
- name: {{ $name }}
{{- end }}
{{- end }}
serviceAccountName: {{ include "guacamole.serviceAccountName" . }}
containers:
- name: guacd
image: {{ printf "%s:%s" .Values.daemon.image.repository .Chart.AppVersion }}
imagePullPolicy: {{ .Values.daemon.image.pullPolicy }}
ports:
- name: guacd
containerPort: 4822
15 changes: 15 additions & 0 deletions charts/guacamole/templates/daemon/networkpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.daemon.networkPolicy.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "guacamole.fullname" . }}-daemon
labels: {{- include "guacamole.labels.daemon" . | nindent 4 }}
spec:
podSelector:
matchLabels: {{- include "guacamole.selectorLabels.daemon" . | nindent 6 }}
ingress:
- from:
- podSelector:
matchLabels: {{- include "guacamole.selectorLabels.frontend" . | nindent 14 }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/guacamole/templates/daemon/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "guacamole.fullname" . }}-daemon
labels: {{- include "guacamole.labels.daemon" . | nindent 4 }}
spec:
selector: {{- include "guacamole.selectorLabels.daemon" . | nindent 4 }}
ports:
- name: guacd
port: 4822
targetPort: guacd
15 changes: 15 additions & 0 deletions charts/guacamole/templates/frontend/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/*
Common labels
*/}}
{{- define "guacamole.labels.frontend" -}}
{{ include "guacamole.labels" . }}
app.kubernetes.io/component: frontend
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "guacamole.selectorLabels.frontend" -}}
{{ include "guacamole.selectorLabels" . }}
app.kubernetes.io/component: frontend
{{- end -}}
49 changes: 49 additions & 0 deletions charts/guacamole/templates/frontend/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "guacamole.fullname" . }}-frontend
labels: {{- include "guacamole.labels.frontend" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels: {{- include "guacamole.selectorLabels.frontend" . | nindent 6 }}
template:
metadata:
#
# Annotations to recreate deployment if config changes
#
annotations:
helm.sh/db-config-sha256: {{ .Values.database | toJson | sha256sum | trunc 32 }}
labels: {{- include "guacamole.selectorLabels.frontend" . | nindent 8 }}
spec:
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{- range $i, $name := .Values.imagePullSecrets }}
- name: {{ $name }}
{{- end }}
{{- end }}
serviceAccountName: {{ include "guacamole.serviceAccountName" . }}
containers:
- name: guacamole
image: {{ printf "%s:%s" .Values.frontend.image.repository .Chart.AppVersion }}
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
env:
# Guacamole daemon location
- name: GUACD_HOSTNAME
value: {{ include "guacamole.fullname" . }}-daemon.{{ .Release.Namespace }}.svc
- name: GUACD_PORT
value: {{ 4822 | quote }}
# Database credentials
- name: POSTGRES_HOSTNAME
value: {{ .Values.database.postgres.host }}
- name: POSTGRES_DATABASE
value: {{ .Values.database.postgres.database }}
- name: POSTGRES_USER
value: {{ .Values.database.postgres.user }}
envFrom:
- secretRef:
name: {{ include "guacamole.fullname" . }}-frontend
ports:
- name: http
containerPort: 8080
36 changes: 36 additions & 0 deletions charts/guacamole/templates/frontend/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.frontend.ingress.enabled }}
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: {{ include "guacamole.fullname" . }}-frontend
{{- if .Values.frontend.ingress.annotations }}
annotations: {{- .Values.frontend.ingress.annotations | toYaml | nindent 4 }}
labels: {{- include "guacamole.labels.frontend" . | nindent 4 }}
spec:
{{- if .Values.frontend.ingress.hosts }}
rules:
{{- range $i, $host := .Values.frontend.ingress.hosts }}
- host: {{ $host.host }}
http:
paths:
{{- range $j, $path := $host.paths }}
- path: {{ $path }}
backend:
serviceName: {{ include "guacamole.fullname" $ }}-frontend
servicePort: http
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.frontend.ingress.tls }}
tls:
{{- range $i, $tls := .Values.frontend.ingress.tls }}
- secretName: {{ $tls.secretName }}
hosts:
{{- range $j, $host := $tls.hosts }}
- {{ $host }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/guacamole/templates/frontend/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "guacamole.fullname" . }}-frontend
labels: {{- include "guacamole.labels.frontend" . | nindent 4 }}
data:
# Database credentials
POSTGRES_PASSWORD: {{ .Values.database.postgres.password | b64enc | quote }}
12 changes: 12 additions & 0 deletions charts/guacamole/templates/frontend/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "guacamole.fullname" . }}-frontend
labels: {{- include "guacamole.labels.frontend" . | nindent 4 }}
spec:
selector: {{- include "guacamole.selectorLabels.frontend" . | nindent 4 }}
ports:
- name: http
port: 80
targetPort: http
15 changes: 15 additions & 0 deletions charts/guacamole/templates/hooks/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{/*
Common labels
*/}}
{{- define "guacamole.labels.hook" -}}
{{ include "guacamole.labels" . }}
app.kubernetes.io/component: hook
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "guacamole.selectorLabels.hook" -}}
{{ include "guacamole.selectorLabels" . }}
app.kubernetes.io/component: hook
{{- end -}}
68 changes: 68 additions & 0 deletions charts/guacamole/templates/hooks/initialize_database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{- if .Values.hooks.initializeDatabase.enabled }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "guacamole.fullname" . }}-frontend-initialize-database
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "-1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels: {{- include "guacamole.labels.hook" . | nindent 4 }}
data:
PGPASSWORD: {{ .Values.database.postgres.password | b64enc | quote }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "guacamole.fullname" . }}-frontend-initialize-database
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
labels: {{- include "guacamole.labels.hook" . | nindent 4 }}
spec:
template:
metadata:
labels: {{- include "guacamole.labels.hook" . | nindent 8 }}
spec:
restartPolicy: Never
volumes:
- name: scratchpad
emptyDir: {}
initContainers:
- name: create-sql-manifests
image: {{ printf "%s:%s" .Values.frontend.image.repository .Chart.AppVersion }}
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
command:
- /bin/sh
- -ec
args:
- >-
/opt/guacamole/bin/initdb.sh
--postgres
> /scratchpad/init.sql
volumeMounts:
- name: scratchpad
mountPath: /scratchpad
containers:
- name: setup-database
image: {{ .Values.hooks.initializeDatabase.postgresImage }}
imagePullPolicy: Always
command:
- /bin/sh
- -ec
args:
- >-
psql
--file=/scratchpad/init.sql
--host={{ .Values.database.postgres.host }}
--dbname={{ .Values.database.postgres.database }}
--username={{ .Values.database.postgres.user }}
envFrom:
- secretRef:
name: {{ include "guacamole.fullname" . }}-frontend-initialize-database
volumeMounts:
- name: scratchpad
mountPath: /scratchpad
{{- end }}
Loading

0 comments on commit 3e3113e

Please sign in to comment.