Skip to content

Commit

Permalink
PM-1753 implement web and api deployments for leaderboard (#220)
Browse files Browse the repository at this point in the history
* PM-1753 implement web and api deployments for leaderboard

* PM-1753 quote env variables

* PM-1753 configure flask to listen on all interfaces

* PM-1753 make swagger url configurable

* PM-1753 move ingress paths to a helm chart
  • Loading branch information
simisimis authored Jun 20, 2024
1 parent abbfbd0 commit 259752e
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 173 deletions.
70 changes: 45 additions & 25 deletions delegation-program-leaderboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,58 @@ helmfile status

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | Affinity rules |
| autoscaling.enabled | bool | `false` | Whether to enable autoscaling |
| autoscaling.maxReplicas | int | `100` | The maximum number of pods |
| autoscaling.minReplicas | int | `1` | The minimum number of pods |
| autoscaling.targetCPUUtilizationPercentage | int | `80` | The metrics to use for autoscaling |
| delegationProgramDB.host | string | `"localhost"` | Delegation Program Database Host |
| delegationProgramDB.name | string | `"postgres"` | Delegation Program Database Name |
| delegationProgramDB.password | string | `"postgres"` | Delegation Program Database Password |
| delegationProgramDB.port | string | `"5432"` | Delegation Program Database Port |
| delegationProgramDB.user | string | `"postgres"` | Delegation Program Database User |
| fullnameOverride | string | `""` | The full release name override |
| image.pullPolicy | string | `"IfNotPresent"` | The pullPolicy used when pulling the image |
| image.repository | string | `"673156464838.dkr.ecr.us-west-2.amazonaws.com/delegation-program-leaderboard"` | The repository of the image |
| image.tag | string | `"2.0.2"` | The tag of the image. Overrides the image tag whose default is the chart appVersion. |
| imagePullSecrets | list | `[]` | The secrets used to pull the image |
| ingress.annotations | object | `{}` | The Ingress Annotations |
| ingress.className | string | `""` | The Ingress Class Name to use |
| ingress.enabled | bool | `false` | Whether to create an Ingress |
| ingress.hosts | list | `[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}]` | The Ingress Hosts |
| ingress.hosts | list | `[{"host":"chart-example.local"}]` | A list of DNS names to create for leaderboard service |
| ingress.tls | list | `[]` | The TLS configuration |
| leaderboard.dbHost | string | `"localhost"` | Leaderboard Database Host |
| leaderboard.dbName | string | `"postgres"` | Leaderboard Database Name |
| leaderboard.dbPassword | string | `"postgres"` | Leaderboard Database Password |
| leaderboard.dbPort | string | `"5432"` | Leaderboard Database Port |
| leaderboard.dbUser | string | `"postgres"` | Leaderboard Database User |
| leaderboard.envVars | object | `{}` | Extra Environment Variables |
| leaderboardApi | object | `{"affinity":{},"cacheTimeout":300,"extraEnvVars":{},"image":{"pullPolicy":"IfNotPresent","repository":"673156464838.dkr.ecr.us-west-2.amazonaws.com/delegation-program-leaderboard-api","tag":"2.1.0"},"imagePullSecrets":[],"logFile":"./application.log","nodeSelector":{},"podAnnotations":{},"podSecurityContext":{},"replicaCount":1,"resources":{},"securityContext":{},"service":{"port":5000,"type":"ClusterIP"},"swaggerUrl":"localhost:5000","tolerations":[]}` | configuration options for leaderboard api deployment |
| leaderboardApi.affinity | object | `{}` | Affinity rules |
| leaderboardApi.cacheTimeout | int | `300` | Application cache timeout in seconds |
| leaderboardApi.extraEnvVars | object | `{}` | Extra Environment Variables |
| leaderboardApi.image.pullPolicy | string | `"IfNotPresent"` | The pullPolicy used when pulling the image |
| leaderboardApi.image.repository | string | `"673156464838.dkr.ecr.us-west-2.amazonaws.com/delegation-program-leaderboard-api"` | The repository of the image |
| leaderboardApi.image.tag | string | `"2.1.0"` | The tag of the image. Overrides the image tag whose default is the chart appVersion. |
| leaderboardApi.imagePullSecrets | list | `[]` | The secrets used to pull the image |
| leaderboardApi.logFile | string | `"./application.log"` | A path to an application log file |
| leaderboardApi.nodeSelector | object | `{}` | Node selector labels |
| leaderboardApi.podAnnotations | object | `{}` | Annotations to add to the pods |
| leaderboardApi.podSecurityContext | object | `{}` | The Pod Security Context |
| leaderboardApi.replicaCount | int | `1` | The number of replicas |
| leaderboardApi.resources | object | `{}` | Resource limitations for the pods |
| leaderboardApi.securityContext | object | `{}` | The Security Context |
| leaderboardApi.service.port | int | `5000` | The port of the service |
| leaderboardApi.service.type | string | `"ClusterIP"` | The type of service to create |
| leaderboardApi.swaggerUrl | string | `"localhost:5000"` | Swagger host URL |
| leaderboardApi.tolerations | list | `[]` | Tolerations |
| leaderboardWeb | object | `{"affinity":{},"autoscaling":{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80},"extraEnvVars":{},"image":{"pullPolicy":"IfNotPresent","repository":"673156464838.dkr.ecr.us-west-2.amazonaws.com/delegation-program-leaderboard","tag":"2.1.0"},"imagePullSecrets":[],"nodeSelector":{},"podAnnotations":{},"podSecurityContext":{},"replicaCount":1,"resources":{},"securityContext":{},"service":{"port":80,"type":"ClusterIP"},"tolerations":[]}` | configuration options for leaderboard web deployment |
| leaderboardWeb.affinity | object | `{}` | Affinity rules |
| leaderboardWeb.autoscaling.enabled | bool | `false` | Whether to enable autoscaling |
| leaderboardWeb.autoscaling.maxReplicas | int | `100` | The maximum number of pods |
| leaderboardWeb.autoscaling.minReplicas | int | `1` | The minimum number of pods |
| leaderboardWeb.autoscaling.targetCPUUtilizationPercentage | int | `80` | The metrics to use for autoscaling |
| leaderboardWeb.extraEnvVars | object | `{}` | Extra Environment Variables |
| leaderboardWeb.image.pullPolicy | string | `"IfNotPresent"` | The pullPolicy used when pulling the image |
| leaderboardWeb.image.repository | string | `"673156464838.dkr.ecr.us-west-2.amazonaws.com/delegation-program-leaderboard"` | The repository of the image |
| leaderboardWeb.image.tag | string | `"2.1.0"` | The tag of the image. Overrides the image tag whose default is the chart appVersion. |
| leaderboardWeb.imagePullSecrets | list | `[]` | The secrets used to pull the image |
| leaderboardWeb.nodeSelector | object | `{}` | Node selector labels |
| leaderboardWeb.podAnnotations | object | `{}` | Annotations to add to the pods |
| leaderboardWeb.podSecurityContext | object | `{}` | The Pod Security Context |
| leaderboardWeb.replicaCount | int | `1` | The number of replicas |
| leaderboardWeb.resources | object | `{}` | Resource limitations for the pods |
| leaderboardWeb.securityContext | object | `{}` | The Security Context |
| leaderboardWeb.service.port | int | `80` | The port of the service |
| leaderboardWeb.service.type | string | `"ClusterIP"` | The type of service to create |
| leaderboardWeb.tolerations | list | `[]` | Tolerations |
| nameOverride | string | `""` | The release name override |
| nodeSelector | object | `{}` | Node selector labels |
| podAnnotations | object | `{}` | Annotations to add to the pods |
| podSecurityContext | object | `{}` | The Pod Security Context |
| replicaCount | int | `1` | The number of replicas |
| resources | object | `{}` | Resource limitations for the pods |
| securityContext | object | `{}` | The Security Context |
| service.port | int | `80` | The port of the service |
| service.type | string | `"ClusterIP"` | The type of service to create |
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account |
| serviceAccount.create | bool | `true` | Specifies whether a service account should be created |
| serviceAccount.name | string | `""` | If not set and create is true, a name is generated using the fullname template |
| tolerations | list | `[]` | Tolerations |

85 changes: 85 additions & 0 deletions delegation-program-leaderboard/templates/deployment-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "delegation-program-leaderboard.fullname" . }}-api
labels:
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}-api
spec:
{{- with .Values.leaderboardApi }}
replicas: {{ .replicaCount }}
selector:
matchLabels:
{{- include "delegation-program-leaderboard.selectorLabels" $ | nindent 6 }}-api
template:
metadata:
{{- with .podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "delegation-program-leaderboard.selectorLabels" $ | nindent 8 }}-api
spec:
{{- with .imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "delegation-program-leaderboard.serviceAccountName" $ }}
securityContext:
{{- toYaml .podSecurityContext | nindent 8 }}
containers:
- name: leaderboard-api
securityContext:
{{- toYaml .securityContext | nindent 12 }}
image: "{{ .image.repository }}:{{ .image.tag | default $.Chart.AppVersion }}"
imagePullPolicy: {{ .image.pullPolicy }}
env:
- name: SNARK_HOST
value: {{ $.Values.delegationProgramDB.host | quote }}
- name: SNARK_PORT
value: {{ $.Values.delegationProgramDB.port | quote }}
- name: SNARK_USER
value: {{ $.Values.delegationProgramDB.user | quote }}
- name: SNARK_PASSWORD
value: {{ $.Values.delegationProgramDB.password | quote }}
- name: SNARK_DB
value: {{ $.Values.delegationProgramDB.name | quote }}
- name: API_HOST
value: 0.0.0.0
- name: API_PORT
value: {{ .service.port | quote }}
- name: CACHE_TIMEOUT
value: {{ .cacheTimeout | quote }}
- name: LOGGING_LOCATION
value: {{ .logFile }}
- name: SWAGGER_HOST
value: {{ .swaggerUrl | quote }}
{{- if .extraEnvVars }}
{{- toYaml .extraEnvVars | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /apidocs
port: http
readinessProbe:
httpGet:
path: /apidocs
port: http
resources:
{{- toYaml .resources | nindent 12 }}
{{- with .nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "delegation-program-leaderboard.fullname" . }}
name: {{ include "delegation-program-leaderboard.fullname" . }}-web
labels:
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}-web
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- with .Values.leaderboardWeb }}
{{- if not .autoscaling.enabled }}
replicas: {{ .replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "delegation-program-leaderboard.selectorLabels" . | nindent 6 }}
{{- include "delegation-program-leaderboard.selectorLabels" $ | nindent 6 }}-web
template:
metadata:
{{- with .Values.podAnnotations }}
{{- with .podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "delegation-program-leaderboard.selectorLabels" . | nindent 8 }}
{{- include "delegation-program-leaderboard.selectorLabels" $ | nindent 8 }}-web
spec:
{{- with .Values.imagePullSecrets }}
{{- with .imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "delegation-program-leaderboard.serviceAccountName" . }}
serviceAccountName: {{ include "delegation-program-leaderboard.serviceAccountName" $ }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- toYaml .podSecurityContext | nindent 8 }}
containers:
- name: leaderboard
- name: leaderboard-web
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- toYaml .securityContext | nindent 12 }}
image: "{{ .image.repository }}:{{ .image.tag | default $.Chart.AppVersion }}"
imagePullPolicy: {{ .image.pullPolicy }}
env:
- name: DB_SNARK_HOST
value: {{ .Values.leaderboard.dbHost | quote }}
value: {{ $.Values.delegationProgramDB.host | quote }}
- name: DB_SNARK_PORT
value: {{ .Values.leaderboard.dbPort | quote }}
value: {{ $.Values.delegationProgramDB.port | quote }}
- name: DB_SNARK_USER
value: {{ .Values.leaderboard.dbUser | quote }}
value: {{ $.Values.delegationProgramDB.user | quote }}
- name: DB_SNARK_PWD
value: {{ .Values.leaderboard.dbPassword | quote }}
value: {{ $.Values.delegationProgramDB.password | quote }}
- name: DB_SNARK_DB
value: {{ .Values.leaderboard.dbName | quote }}
{{- if .Values.leaderboard.envVars }}
{{- toYaml .Values.leaderboard.envVars | nindent 12 }}
value: {{ $.Values.delegationProgramDB.name | quote }}
{{- if .extraEnvVars }}
{{- toYaml .extraEnvVars | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
containerPort: {{ .service.port }}
protocol: TCP
livenessProbe:
httpGet:
Expand All @@ -60,16 +61,17 @@ spec:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
{{- toYaml .resources | nindent 12 }}
{{- with .nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
{{- with .affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
{{- with .tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
20 changes: 10 additions & 10 deletions delegation-program-leaderboard/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{{- if .Values.autoscaling.enabled }}
{{- if .Values.leaderboardWeb.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "delegation-program-leaderboard.fullname" . }}
name: {{ include "delegation-program-leaderboard.fullname" . }}-web
labels:
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}-web
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "delegation-program-leaderboard.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
name: {{ include "delegation-program-leaderboard.fullname" . }}-web
minReplicas: {{ .Values.leaderboardWeb.autoscaling.minReplicas }}
maxReplicas: {{ .Values.leaderboardWeb.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- if .Values.leaderboardWeb.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
averageUtilization: {{ .Values.leaderboardWeb.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- if .Values.leaderboardWeb.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
averageUtilization: {{ .Values.leaderboardWeb.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
46 changes: 32 additions & 14 deletions delegation-program-leaderboard/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "delegation-program-leaderboard.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") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
Expand Down Expand Up @@ -41,21 +40,40 @@ spec:
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
- path: /apidocs
pathType: Prefix
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
name: {{ include "delegation-program-leaderboard.fullname" $ }}-api
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
number: {{ $.Values.leaderboardApi.service.port }}
- path: /uptimescore
pathType: Prefix
backend:
service:
name: {{ include "delegation-program-leaderboard.fullname" $ }}-api
port:
number: {{ $.Values.leaderboardApi.service.port }}
- path: /flasgger_static
pathType: Prefix
backend:
service:
name: {{ include "delegation-program-leaderboard.fullname" $ }}-api
port:
number: {{ $.Values.leaderboardApi.service.port }}
- path: /apispec_1.json
pathType: Exact
backend:
service:
name: {{ include "delegation-program-leaderboard.fullname" $ }}-api
port:
number: {{ $.Values.leaderboardApi.service.port }}
- path: /
pathType: Prefix
backend:
service:
name: {{ include "delegation-program-leaderboard.fullname" $ }}-web
port:
number: {{ $.Values.leaderboardWeb.service.port }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "delegation-program-leaderboard.fullname" . }}
name: {{ include "delegation-program-leaderboard.fullname" . }}-api
labels:
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}
{{- include "delegation-program-leaderboard.labels" . | nindent 4 }}-api
spec:
type: {{ .Values.service.type }}
type: {{ .Values.leaderboardApi.service.type }}
ports:
- port: {{ .Values.service.port }}
- port: {{ .Values.leaderboardApi.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "delegation-program-leaderboard.selectorLabels" . | nindent 4 }}
{{- include "delegation-program-leaderboard.selectorLabels" . | nindent 4 }}-api
Loading

0 comments on commit 259752e

Please sign in to comment.