Skip to content

Commit 67a2d95

Browse files
authored
Add helm chart for the operator installation (#90)
* Add helm chart * Update documentation * Do not override secret on chart updates
1 parent 2421f1e commit 67a2d95

13 files changed

+485
-1
lines changed

.github/workflows/chart.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release Charts
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Configure Git
18+
run: |
19+
git config user.name "$GITHUB_ACTOR"
20+
git config user.email "[email protected]"
21+
22+
- name: Install Helm
23+
uses: azure/setup-helm@v1
24+
with:
25+
version: v3.8.1
26+
27+
- name: Run chart-releaser
28+
uses: helm/[email protected]
29+
with:
30+
charts_dir: charts
31+
env:
32+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ data:
6666
POSTGRES_DEFAULT_DATABASE: cG9zdGdyZXM=
6767
```
6868
69-
To install the operator, follow the steps below.
69+
To install the operator using kustomize, follow the steps below.
7070
7171
1. Configure Postgres credentials for the operator in `deploy/secret.yaml`
7272
2. Create namespace if needed with\
@@ -78,6 +78,15 @@ To install the operator, follow the steps below.
7878
or by using [kustomize](https://github.com/kubernetes-sigs/kustomize) directly\
7979
`kustomize build deploy/ | apply -f -`
8080

81+
Alternatively you can install operator using Helm Chart located in the
82+
`charts/ext-postgres-operator` subdirectory. Sample installation commands provided below:
83+
84+
```
85+
helm repo add ext-postgres-operator https://movetokube.github.io/postgres-operator/
86+
helm install -n operators ext-postgres-operator ext-postgres-operator/ext-postgres-operator
87+
```
88+
See [values.yaml](charts/ext-postgres-operator/values.yaml) for the possible values to define.
89+
8190
## CRs
8291

8392
### Postgres
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v2
2+
name: ext-postgres-operator
3+
description: A Helm chart for the External Postgres operator
4+
5+
type: application
6+
7+
# This is the chart version. This version number should be incremented each time you make changes
8+
# to the chart and its templates, including the app version.
9+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
10+
version: 0.1.2
11+
12+
# This is the version number of the application being deployed. This version number should be
13+
# incremented each time you make changes to the application. Versions are not expected to
14+
# follow Semantic Versioning. They should reflect the version the application is using.
15+
# It is recommended to use it with quotes.
16+
appVersion: "1.1.1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: postgres.db.movetokube.com
5+
spec:
6+
group: db.movetokube.com
7+
names:
8+
kind: Postgres
9+
listKind: PostgresList
10+
plural: postgres
11+
singular: postgres
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
schema:
16+
openAPIV3Schema:
17+
description: Postgres is the Schema for the postgres API
18+
properties:
19+
apiVersion:
20+
description: 'APIVersion defines the versioned schema of this representation
21+
of an object. Servers should convert recognized schemas to the latest
22+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
type: string
24+
kind:
25+
description: 'Kind is a string value representing the REST resource this
26+
object represents. Servers may infer this from the endpoint the client
27+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
28+
type: string
29+
metadata:
30+
type: object
31+
spec:
32+
description: PostgresSpec defines the desired state of Postgres
33+
properties:
34+
database:
35+
type: string
36+
dropOnDelete:
37+
type: boolean
38+
extensions:
39+
items:
40+
type: string
41+
type: array
42+
x-kubernetes-list-type: set
43+
masterRole:
44+
type: string
45+
schemas:
46+
items:
47+
type: string
48+
type: array
49+
x-kubernetes-list-type: set
50+
required:
51+
- database
52+
type: object
53+
status:
54+
description: PostgresStatus defines the observed state of Postgres
55+
properties:
56+
extensions:
57+
items:
58+
type: string
59+
type: array
60+
x-kubernetes-list-type: set
61+
roles:
62+
description: PostgresRoles stores the different group roles for database
63+
properties:
64+
owner:
65+
type: string
66+
reader:
67+
type: string
68+
writer:
69+
type: string
70+
required:
71+
- owner
72+
- reader
73+
- writer
74+
type: object
75+
schemas:
76+
items:
77+
type: string
78+
type: array
79+
x-kubernetes-list-type: set
80+
succeeded:
81+
type: boolean
82+
required:
83+
- roles
84+
- succeeded
85+
type: object
86+
type: object
87+
served: true
88+
storage: true
89+
subresources:
90+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: postgresusers.db.movetokube.com
5+
spec:
6+
group: db.movetokube.com
7+
names:
8+
kind: PostgresUser
9+
listKind: PostgresUserList
10+
plural: postgresusers
11+
singular: postgresuser
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
schema:
16+
openAPIV3Schema:
17+
description: PostgresUser is the Schema for the postgresusers API
18+
properties:
19+
apiVersion:
20+
description: 'APIVersion defines the versioned schema of this representation
21+
of an object. Servers should convert recognized schemas to the latest
22+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
type: string
24+
kind:
25+
description: 'Kind is a string value representing the REST resource this
26+
object represents. Servers may infer this from the endpoint the client
27+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
28+
type: string
29+
metadata:
30+
type: object
31+
spec:
32+
description: PostgresUserSpec defines the desired state of PostgresUser
33+
properties:
34+
database:
35+
type: string
36+
privileges:
37+
type: string
38+
role:
39+
type: string
40+
secretName:
41+
type: string
42+
required:
43+
- database
44+
- role
45+
- secretName
46+
type: object
47+
status:
48+
description: PostgresUserStatus defines the observed state of PostgresUser
49+
properties:
50+
databaseName:
51+
type: string
52+
postgresGroup:
53+
type: string
54+
postgresLogin:
55+
type: string
56+
postgresRole:
57+
type: string
58+
succeeded:
59+
type: boolean
60+
required:
61+
- databaseName
62+
- postgresGroup
63+
- postgresLogin
64+
- postgresRole
65+
- succeeded
66+
type: object
67+
type: object
68+
served: true
69+
storage: true
70+
subresources:
71+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "chart.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "chart.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "chart.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "chart.labels" -}}
37+
helm.sh/chart: {{ include "chart.chart" . }}
38+
{{ include "chart.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "chart.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "chart.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{- define "chart.selectorLabelsDev" -}}
54+
app.kubernetes.io/name: {{ include "chart.name" . }}-dev
55+
app.kubernetes.io/instance: {{ .Release.Name }}-dev
56+
{{- end }}
57+
58+
{{/*
59+
Create the name of the service account to use
60+
*/}}
61+
{{- define "chart.serviceAccountName" -}}
62+
{{- default (include "chart.fullname" .) .Values.serviceAccount.name }}
63+
{{- end }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "chart.fullname" . }}
5+
labels:
6+
{{- include "chart.labels" . | nindent 4 }}
7+
namespace: {{ .Release.Namespace }}
8+
spec:
9+
replicas: {{ .Values.replicaCount }}
10+
selector:
11+
matchLabels:
12+
{{- include "chart.selectorLabels" . | nindent 6 }}
13+
template:
14+
metadata:
15+
{{- with .Values.podAnnotations }}
16+
annotations:
17+
{{- toYaml . | nindent 8 }}
18+
{{- end }}
19+
labels:
20+
{{- include "chart.selectorLabels" . | nindent 8 }}
21+
spec:
22+
serviceAccountName: {{ include "chart.serviceAccountName" . }}
23+
securityContext:
24+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
25+
containers:
26+
- name: {{ .Chart.Name }}
27+
securityContext:
28+
{{- toYaml .Values.securityContext | nindent 12 }}
29+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
30+
command:
31+
- postgres-operator
32+
imagePullPolicy: {{ .Values.image.pullPolicy }}
33+
envFrom:
34+
- secretRef:
35+
name: {{ include "chart.fullname" . }}
36+
env:
37+
- name: WATCH_NAMESPACE
38+
value: ""
39+
- name: POD_NAME
40+
valueFrom:
41+
fieldRef:
42+
fieldPath: metadata.name
43+
- name: OPERATOR_NAME
44+
value: {{ include "chart.fullname" . }}

0 commit comments

Comments
 (0)