Skip to content

Commit

Permalink
helm charts for the http rest API (#604)
Browse files Browse the repository at this point in the history
* remove old helm charts in repo root

* re-scaffold helm charts

* add environment variables to rest-api deployment

* adjust values to use haztrak-server image

* misc small changes including update whitenoise, settings, dockerfile, move static dir

* add collect static to run.sh bash script, add DEFAULT_RENDERER_CLASSES to rest framework settings to serve json by default (instead of the browseable API for development

* create separate configs (settings module) for dev, test, and prod environments

* update cors headings

* move database configs to environment config files

* add remaining environmental variables to helm chart environment variables

* disable readiness and liveness probe temporarily until we can implement a health check end point

we are also currently implementing a postgres instance (for testing) outside the version control system currently
  • Loading branch information
dpgraham4401 authored Oct 12, 2023
1 parent faf759e commit 8bd03b0
Show file tree
Hide file tree
Showing 32 changed files with 314 additions and 274 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: trailing-whitespace
- id: check-json
- id: check-yaml
exclude: ^haztrak-charts/
exclude: ^haztrak/
- id: end-of-file-fixer
exclude: |
(?x)^(
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
**/*.bak
/client/public/mockServiceWorker.js
.github/pull_request_template.md
haztrak/*
2 changes: 1 addition & 1 deletion configs/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

### Django Configs
HT_SECRET_KEY='django-insecure-%btjqoun@6ps$e@8bw$48s+!x1e4aiz&5p2nrf6cmiw4)jsx5d'
HT_DEBUG=True
HT_HOST=localhost
HT_TIMEZONE=America/New_York
HT_CORS_DOMAIN=http://localhost:3000
Expand All @@ -24,6 +23,7 @@ HT_DB_NAME=haztrak_db
HT_DB_USER=admin
HT_DB_PASSWORD='password1'
HT_DB_PORT=5432
HT_DB_HOST=localhost

### Celery task queue configs
CELERY_RESULT_BACKEND=django-db
Expand Down
8 changes: 1 addition & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ services:
image: haztrak-server
build:
context: ./server
target: dev
ports:
- '8000:8000'
volumes:
- ./server:/app
environment:
DJANGO_SETTINGS_MODULE: 'haztrak.settings.dev'
HT_HOST: 'localhost'
HT_SECRET_KEY: ${HT_SECRET_KEY}
HT_DEBUG: ${HT_DEBUG}
Expand All @@ -28,12 +28,6 @@ services:
HT_DB_PASSWORD: ${HT_DB_PASSWORD}
HT_DB_HOST: postgres
HT_DB_PORT: ${HT_DB_PORT}
command: |
sh -c "
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py loaddata dev_data.yaml &&
python manage.py runserver 0.0.0.0:8000"
depends_on:
postgres:
condition: service_healthy
Expand Down
15 changes: 0 additions & 15 deletions haztrak-charts/Chart.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions haztrak-charts/templates/configmap.yaml

This file was deleted.

72 changes: 0 additions & 72 deletions haztrak-charts/templates/deployment.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions haztrak-charts/templates/secrets.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions haztrak-charts/templates/service.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions haztrak-charts/templates/tests/test-connection.yaml

This file was deleted.

File renamed without changes.
24 changes: 24 additions & 0 deletions haztrak/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: haztrak
description: A Helm chart for 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

# 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.
# It is recommended to use it with quotes.
appVersion: "0.6.1"
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
{{- 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 "haztrak-charts.fullname" . }})
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "haztrak.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 "haztrak-charts.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "haztrak-charts.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "haztrak.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "haztrak.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 "haztrak-charts.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "haztrak.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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "haztrak-charts.name" -}}
{{- define "haztrak.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ 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 "haztrak-charts.fullname" -}}
{{- define "haztrak.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "haztrak-charts.chart" -}}
{{- define "haztrak.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "haztrak-charts.labels" -}}
helm.sh/chart: {{ include "haztrak-charts.chart" . }}
{{ include "haztrak-charts.selectorLabels" . }}
{{- define "haztrak.labels" -}}
helm.sh/chart: {{ include "haztrak.chart" . }}
{{ include "haztrak.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "haztrak-charts.selectorLabels" -}}
app.kubernetes.io/name: {{ include "haztrak-charts.name" . }}
{{- define "haztrak.selectorLabels" -}}
app.kubernetes.io/name: {{ include "haztrak.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "haztrak-charts.serviceAccountName" -}}
{{- define "haztrak.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "haztrak-charts.fullname" .) .Values.serviceAccount.name }}
{{- default (include "haztrak.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
16 changes: 10 additions & 6 deletions haztrak-charts/templates/hpa.yaml → haztrak/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "haztrak-charts.fullname" . }}
name: {{ include "haztrak.fullname" . }}
labels:
{{- include "haztrak-charts.labels" . | nindent 4 }}
{{- include "haztrak.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "haztrak-charts.fullname" . }}
name: {{ include "haztrak.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "haztrak-charts.fullname" . -}}
{{- $fullName := include "haztrak.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
Expand All @@ -17,7 +17,7 @@ kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "haztrak-charts.labels" . | nindent 4 }}
{{- include "haztrak.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
Loading

0 comments on commit 8bd03b0

Please sign in to comment.