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

Add PgBouncer #168

Merged
merged 13 commits into from
Aug 22, 2023
15 changes: 15 additions & 0 deletions charts/studio/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

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

{{/*
Selector labels
*/}}
Expand Down Expand Up @@ -122,6 +131,12 @@ app.kubernetes.io/name: studio-worker
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "pgbouncer.selectorLabels" -}}
app.kubernetes.io/name: pgbouncer
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}


{{/*
Create the name of the service account to use
*/}}
Expand Down
66 changes: 66 additions & 0 deletions charts/studio/templates/deployment-pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{.Release.Name}}-pgbouncer
labels:
{{- include "pgbouncer.labels" . | nindent 4 }}
spec:
{{- if not .Values.pgBouncer.autoscaling.enabled }}
replicas: {{ .Values.pgBouncer.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "pgbouncer.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- include "studio.checksum" . | indent 8 }}
{{- with .Values.pgBouncer.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "pgbouncer.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ .Values.pgBouncer.serviceAccountName }}
securityContext:
{{- with .Values.pgBouncer.podSecurityContext }}
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: pgbouncer
securityContext:
{{- toYaml .Values.pgBouncer.securityContext | nindent 12 }}
image: "{{ .Values.pgBouncer.image.repository }}:{{ .Values.pgBouncer.image.tag }}"
imagePullPolicy: {{ .Values.pgBouncer.image.pullPolicy }}
resources:
{{- toYaml .Values.pgBouncer.resources | nindent 12 }}
env:
- name: PGBOUNCER_PORT
value: "6432"
envFrom:
- secretRef:
name: pgbouncer
{{- if .Values.pgBouncer.envFromSecret }}
- secretRef:
name: {{ .Values.pgBouncer.envFromSecret }}
{{- end }}
ports:
- name: pgbouncer
containerPort: 6432
protocol: TCP
{{- with .Values.pgBouncer.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.pgBouncer.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.pgBouncer.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/studio/templates/deployment-studio-dvcx-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
securityContext:
fsGroup: 103
fsGroupChangePolicy: "OnRootMismatch"
{{- with .Values.studioWorker.podSecurityContext }}
{{- with .Values.studioDvcxWorker.podSecurityContext }}
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
Expand Down
18 changes: 18 additions & 0 deletions charts/studio/templates/secret-pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Secret
metadata:
name: pgbouncer
{{ if (not (hasKey .Values "ci")) }} # Add annotation if we're not in CI execution.
annotations:
helm.sh/resource-policy: "keep"
argocd.argoproj.io/sync-options: Delete=false
{{- end }}
labels:
{{- include "studio.labels" . | nindent 4 }}
type: Opaque
stringData:
POSTGRESQL_USERNAME: {{ .Values.global.postgres.user | quote }}
POSTGRESQL_PASSWORD: {{ .Values.global.postgres.password | quote }}
POSTGRESQL_DATABASE: {{ .Values.global.postgres.databaseName | quote }}
POSTGRESQL_HOST: {{ .Values.global.postgres.host | quote }}
POSTGRESQL_PORT: {{ .Values.global.postgres.port | quote }}
10 changes: 2 additions & 8 deletions charts/studio/templates/secret-studio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ metadata:
{{- include "studio.labels" . | nindent 4 }}
type: Opaque
stringData:
{{- if .Values.global.postgres.databaseUrl }}
# Deprecated configuration format.
# Will be removed in a future release
DATABASE_URL: "psql://{{ .Values.global.postgres.databaseUser}}:{{ .Values.global.postgres.databasePassword }}@{{ .Values.global.postgres.databaseUrl }}"
{{- else }}
mjasion marked this conversation as resolved.
Show resolved Hide resolved
DATABASE_USER: {{ .Values.global.postgres.user | quote }}
DATABASE_PASSWORD: {{ .Values.global.postgres.password | quote }}
DATABASE_NAME: {{ .Values.global.postgres.databaseName | quote }}
DATABASE_HOST: {{ .Values.global.postgres.host | quote }}
DATABASE_PORT: {{ .Values.global.postgres.port | quote }}
{{- end }}
DATABASE_HOST: "pgbouncer.{{ .Release.Namespace }}.svc.cluster.local"
DATABASE_PORT: {{ .Values.pgBouncer.service.port | quote }}

{{- if .Values.global.scmProviders.gitlab.clientId }}
GITLAB_CLIENT_ID: {{ .Values.global.scmProviders.gitlab.clientId | quote }}
Expand Down
15 changes: 15 additions & 0 deletions charts/studio/templates/service-pgbouncer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: pgbouncer
labels:
{{- include "pgbouncer.labels" . | nindent 4 }}
spec:
type: {{ .Values.pgBouncer.service.type }}
ports:
- port: {{ .Values.pgBouncer.service.port }}
targetPort: pgbouncer
protocol: TCP
name: pgbouncer
selector:
{{- include "pgbouncer.selectorLabels" . | nindent 4 }}
89 changes: 89 additions & 0 deletions charts/studio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,95 @@ ray:
minimum: 1
maximum: 4

# -- PgBouncer settings group
pgBouncer:
# -- PgBouncer image settings
image:
# -- PgBouncer image repository
repository: docker.io/bitnami/pgbouncer
# -- PgBouncer image pull policy
pullPolicy: IfNotPresent
# -- PgBouncer image tag
tag: "1.20.1"

service:
type: ClusterIP
port: 6432

# -- Additional environment variables for PgBouncer pods
envVars: {}
# Example:
# envVars:
# DEBUG: "True"

# -- The name of an existing Secret that contains sensitive environment variables passed to DVCx
# worker pods.
envFromSecret: ""

replicaCount: 1

# -- PgBouncer resources configuration
resources:
# -- PgBouncer requests configuration
requests:
cpu: 500m
memory: 512Mi
# -- PgBouncer limits configuration
limits:
cpu: 1000m
memory: 1024Mi

# -- PgBouncer autoscaling configuration
autoscaling:
# -- PgBouncer autoscaling enabled flag
enabled: false
# -- PgBouncer autoscaling min replicas
minReplicas: 1
# -- PgBouncer autoscaling max replicas
maxReplicas: 5
# -- PgBouncer autoscaling target CPU utilization percentage
targetCPUUtilizationPercentage: 80
# -- PgBouncer autoscaling target memory utilization percentage
# targetMemoryUtilizationPercentage: 80

# -- Additional PgBouncer pod annotations
podAnnotations: {}

# -- PgBouncer pod security context configuration
podSecurityContext: {}
# fsGroup: 2000

# -- PgBouncer pod security context configuration
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

# -- PgBouncer service account name
serviceAccountName: ""

# -- PgBouncer pod node selector configuration
nodeSelector: {}

# -- PgBouncer pod tolerations configuration
tolerations: []

# -- PgBouncer pod affinity configuration
affinity: {}

serviceAccount:
# Specifies whether a service account should be created
create: false
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
jesper7 marked this conversation as resolved.
Show resolved Hide resolved


# -- Studio UI settings group
studioUi:
# -- Additional environment variables for ui pods
Expand Down
Loading