Skip to content

Commit

Permalink
Feature: create valid helm files (#296)
Browse files Browse the repository at this point in the history
## Changes

- Add valid `helm` charts to the portal

## Issue(s)

- #
  • Loading branch information
Gustavo-SF authored Jul 23, 2024
1 parent 95f9954 commit d8e1bb7
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 0 deletions.
3 changes: 3 additions & 0 deletions portal/.gitignore → .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,6 @@ portal/media/
.envs/*
!.envs/.local/
deployment/configmaps

# Helm
ldsa-portal-*.tgz
23 changes: 23 additions & 0 deletions deploy/ldsa-portal/.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/
9 changes: 9 additions & 0 deletions deploy/ldsa-portal/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies:
- name: cert-manager
repository: https://charts.jetstack.io
version: v1.13.0
- name: ingress-nginx
repository: https://kubernetes.github.io/ingress-nginx
version: 4.0.19
digest: sha256:a52b0cf005c89c587662d8b7573bc24a684153be2168f0a2dd16f0b8aaf2e9ee
generated: "2024-07-19T09:25:09.078285+01:00"
14 changes: 14 additions & 0 deletions deploy/ldsa-portal/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v2
name: ldsa-portal
description: A Helm chart for deploying the LSDA Portal
type: application
version: 0.1.0
appVersion: "1.0"
icon: https://d9hhrg4mnvzow.cloudfront.net/www.lisbondatascience.org/about-us/a5dfc2f8-ball_103h03h000000000000028.png
dependencies:
- name: cert-manager
version: "v1.13.0"
repository: "https://charts.jetstack.io"
- name: ingress-nginx
version: "4.0.19"
repository: "https://kubernetes.github.io/ingress-nginx"
22 changes: 22 additions & 0 deletions deploy/ldsa-portal/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- 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 "ldsa-portal.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "ldsa-portal.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ldsa-portal.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 "ldsa-portal.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 }}
62 changes: 62 additions & 0 deletions deploy/ldsa-portal/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "ldsa-portal.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 "ldsa-portal.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 "ldsa-portal.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "ldsa-portal.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "ldsa-portal.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
46 changes: 46 additions & 0 deletions deploy/ldsa-portal/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "ldsa-portal.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
strategy:
rollingUpdate:
maxSurge: {{ .Values.strategy.rollingUpdate.maxSurge }}
maxUnavailable: {{ .Values.strategy.rollingUpdate.maxUnavailable }}
selector:
matchLabels:
app: {{ include "ldsa-portal.name" . }}
template:
metadata:
labels:
app: {{ include "ldsa-portal.name" . }}
environment: {{ .Values.environment }}
spec:
restartPolicy: Always
volumes:
- name: kubeconfig-volume
configMap:
name: {{ .Values.kubeconfigConfigMapName }}
- name: aws-volume
configMap:
name: {{ .Values.awsConfigMapName }}
containers:
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
name: django
resources: {}
args:
- {{ .Values.startScript }}
volumeMounts:
- name: kubeconfig-volume
mountPath: /home/django/.kube/
- name: aws-volume
mountPath: /home/django/.aws/
env:
{{- range .Values.env }}
- name: {{ .name }}
valueFrom:
configMapKeyRef:
key: {{ .key }}
name: {{ .configMapName }}
{{- end }}
32 changes: 32 additions & 0 deletions deploy/ldsa-portal/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ldsa-portal.fullname" . }}
labels:
{{- include "ldsa-portal.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "ldsa-portal.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
24 changes: 24 additions & 0 deletions deploy/ldsa-portal/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "ldsa-portal.fullname" . }}
annotations:
cert-manager.io/issuer: {{ .Values.ingress.annotations.certManagerIssuer }}
nginx.ingress.kubernetes.io/proxy-body-size: "{{ .Values.ingress.annotations.proxyBodySize }}"
spec:
ingressClassName: {{ .Values.ingress.className }}
tls:
- hosts:
- {{ .Values.ingress.host }}
secretName: {{ .Values.ingress.secretName }}
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ include "ldsa-portal.fullname" . }}
port:
number: {{ .Values.service.port }}
16 changes: 16 additions & 0 deletions deploy/ldsa-portal/templates/letsencrypt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ .Values.letsencrypt.name }}
labels:
app: cert-manager
spec:
acme:
server: {{ .Values.letsencrypt.server }}
email: {{ .Values.letsencrypt.email }}
privateKeySecretRef:
name: {{ .Values.letsencrypt.privateKeySecretName }}
solvers:
- http01:
ingress:
class: {{ .Values.letsencrypt.ingressClass }}
12 changes: 12 additions & 0 deletions deploy/ldsa-portal/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "ldsa-portal.fullname" . }}
labels:
app: {{ include "ldsa-portal.name" . }}
spec:
ports:
- port: {{ .Values.service.port }}
protocol: TCP
selector:
app: {{ include "ldsa-portal.name" . }}
13 changes: 13 additions & 0 deletions deploy/ldsa-portal/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "ldsa-portal.serviceAccountName" . }}
labels:
{{- include "ldsa-portal.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
15 changes: 15 additions & 0 deletions deploy/ldsa-portal/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "ldsa-portal.fullname" . }}-test-connection"
labels:
{{- include "ldsa-portal.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "ldsa-portal.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit d8e1bb7

Please sign in to comment.