Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workers): Add dedicated clock worker #131

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions templates/billing-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
223 changes: 223 additions & 0 deletions templates/clock-worker-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}
2 changes: 2 additions & 0 deletions templates/events-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions templates/webhook-worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions templates/worker-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 24 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading