Skip to content

Commit

Permalink
feat(4550): implement maintenance mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhanchik committed Jan 30, 2025
1 parent 31d34b6 commit 2ef4442
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/toggle-maintenance-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Toggle Maintenance Mode

on:
workflow_dispatch:
inputs:
environment:
description: Environment to toggle maintenance mode
type: environment
required: true
maintenanceMode:
description: Enable or disable maintenance mode (true/false)
type: boolean
required: true

jobs:
toggle-maintenance:
runs-on: ubuntu-22.04
timeout-minutes: 5
permissions:
contents: read
environment:
name: ${{ inputs.environment }}

steps:
- uses: hmarr/debug-action@f7318c783045ac39ed9bb497e22ce835fdafbfe6
- uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
with:
ref: main

- name: Authenticate and set context
uses: redhat-actions/oc-login@dfbd9912672664f9df2023c1c16e07bcf306043c
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ inputs.environment }}
insecure_skip_tls_verify: true

- name: Toggle Maintenance Mode with Helm
run: |
helm upgrade maintenance-mode ./helm/main \
--namespace ${{ inputs.environment }} \
--set maintenanceMode=${{ inputs.maintenanceMode }}
23 changes: 23 additions & 0 deletions helm/_maintenance-mode/.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/
6 changes: 6 additions & 0 deletions helm/_maintenance-mode/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: maintenance-mode
description: A Helm chart for the Maintenance mode
type: application
version: 0.1.0
appVersion: "0.1.0"
62 changes: 62 additions & 0 deletions helm/_maintenance-mode/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "_.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 "_.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 "_.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "_.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "_.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
87 changes: 87 additions & 0 deletions helm/_maintenance-mode/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{- $deploymentTag := .Values.image.tag | default .Chart.AppVersion -}}

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "_.fullname" . }}
labels:
{{- include "_.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "_.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- $podAnnotations := (.Values.podAnnotations | default dict) -}}
{{- with $podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "_.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- $imagePullSecrets := concat (.Values.imagePullSecrets | default list) (.Values.global.imagePullSecrets | default list) -}}
{{- with $imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ default .Values.global.serviceAccountName .Values.serviceAccountName }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ $deploymentTag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- $env := merge (.Values.global.env | default dict) (.Values.env | default dict) -}}
{{- range $k, $v := $env }}
- name: {{ $k | quote }}
value: {{ $v | quote }}
{{- end }}
{{- if .Values.envSecretName }}
envFrom:
- secretRef:
name: {{ .Values.envSecretName }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: http
readinessProbe:
httpGet:
path: /health
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
32 changes: 32 additions & 0 deletions helm/_maintenance-mode/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 "_.fullname" . }}
labels:
{{- include "_.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "_.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 }}
20 changes: 20 additions & 0 deletions helm/_maintenance-mode/templates/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.route.enabled }}
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{ include "_.fullname" . }}
annotations:
haproxy.router.openshift.io/balance: roundrobin
haproxy.router.openshift.io/disable_cookies: 'true'
haproxy.router.openshift.io/timeout: 600s
spec:
{{- if .Values.route.host }}
host: {{ .Values.route.host }}
{{- end }}
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
to:
kind: Service
name: {{ include "_.fullname" . }}
{{- end }}
15 changes: 15 additions & 0 deletions helm/_maintenance-mode/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "_.fullname" . }}
labels:
{{- include "_.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "_.selectorLabels" . | nindent 4 }}
71 changes: 71 additions & 0 deletions helm/_maintenance-mode/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
replicaCount: 1

image:
repository: ghcr.io/bcgov/pltsvc-maintenance-mode
tag: latest
pullPolicy: Always

imagePullSecrets: []
nameOverride: pltsvc-maintenance-mode
fullnameOverride: pltsvc-maintenance-mode

podAnnotations: {}
podLabels: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

service:
type: ClusterIP
port: 7070

route:
enabled: false
host:

serviceAccountName:
envSecretName:
env: {}

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

# Additional volumes on the output Deployment definition.
volumes: []


# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true

nodeSelector: {}

tolerations: []

affinity: {}
7 changes: 5 additions & 2 deletions helm/main/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ dependencies:
- name: mailpit
repository: file://../_mailpit
version: 0.1.0
digest: sha256:a9417c21d60ed7e0b922d578e9f0917a09c77fd794cefdc2769f94239c3c659c
generated: "2025-01-24T16:22:29.931737705-08:00"
- name: maintenance-mode
repository: file://../_maintenance-mode
version: 0.1.0
digest: sha256:0f20b7437c839b3c23a98826794ec542ff9ed88b9b926bf8a1466267af9dbe85
generated: "2025-01-29T13:57:24.526089-08:00"
4 changes: 4 additions & 0 deletions helm/main/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ dependencies:
version: '0.1.0'
repository: 'file://../_mailpit'
condition: mailpit.enabled
- name: maintenance-mode
version: '0.1.0'
repository: 'file://../_maintenance-mode'
condition: maintenance-mode.enabled
Loading

0 comments on commit 2ef4442

Please sign in to comment.