Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base Helm Chart #30

Merged
merged 4 commits into from
Aug 9, 2024
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/target

/**/output/
/**/charts/
!/charts/
23 changes: 23 additions & 0 deletions charts/pod-director/.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/
5 changes: 5 additions & 0 deletions charts/pod-director/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: pod-director
description: A simple utility to make pods in specific namespaces run in specific nodes
type: application
version: 0.1.0
14 changes: 14 additions & 0 deletions charts/pod-director/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.config.groups }}
Pod Director installed, the following groups were configured:
{{- toYaml .Values.config.groups | nindent 2 }}

{{ $firstGroup := first (keys .Values.config.groups) -}}
{{ $testNamespace := "test-namespace" -}}
You can validate that the groups are working by labelling a test namespace with a group and running a pod in it:
kubectl create namespace {{ $testNamespace }}
kubectl label namespace {{ $testNamespace }} pod-director/group={{ $firstGroup }}
kubectl -n {{ $testNamespace }} run --rm -ti --image=busybox -- /bin/sh
{{- else }}
Pod Director was installed, but no groups were configured! It will remain idle until you configure a group and label
a namespace!
{{- end }}
69 changes: 69 additions & 0 deletions charts/pod-director/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- define "pod-director.name" -}}
{{- .Values.nameOverride | default .Chart.Name | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "pod-director.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := .Values.nameOverride | default .Chart.Name }}
{{- if .Release.Name | contains $name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "pod-director.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{- define "pod-director.labels" -}}
{{- include "pod-director.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.Version | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "pod-director.chart" . }}
{{- with .Values.globalLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{- define "pod-director.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pod-director.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "pod-director.serviceAccountName" -}}
{{- .Values.serviceAccount.name | default (include "pod-director.fullname" .) }}
{{- end }}

{{- define "pod-director.imageFullname" -}}
{{- $image := .Values.image }}
{{- $registry := $image.registry }}
{{- $repository := required "An repository is required" $image.repository }}
{{- $tag := $image.tag | default .Chart.Version }}
{{- if $registry }}
{{- $registry = print $registry "/" }}
{{- end }}
{{- if $tag }}
{{- $tag = print ":" $tag }}
{{- end }}
{{- print $registry $repository $tag }}
{{- end }}

{{- define "pod-director.configMapName" -}}
{{- include "pod-director.fullname" . }}
{{- end }}

{{- define "pod-director.serviceName" -}}
{{- include "pod-director.fullname" . }}
{{- end }}

{{- define "pod-director.webhookSecretName" -}}
{{- include "pod-director.fullname" . }}
{{- end }}

{{- define "pod-director.clusterRoleName" -}}
{{- include "pod-director.fullname" . }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/pod-director/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "pod-director.clusterRoleName" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list", "watch"]
16 changes: 16 additions & 0 deletions charts/pod-director/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "pod-director.configMapName" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.config.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data:
{{ .Values.config.filename | quote }}: |
server:
{{- toYaml .Values.config.server | nindent 6 }}
groups:
{{- toYaml .Values.config.groups | nindent 6 }}
101 changes: 101 additions & 0 deletions charts/pod-director/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{{- $configMountPath := without (splitList "/" .Values.config.mountPath) "" | join "/" | printf "/%s" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "pod-director.fullname" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- with .Values.updateStrategy }}
strategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "pod-director.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pod-director.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
imagePullSecrets:
{{- toYaml .Values.image.pullSecrets | nindent 8 }}
serviceAccountName: {{ include "pod-director.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers:
{{- toYaml .Values.initContainers | nindent 8 }}
containers:
- name: pod-director
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: {{ include "pod-director.imageFullname" . | quote }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: PD_CONFIG_FILE
value: {{ print $configMountPath "/" .Values.config.filename | quote }}
{{- with .Values.env }}
{{- toYaml . | nindent 12 }}
{{- end }}
envFrom:
{{- toYaml .Values.envFrom | nindent 12 }}
ports:
- name: http
containerPort: {{ .Values.config.server.port | default 8443 }}
protocol: TCP
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.readinessProbe.path }}
port: http
scheme: {{ .Values.readinessProbe.scheme }}
periodSeconds: {{ .Values.readinessProbe.period }}
successThreshold: {{ .Values.readinessProbe.successCount }}
failureThreshold: {{ .Values.readinessProbe.failureCount }}
{{- if .Values.readinessProbe.initialDelaySeconds }}
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
{{- end }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
lifecycle:
{{- toYaml .Values.lifecycle | nindent 12 }}
volumeMounts:
- name: pd-config
mountPath: {{ $configMountPath }}
readOnly: true
- name: webhook
mountPath: /app/certs
readOnly: true
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraContainers }}
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: pd-config
configMap:
name: {{ include "pod-director.configMapName" . }}
- name: webhook
secret:
secretName: {{ include "pod-director.webhookSecretName" . }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
nodeSelector:
{{- toYaml .Values.nodeSelector | nindent 8 }}
affinity:
{{- toYaml .Values.affinity | nindent 8 }}
tolerations:
{{- toYaml .Values.tolerations | nindent 8 }}
23 changes: 23 additions & 0 deletions charts/pod-director/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "pod-director.fullname" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.autoscaling.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "pod-director.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- toYaml .Values.autoscaling.metrics | nindent 4 }}
behavior:
{{- toYaml .Values.autoscaling.behavior | nindent 4 }}
{{- end }}
43 changes: 43 additions & 0 deletions charts/pod-director/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "pod-director.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.className }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: {{ .pathType }}
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
33 changes: 33 additions & 0 deletions charts/pod-director/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.pdb.enabled }}
{{- if or (and .Values.pdb.minAvailable .Values.pdb.maxUnavailable) (and (not .Values.pdb.minAvailable) (not .Values.pdb.maxUnavailable)) }}
{{- fail "Either minAvailable or maxUnavailable for PDB must be defined (but not both)" }}
{{- end }}

{{- if .Values.autoscaling.enabled }}
{{- if le (int .Values.autoscaling.minReplicas) 1 }}
{{- fail "To use a PDB with autoscaling, minReplicas must be greater than 1" }}
{{- end }}
{{- else if le (int .Values.replicaCount) 1 }}
{{- fail "To use a PDB with a static replica count, replicaCount must be greater than 1" }}
{{- end }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "pod-director.fullname" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.pdb.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.pdb.minAvailable }}
minAvailable: {{ . }}
{{- end }}
{{- with .Values.pdb.maxUnavailable }}
maxUnavailable: {{ . }}
{{- end }}
selector:
matchLabels:
{{- include "pod-director.selectorLabels" . | nindent 6 }}
{{- end }}
14 changes: 14 additions & 0 deletions charts/pod-director/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "pod-director.fullname" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
subjects:
- apiGroup: ""
kind: ServiceAccount
name: {{ include "pod-director.serviceAccountName" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "pod-director.clusterRoleName" . }}
19 changes: 19 additions & 0 deletions charts/pod-director/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "pod-director.serviceName" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "pod-director.selectorLabels" . | nindent 4 }}
11 changes: 11 additions & 0 deletions charts/pod-director/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "pod-director.serviceAccountName" . }}
labels:
{{- include "pod-director.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: true
Loading
Loading