Skip to content

Commit

Permalink
Merge pull request #85 from pmint93/pgbouncer-chart
Browse files Browse the repository at this point in the history
[charts/pgbouncer] Add pgbouncer chart
  • Loading branch information
pmint93 authored Nov 10, 2023
2 parents 808e378 + c8a5c57 commit da1bc38
Show file tree
Hide file tree
Showing 12 changed files with 719 additions and 2 deletions.
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Contributions are welcome via GitHub pull requests. This document outlines the p

Isssues or Pull requests to a chart should be created with prefix `[charts/<name>]` eg: `[charts/metabase]`

_For now, there's only one chart, then this is just a best practice_

**Bumping chart version**

Every PR should include chart version bump, because we can not have different version of the charts with the same version name.
Expand Down
23 changes: 23 additions & 0 deletions charts/pgbouncer/.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/
10 changes: 10 additions & 0 deletions charts/pgbouncer/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v2
name: pgbouncer
version: "0.1.0"
description: A Helm chart for Pgbouncer
type: application
home: https://github.com/pmint93/helm-charts
maintainers:
- name: pmint93
url: https://github.com/pmint93
appVersion: "v1.21.0"
32 changes: 32 additions & 0 deletions charts/pgbouncer/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
PgBouncer has been installed!

{{- if contains "NodePort" .Values.service.type }}

PgBouncer is exposed as a `NodePort` type service.
Get the address by running these commands:

export NODE_PORT=$(kubectl --namespace {{ .Release.Namespace }} get services -o jsonpath="{.spec.ports[0].nodePort}" {{ include "pgbouncer.fullname" . }})
export NODE_IP=$(kubectl --namespace {{ .Release.Namespace }} get nodes -o jsonpath="{.items[0].status.addresses[1].address}")

echo "Connect to PgBouncer by using IP address: $NODE_IP and port number: $NODE_PORT"

{{- else if contains "LoadBalancer" .Values.service.type }}

PgBouncer is exposed as a `LoadBalancer` type service.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "pgbouncer.fullname" . }}'

export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "pgbouncer.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo "Connect to PgBouncer by using IP address: $SERVICE_IP and port number: {{ .Values.service.port }}"

{{- else if contains "ClusterIP" .Values.service.type }}

PgBouncer is exposed as a `ClusterIP` type service.
Get the address by running these commands:

export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "pgbouncer.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Connect to PgBouncer by using IP address: 127.0.0.1 and port number: 5432"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 5432:$CONTAINER_PORT

{{- end }}
51 changes: 51 additions & 0 deletions charts/pgbouncer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "pgbouncer.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 "pgbouncer.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 "pgbouncer.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "pgbouncer.labels" -}}
helm.sh/chart: {{ include "pgbouncer.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
*/}}
{{- define "pgbouncer.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pgbouncer.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/pgbouncer/templates/_pgbouncer-other.ini.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "pgbouncer-other.ini" -}}
{{- range $k, $v := .Values.extraSettings -}}
{{ $k }} = {{ $v }}
{{- end -}}
{{- end -}}
Loading

0 comments on commit da1bc38

Please sign in to comment.