refactor into helpers

This commit is contained in:
Simon Larsen 2023-09-24 12:28:45 +00:00
parent 05d6dd2182
commit 55bf11bfd1
3 changed files with 112 additions and 65 deletions

View File

@ -0,0 +1,23 @@
### Installation
```
helm install oneuptime ./HelmChart/public/oneuptime
```
### Upgrade
```
helm upgrade oneuptime ./HelmChart/public/oneuptime
```
### Remove
```
helm uninstall oneuptime
```
### Lint
```
helm lint ./HelmChart/public/oneuptime
```

View File

@ -4,7 +4,7 @@
- name: NODE_ENV
value: {{ $.Values.nodeEnvironment }}
- name: BILLING_ENABLED
value: {{ $.Values.billing.enabled }}
value: {{ $.Values.billing.enabled | squote }}
- name: BILLING_PUBLIC_KEY
value: {{ $.Values.billing.publicKey }}
- name: SUBSCRIPTION_PLAN_BASIC
@ -29,7 +29,7 @@
{{- define "oneuptime.env.commonUi" }}
- name: IS_SERVER
value: false
value: "false"
- name: STATUS_PAGE_CNAME_RECORD
value: {{ $.Values.statusPage.cnameRecord }}
{{- end }}
@ -37,7 +37,7 @@
{{- define "oneuptime.env.commonServer" }}
- name: IS_SERVER
value: true
value: "true"
- name: ONEUPTIME_SECRET
value: {{ $.Values.secrets.oneuptime }}
@ -89,16 +89,12 @@
- name: POSTGRES_SSL_REJECT_UNAUTHORIZED
value: {{ $.Values.postgres.sslRejectUnauthorized }}
- name: BILLING_ENABLED
value: {{ $.Values.billing.enabled }}
- name: BILLING_PUBLIC_KEY
value: {{ $.Values.billing.publicKey }}
- name: BILLING_PRIVATE_KEY
value: {{ $.Values.billing.privateKey }}
- name: DISABLE_AUTOMATIC_INCIDENT_CREATION
value: {{ $.Values.incidents.disableAutomaticCreation }}
value: {{ $.Values.incidents.disableAutomaticCreation | squote }}
{{- end }}
{{- define "oneuptime.env.pod" }}
@ -122,21 +118,91 @@
{{- define "oneuptime.service.clusterIP" }}
{{- define "oneuptime.service" }}
apiVersion: v1
kind: Service
metadata:
labels:
app: {{ printf "%s-%s" $.ReleaseName $.ServiceName }}
app: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
app.kubernetes.io/part-of: oneuptime
app.kubernetes.io/managed-by: Helm
name: {{ printf "%s-%s" $.ReleaseName $.ServiceName }}
namespace: {{ $.Namespace }}
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
namespace: {{ $.Release.Namespace }}
spec:
ports:
- port: {{ $.Port }}
targetPort: {{ $.Port }}
selector:
app: {{ printf "%s-%s" $.ReleaseName $.ServiceName }}
app: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
type: ClusterIP
{{- end }}
{{- define "oneuptime.deployment" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
namespace: {{ $.Release.Namespace }}
labels:
app: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
app.kubernetes.io/part-of: oneuptime
app.kubernetes.io/managed-by: Helm
spec:
selector:
matchLabels:
app: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
replicas: {{ $.Values.replicaCount }}
template:
metadata:
labels:
app: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
spec:
containers:
- image: {{ printf "%s/%s/%s:%s" .Values.image.registry .Values.image.repository $.ServiceName .Values.image.tag }}
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
{{- include "oneuptime.env.common" . | nindent 22 }}
ports:
- containerPort: {{ $.Port }}
hostPort: {{ $.Port }}
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
restartPolicy: {{ $.Values.image.restartPolicy }}
{{- end }}
{{- define "oneuptime.autoscaler" }}
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
namespace: {{ $.Release.Namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ printf "%s-%s" $.Release.Name $.ServiceName }}
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 }}
{{- end }}

View File

@ -1,56 +1,14 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ printf "%s-%s" $.Release.Name "home" }}
namespace: {{ $.Release.Namespace }}
labels:
app: {{ printf "%s-%s" $.Release.Name "home" }}
app.kubernetes.io/part-of: oneuptime
app.kubernetes.io/managed-by: Helm
spec:
selector:
matchLabels:
app: {{ printf "%s-%s" $.Release.Name "home" }}
replicas: {{ $.Values.replicaCount }}
template:
metadata:
labels:
app: {{ printf "%s-%s" $.Release.Name "home" }}
spec:
containers:
- image: {{ printf "%s/%s/%s:%s" .Values.image.registry .Values.image.repository "home" .Values.image.tag }}
name: {{ printf "%s-%s" $.Release.Name "home" }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
{{- include "oneuptime.env.common" . | nindent 22 }}
{{- include "oneuptime.env.commonUi" . | nindent 22 }}
{{- include "oneuptime.env.pod" . | nindent 22 }}
ports:
- containerPort: {{ $.Values.port.home }}
hostPort: {{ $.Values.port.home }}
name: {{ printf "%s-%s" $.Release.Name "home" }}
restartPolicy: {{ $.Values.image.restartPolicy }}
---
# OneUptime home Service
{{- $serviceArgs := dict "ServiceName" "home" "Port" "1444" "ReleaseName" $.Release.Name "Namespace" $.Release.Namespace -}}
{{- include "oneuptime.service.clusterIP" $serviceArgs -}}
{{- $homeDeploymentArgs :=dict "ServiceName" "home" "Port" "1444" "Release" $.Release "Values" $.Values -}}
{{- include "oneuptime.deployment" $homeDeploymentArgs }}
---
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v1
kind: HorizontalPodautoscaling
metadata:
name: {{ printf "%s-%s" $.Release.Name "home" }}
namespace: {{ $.Release.Namespace }}
spec:
maxReplicas: {{ $.Values.autoscaling.maxReplicas }}
minReplicas: {{ $.Values.autoscaling.minReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ printf "%s-%s" $.Release.Name "home" }}
targetCPUUtilizationPercentage: {{ $.Values.autoscaling.targetCPUUtilizationPercentage }}
targetMemoryUtilizationPercentage: {{ $.Values.autoscaling.targetMemoryUtilizationPercentage }}
# OneUptime home Service
{{- $homeServiceArgs := dict "ServiceName" "home" "Port" "1444" "Release" $.Release "Values" $.Values -}}
{{- include "oneuptime.service" $homeServiceArgs }}
---
{{- end }}
# OneUptime home Service
{{- $homeAutoScalerArgs := dict "ServiceName" "home" "Release" $.Release "Values" $.Values -}}
{{- include "oneuptime.autoscaler" $homeAutoScalerArgs }}
---