From 3385b947c78bfa7bfb7d8a401c13b2d2e4fa1398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Denquin?= Date: Mon, 30 Dec 2024 15:46:05 +0100 Subject: [PATCH] feat(workers): Add dedicated clock worker (#131) --- templates/api-deployment.yaml | 2 + templates/billing-worker-deployment.yaml | 2 + templates/clock-worker-deployment.yaml | 223 +++++++++++++++++++++++ templates/events-worker-deployment.yaml | 2 + templates/webhook-worker-deployment.yaml | 2 + templates/worker-deployment.yaml | 2 + values.yaml | 24 +++ 7 files changed, 257 insertions(+) create mode 100644 templates/clock-worker-deployment.yaml diff --git a/templates/api-deployment.yaml b/templates/api-deployment.yaml index 9f160a4..2a3efe0 100644 --- a/templates/api-deployment.yaml +++ b/templates/api-deployment.yaml @@ -146,6 +146,8 @@ spec: value: {{ .Values.webhookWorker.enabled | quote }} - name: SIDEKIQ_BILLING value: {{ .Values.billingWorker.enabled | quote }} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote }} {{- with .Values.api.extraEnv }} {{- range $key, $value := . }} - name: {{ $key }} diff --git a/templates/billing-worker-deployment.yaml b/templates/billing-worker-deployment.yaml index 790d57f..548181b 100644 --- a/templates/billing-worker-deployment.yaml +++ b/templates/billing-worker-deployment.yaml @@ -119,6 +119,8 @@ spec: value: {{ .Values.webhookWorker.enabled | quote }} - name: SIDEKIQ_BILLING value: {{ .Values.billingWorker.enabled | quote }} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote }} {{- with .Values.billingWorker.extraEnv }} {{- range $key, $value := . }} - name: {{ $key }} diff --git a/templates/clock-worker-deployment.yaml b/templates/clock-worker-deployment.yaml new file mode 100644 index 0000000..fc6965c --- /dev/null +++ b/templates/clock-worker-deployment.yaml @@ -0,0 +1,223 @@ +{{- if .Values.clockWorker.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.lago.service: {{ .Release.Name }}-clock-worker + name: {{ .Release.Name }}-clock-worker +spec: + replicas: {{ .Values.clockWorker.replicas }} + selector: + matchLabels: + io.lago.service: {{ .Release.Name }}-clock-worker + strategy: + type: Recreate + template: + metadata: + labels: + io.lago.service: {{ .Release.Name }}-clock-worker + {{- range $key, $value := .Values.clockWorker.podLabels }} + {{ $key }}: {{ $value | quote }} + {{- end }} + annotations: + {{- range $key, $value := .Values.clockWorker.podAnnotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + spec: + {{- with .Values.clockWorker.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.clockWorker.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.clockWorker.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + initContainers: + {{ if .Values.redis.enabled }} + - name: wait-for-redis + image: "docker.io/bitnami/kubectl:{{ include "kubectlVersion" . }}" + args: + - wait + - pod/{{ .Release.Name }}-redis-master-0 + - --for=condition=ready + - --timeout=180s + {{ end }} + - name: wait-for-migrations + image: "docker.io/bitnami/kubectl:{{ include "kubectlVersion" . }}" + args: + - wait + - job/{{ include "migrateJobName" . }} + - --for=condition=complete + - --timeout=180s + containers: + - args: ["./scripts/start.clock.worker.sh"] + env: + - name: RAILS_ENV + value: {{ .Values.clockWorker.rails.env }} + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ include "secret-path" . }} + key: databaseUrl + - name: REDIS_URL + valueFrom: + secretKeyRef: + name: {{ include "secret-path" . }} + key: redisUrl + - name: LAGO_REDIS_CACHE_URL + valueFrom: + secretKeyRef: + name: {{ include "secret-path" . }} + key: redisUrl + - name: LAGO_PDF_URL + {{- $pdfHost := printf "%s-pdf-svc.%s" .Release.Name .Release.Namespace }} + value: {{ printf "http://%s:%v" $pdfHost .Values.pdf.service.port | quote }} + - name: LAGO_API_URL + value: {{ required "apiUrl value is required" .Values.apiUrl | quote }} + - name: LAGO_FRONT_URL + value: {{ required "frontUrl value is required" .Values.frontUrl | quote }} + - name: RAILS_LOG_TO_STDOUT + value: {{ .Values.clockWorker.rails.logStdout | quote }} + - name: LAGO_RSA_PRIVATE_KEY + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: rsaPrivateKey + - name: SECRET_KEY_BASE + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: secretKeyBase + - name: ENCRYPTION_DETERMINISTIC_KEY + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: encryptionDeterministicKey + - name: ENCRYPTION_KEY_DERIVATION_SALT + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: encryptionKeyDerivationSalt + - name: ENCRYPTION_PRIMARY_KEY + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: encryptionPrimaryKey + - name: LAGO_DISABLE_SEGMENT + value: {{ not .Values.global.segment.enabled | quote }} + - name: DATABASE_POOL + value: {{ .Values.billingWorker.rails.sidekiqConcurrency | quote }} + - name: SIDEKIQ_CONCURRENCY + value: {{ .Values.billingWorker.rails.sidekiqConcurrency | quote }} + - name: LAGO_LOG_LEVEL + value: {{ .Values.billingWorker.rails.logLevel | quote }} + - name: SIDEKIQ_WEBHOOK + value: {{ .Values.webhookWorker.enabled | quote }} + - name: SIDEKIQ_BILLING + value: {{ .Values.billingWorker.enabled | quote }} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote }} + {{- with .Values.clockWorker.extraEnv }} + {{- range $key, $value := . }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + {{ if .Values.global.license }} + - name: LAGO_LICENSE + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: license + {{ end }} + + {{ if or .Values.global.s3.enabled .Values.minio.enabled }} + - name: LAGO_USE_AWS_S3 + value: "true" + {{- if .Values.minio.enabled }} + - name: LAGO_AWS_S3_PATH_STYLE + value: "true" + {{- end }} + {{- if or .Values.global.s3.endpoint .Values.minio.endpoint }} + - name: LAGO_AWS_S3_ENDPOINT + value: {{ if .Values.minio.enabled }} + {{ .Values.minio.endpoint | quote }} + {{ else }} + {{ .Values.global.s3.endpoint | quote }} + {{ end }} + {{- end }} + {{- if or .Values.global.s3.accessKeyId .Values.minio.enabled .Values.global.existingSecret }} + - name: LAGO_AWS_S3_ACCESS_KEY_ID + valueFrom: + secretKeyRef: + name: {{ if .Values.minio.enabled }} + {{ .Release.Name }}-minio + {{ else }} + {{ include "secret-path" . }} + {{ end }} + key: {{ if .Values.minio.enabled }} + rootUser + {{ else }} + awsS3AccessKeyId + {{ end }} + {{- end }} + {{- if or .Values.global.s3.secretAccessKey .Values.minio.enabled .Values.global.existingSecret }} + - name: LAGO_AWS_S3_SECRET_ACCESS_KEY + valueFrom: + secretKeyRef: + name: {{ if .Values.minio.enabled }} + {{ .Release.Name }}-minio + {{ else }} + {{ include "secret-path" . }} + {{ end }} + key: {{ if .Values.minio.enabled }} + rootPassword + {{ else }} + awsS3SecretAccessKey + {{ end }} + {{- end }} + - name: LAGO_AWS_S3_BUCKET + value: {{ if .Values.minio.enabled }} + {{ (index .Values.minio.buckets 0).name | quote }} + {{ else }} + {{ .Values.global.s3.bucket | quote }} + {{ end }} + - name: LAGO_AWS_S3_REGION + value: {{ if .Values.global.s3.enabled }} + {{ .Values.global.s3.region | quote }} + {{ else if .Values.minio.enabled }} + {{ default "us-east-1" .Values.minio.region | quote }} + {{ end }} + {{ end }} + + {{ if .Values.global.newRelic.enabled }} + - name: NEW_RELIC_KEY + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-secrets + key: newRelicKey + {{ end }} + image: getlago/api:v{{ .Values.version }} + name: {{ .Release.Name }}-clock-worker + {{- with .Values.clockWorker.resources }} + resources: + {{- toYaml . | nindent 12}} + {{- end }} + {{ if and (not .Values.global.s3.enabled) (not .Values.minio.enabled) }} + volumeMounts: + - mountPath: /app/storage + name: {{ .Release.Name }}-storage-data + {{ end }} + restartPolicy: Always + {{ if and (not .Values.global.s3.enabled) (not .Values.minio.enabled) }} + volumes: + - name: {{ .Release.Name }}-storage-data + persistentVolumeClaim: + claimName: {{ .Release.Name }}-storage-data + {{ end }} + serviceAccountName: {{ .Values.global.serviceAccountName | default (printf "%s-serviceaccount" .Release.Name) }} +{{- end -}} \ No newline at end of file diff --git a/templates/events-worker-deployment.yaml b/templates/events-worker-deployment.yaml index 704a0c1..13ac8e1 100644 --- a/templates/events-worker-deployment.yaml +++ b/templates/events-worker-deployment.yaml @@ -109,6 +109,8 @@ spec: value: {{ .Values.webhookWorker.enabled | quote }} - name: SIDEKIQ_BILLING value: {{ .Values.billingWorker.enabled | quote}} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote}} {{- with .Values.eventsWorker.extraEnv }} {{- range $key, $value := . }} - name: {{ $key }} diff --git a/templates/webhook-worker-deployment.yaml b/templates/webhook-worker-deployment.yaml index c881eaf..cb1b079 100644 --- a/templates/webhook-worker-deployment.yaml +++ b/templates/webhook-worker-deployment.yaml @@ -108,6 +108,8 @@ spec: value: "true" - name: SIDEKIQ_BILLING value: {{ .Values.billingWorker.enabled | quote }} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote }} - name: LAGO_LOG_LEVEL value: {{ .Values.webhookWorker.rails.logLevel | quote }} {{- with .Values.webhookWorker.extraEnv }} diff --git a/templates/worker-deployment.yaml b/templates/worker-deployment.yaml index f69c8c5..7b331e3 100644 --- a/templates/worker-deployment.yaml +++ b/templates/worker-deployment.yaml @@ -118,6 +118,8 @@ spec: value: {{ .Values.webhookWorker.enabled | quote }} - name: SIDEKIQ_BILLING value: {{ .Values.billingWorker.enabled | quote}} + - name: SIDEKIQ_CLOCK + value: {{ .Values.clockWorker.enabled | quote}} {{- with .Values.worker.extraEnv }} {{- range $key, $value := . }} - name: {{ $key }} diff --git a/values.yaml b/values.yaml index 83d61df..f062aa5 100644 --- a/values.yaml +++ b/values.yaml @@ -184,6 +184,30 @@ eventsWorker: nodeSelector: {} affinity: {} +clockWorker: + enabled: true + replicas: 1 + rails: + sidekiqConcurrency: 20 + env: 'production' + logStdout: true + logLevel: error + resources: + requests: + memory: 1Gi + cpu: '1100m' + podAnnotations: {} + podLabels: {} + extraEnv: {} + livenessProbe: + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + tolerations: [] + nodeSelector: {} + affinity: {} + clock: replicas: 1 rails: