Skip to content

Commit 4695e4e

Browse files
authored
Merge pull request #2 from movetokube/feat/operatorhub
Feat/operatorhub
2 parents a5790f9 + 6164b18 commit 4695e4e

10 files changed

Lines changed: 268 additions & 25 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PostgreSQL operator for Kubernetes
1+
# External PostgreSQL server operator for Kubernetes
22

33
## Features
44
* creates a database

deploy/dev/postgres.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: postgres
5+
namespace: databases
56
spec:
67
selector:
78
app: postgres
@@ -16,6 +17,7 @@ apiVersion: v1
1617
kind: ConfigMap
1718
metadata:
1819
name: postgres-config
20+
namespace: databases
1921
labels:
2022
app: postgres
2123
data:
@@ -29,6 +31,7 @@ apiVersion: extensions/v1beta1
2931
kind: Deployment
3032
metadata:
3133
name: postgres
34+
namespace: databases
3235
spec:
3336
replicas: 1
3437
template:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
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+
validation:
14+
openAPIV3Schema:
15+
properties:
16+
apiVersion:
17+
description: 'APIVersion defines the versioned schema of this representation
18+
of an object. Servers should convert recognized schemas to the latest
19+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
20+
type: string
21+
kind:
22+
description: 'Kind is a string value representing the REST resource this
23+
object represents. Servers may infer this from the endpoint the client
24+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
25+
type: string
26+
metadata:
27+
type: object
28+
spec:
29+
type: object
30+
status:
31+
type: object
32+
version: v1alpha1
33+
versions:
34+
- name: v1alpha1
35+
served: true
36+
storage: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packageName: ext-postgres-operator
2+
channels:
3+
- name: stable
4+
currentCSV: ext-postgres-operator.v0.2.0
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
apiVersion: operators.coreos.com/v1alpha1
2+
kind: ClusterServiceVersion
3+
metadata:
4+
annotations:
5+
alm-examples: '[{"apiVersion":"db.movetokube.com/v1alpha1","kind":"Postgres","metadata":{"name":"my-db","namespace":"app"},"spec":{"database":"test-db","secretName":"my-secret"}}]'
6+
capabilities: Basic Install
7+
containerImage: movetokube/postgres-operator
8+
description: Manage databases and roles in external PostgreSQL server or cluster
9+
repository: https://github.com/movetokube/postgres-operator
10+
name: ext-postgres-operator.v0.2.0
11+
namespace: placeholder
12+
spec:
13+
apiservicedefinitions: {}
14+
customresourcedefinitions:
15+
owned:
16+
- description: Represents a resource for managing PostgreSQL database associated
17+
role
18+
displayName: postgres.db.movetokube.com
19+
kind: Postgres
20+
name: postgres.db.movetokube.com
21+
version: v1alpha1
22+
description: |-
23+
ext-postgres-operator is an external PostgreSQL database operator. This is a very light-weight basic operator which
24+
does not provide a PostgreSQL server, but rather manages databases inside an existing PostgreSQL database server (or cluster).
25+
### Features
26+
This operator enables you to create roles and databases easily by defining simple Custom Resources. Operator's
27+
features are as follows:
28+
29+
* Creates a database
30+
* Creates a role which has admin access to the database
31+
* Creates a secret role, password and postgres uri
32+
* on CR deletion, reassigns all objects owned by role to **postgres** role, removes role and secret
33+
34+
### Installation
35+
This operator requires a Kubernetes Secret to be created in the **same namespace** as operator itself. Secret should
36+
contain these keys: POSTGRES\_HOST, POSTGRES\_USER, POSTGRES\_PASS, POSTGRES\_URI\_ARGS.
37+
38+
Example
39+
```yaml
40+
apiVersion: v1
41+
kind: Secret
42+
metadata:
43+
name: ext-postgres-operator
44+
namespace: operators
45+
type: Opaque
46+
data:
47+
POSTGRES_HOST: postgres
48+
POSTGRES_USER: postgres
49+
POSTGRES_PASS: admin
50+
POSTGRES_URI_ARGS:
51+
```
52+
53+
### Custom Resources
54+
Custom Resource is very simple for this operator, it only supports two keys in specification, which are defined below
55+
* `spec.database` - name of PostgreSQL database that should be created (if it does not exist)
56+
* `spec.secretName` - name of the secret that will contain `ROLE`, `PASSWORD` and `POSTGRES_URL`. The final secret
57+
name will be format: **spec.secretName**-**CR.metadata.name**
58+
displayName: Ext Postgres Operator
59+
install:
60+
spec:
61+
clusterPermissions:
62+
- rules:
63+
- apiGroups:
64+
- ""
65+
resources:
66+
- pods
67+
- services
68+
- endpoints
69+
- persistentvolumeclaims
70+
- events
71+
- configmaps
72+
- secrets
73+
verbs:
74+
- '*'
75+
- apiGroups:
76+
- apps
77+
resources:
78+
- deployments
79+
- daemonsets
80+
- replicasets
81+
- statefulsets
82+
verbs:
83+
- '*'
84+
- apiGroups:
85+
- monitoring.coreos.com
86+
resources:
87+
- servicemonitors
88+
verbs:
89+
- get
90+
- create
91+
- apiGroups:
92+
- apps
93+
resourceNames:
94+
- postgres-operator
95+
resources:
96+
- deployments/finalizers
97+
verbs:
98+
- update
99+
- apiGroups:
100+
- db.movetokube.com
101+
resources:
102+
- '*'
103+
verbs:
104+
- '*'
105+
serviceAccountName: ext-postgres-operator
106+
deployments:
107+
- name: ext-postgres-operator
108+
spec:
109+
replicas: 1
110+
selector:
111+
matchLabels:
112+
name: ext-postgres-operator
113+
strategy: {}
114+
template:
115+
metadata:
116+
labels:
117+
name: ext-postgres-operator
118+
spec:
119+
containers:
120+
- command:
121+
- postgres-operator
122+
env:
123+
- name: WATCH_NAMESPACE
124+
- name: POD_NAME
125+
valueFrom:
126+
fieldRef:
127+
fieldPath: metadata.name
128+
- name: OPERATOR_NAME
129+
value: ext-postgres-operator
130+
- name: POSTGRES_HOST
131+
valueFrom:
132+
secretKeyRef:
133+
key: POSTGRES_HOST
134+
name: ext-postgres-operator
135+
- name: POSTGRES_USER
136+
valueFrom:
137+
secretKeyRef:
138+
key: POSTGRES_USER
139+
name: ext-postgres-operator
140+
- name: POSTGRES_PASS
141+
valueFrom:
142+
secretKeyRef:
143+
key: POSTGRES_PASS
144+
name: ext-postgres-operator
145+
- name: POSTGRES_URI_ARGS
146+
valueFrom:
147+
secretKeyRef:
148+
key: POSTGRES_URI_ARGS
149+
name: ext-postgres-operator
150+
image: movetokube/postgres-operator:0.2
151+
imagePullPolicy: Always
152+
name: ext-postgres-operator
153+
resources: {}
154+
serviceAccountName: ext-postgres-operator
155+
strategy: deployment
156+
installModes:
157+
- supported: true
158+
type: OwnNamespace
159+
- supported: true
160+
type: SingleNamespace
161+
- supported: false
162+
type: MultiNamespace
163+
- supported: true
164+
type: AllNamespaces
165+
keywords:
166+
- postgres-operator
167+
- postgres
168+
- postgresql
169+
- kubernetes
170+
- database
171+
labels:
172+
name: ext-postgres-operator
173+
links:
174+
- name: movetokube.com
175+
url: https://movetokube.com
176+
maintainers:
177+
- email: tomas@movetokube.com
178+
name: Tomas Adomavicius
179+
maturity: alpha
180+
provider:
181+
name: movetokube.com
182+
version: 0.2.0

deploy/operator.yaml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: postgres-operator
4+
name: ext-postgres-operator
55
namespace: operators
66
spec:
77
replicas: 1
88
selector:
99
matchLabels:
10-
name: postgres-operator
10+
name: ext-postgres-operator
1111
template:
1212
metadata:
1313
labels:
14-
name: postgres-operator
14+
name: ext-postgres-operator
1515
spec:
16-
serviceAccountName: postgres-operator
16+
serviceAccountName: ext-postgres-operator
1717
containers:
18-
- name: postgres-operator
19-
# Replace this with the built image name
18+
- name: ext-postgres-operator
2019
image: movetokube/postgres-operator:0.2
2120
command:
2221
- postgres-operator
@@ -29,8 +28,24 @@ spec:
2928
fieldRef:
3029
fieldPath: metadata.name
3130
- name: OPERATOR_NAME
32-
value: "postgres-operator"
33-
- name: POSTGRES_URL
34-
value: "postgresql://postgres:admin123@postgres:5432?sslmode=disable"
31+
value: "ext-postgres-operator"
3532
- name: POSTGRES_HOST
36-
value: "postgres:5432"
33+
valueFrom:
34+
secretKeyRef:
35+
name: ext-postgres-operator
36+
key: POSTGRES_HOST
37+
- name: POSTGRES_USER
38+
valueFrom:
39+
secretKeyRef:
40+
name: ext-postgres-operator
41+
key: POSTGRES_USER
42+
- name: POSTGRES_PASS
43+
valueFrom:
44+
secretKeyRef:
45+
name: ext-postgres-operator
46+
key: POSTGRES_PASS
47+
- name: POSTGRES_URI_ARGS
48+
valueFrom:
49+
secretKeyRef:
50+
name: ext-postgres-operator
51+
key: POSTGRES_URI_ARGS

deploy/role.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRole
33
metadata:
4-
creationTimestamp: null
5-
name: postgres-operator
4+
name: ext-postgres-operator
65
rules:
76
- apiGroups:
87
- ""
@@ -25,17 +24,10 @@ rules:
2524
- statefulsets
2625
verbs:
2726
- '*'
28-
- apiGroups:
29-
- monitoring.coreos.com
30-
resources:
31-
- servicemonitors
32-
verbs:
33-
- get
34-
- create
3527
- apiGroups:
3628
- apps
3729
resourceNames:
38-
- postgres-operator
30+
- ext-postgres-operator
3931
resources:
4032
- deployments/finalizers
4133
verbs:

deploy/role_binding.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
kind: ClusterRoleBinding
22
apiVersion: rbac.authorization.k8s.io/v1
33
metadata:
4-
name: postgres-operator
4+
name: ext-postgres-operator
55
subjects:
66
- kind: ServiceAccount
7-
name: postgres-operator
7+
name: ext-postgres-operator
88
namespace: operators
99
roleRef:
1010
kind: ClusterRole
11-
name: postgres-operator
11+
name: ext-postgres-operator
1212
apiGroup: rbac.authorization.k8s.io

deploy/secret.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: ext-postgres-operator
5+
namespace: operators
6+
type: Opaque
7+
data:
8+
POSTGRES_HOST: cG9zdGdyZXMuZGF0YWJhc2Vz
9+
POSTGRES_USER: cG9zdGdyZXM=
10+
POSTGRES_PASS: YWRtaW4xMjM=
11+
POSTGRES_URI_ARGS: c3NsbW9kZT1kaXNhYmxl

deploy/service_account.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v1
22
kind: ServiceAccount
33
metadata:
4-
name: postgres-operator
4+
name: ext-postgres-operator
55
namespace: operators

0 commit comments

Comments
 (0)