Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit 1e512f8

Browse files
committed
registry: add support for percona mongodb clusters
Percona is one of the better-used database providers in k8s. Supporting them as best as we can in SBO will be to our benefit. Signed-off-by: Andy Sadler <[email protected]>
1 parent 2253974 commit 1e512f8

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

config/rbac/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resources:
1313
# operators supproted out of the box
1414
- opstree_redis_clusterrole.yaml
1515
- crunchy_postgres_clusterrole.yaml
16+
- percona_mongodb_clusterrole.yaml
1617
# Comment the following 4 lines if you want to disable
1718
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
1819
# which protects your /metrics endpoint.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: percona-mongodb-view
5+
labels:
6+
servicebinding.io/controller: "true"
7+
rules:
8+
- apiGroups:
9+
- psmdb.percona.com
10+
resources:
11+
- perconaservermongodbs
12+
verbs:
13+
- get
14+
- list

controllers/crd/crd_controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ var bindingAnnotations = map[schema.GroupVersionKind]map[string]string{
4848
"service.binding/database": "path={.metadata.name}-pguser-{.metadata.name},objectType=Secret,sourceKey=dbname",
4949
"service.binding/username": "path={.metadata.name}-pguser-{.metadata.name},objectType=Secret,sourceKey=user",
5050
},
51+
schema.GroupVersionKind{Group: "psmdb.percona.com", Version: "v1-9-0", Kind: "PerconaServerMongoDb"}: {
52+
"service.binding/type": "percona-mongodb",
53+
"service.binding": "path={.spec.secrets.users},objectType=Secret",
54+
"service.binding/host": "path={.status.host}",
55+
"service.binding/replset": "path={.status.replsets[0].name}",
56+
},
57+
schema.GroupVersionKind{Group: "psmdb.percona.com", Version: "v1-10-0", Kind: "PerconaServerMongoDb"}: {
58+
"service.binding/type": "percona-mongodb",
59+
"service.binding": "path={.spec.secrets.users},objectType=Secret",
60+
"service.binding/host": "path={.status.host}",
61+
"service.binding/replset": "path={.status.replsets[0].name}",
62+
},
5163
}
5264

5365
// CrdReconciler reconciles a CustomResourceDefinition resources
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from olm import Operator
2+
from environment import ctx
3+
from behave import given
4+
5+
6+
class PerconaMongoDBOperator(Operator):
7+
8+
def __init__(self, name="percona-server-mongodb-operator"):
9+
self.name = name
10+
if ctx.cli == "oc":
11+
self.operator_catalog_source_name = "community-operators"
12+
else:
13+
self.operator_catalog_source_name = "operatorhubio-catalog"
14+
self.operator_catalog_channel = "stable"
15+
self.package_name = name
16+
17+
18+
@given(u'Percona MongoDB operator is running')
19+
def install_percona_mongodb_operator(_context):
20+
operator = PerconaMongoDBOperator()
21+
if not operator.is_running():
22+
operator.install_operator_subscription()
23+
operator.is_running(wait=True)
24+
print("Percona MongoDB operator is running")

test/acceptance/features/supportExistingOperatorBackedServices.feature

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,122 @@ Feature: Support a number of existing operator-backed services out of the box
158158
hippo
159159
"""
160160
And File "/bindings/$scenario_id/password" exists in application pod
161+
162+
Scenario: Bind test application to MongoDB provisioned by Percona's MongoDB operator
163+
Given Crunchy Data Postgres operator is running
164+
* Generic test application is running
165+
* The secret is present
166+
"""
167+
apiVersion: v1
168+
kind: Secret
169+
metadata:
170+
name: my-cluster-name-secrets
171+
type: Opaque
172+
stringData:
173+
MONGODB_BACKUP_USER: backup
174+
MONGODB_BACKUP_PASSWORD: backup123456
175+
MONGODB_CLUSTER_ADMIN_USER: clusterAdmin
176+
MONGODB_CLUSTER_ADMIN_PASSWORD: clusterAdmin123456
177+
MONGODB_CLUSTER_MONITOR_USER: clusterMonitor
178+
MONGODB_CLUSTER_MONITOR_PASSWORD: clusterMonitor123456
179+
MONGODB_USER_ADMIN_USER: userAdmin
180+
MONGODB_USER_ADMIN_PASSWORD: userAdmin123456
181+
PMM_SERVER_USER: pmm
182+
PMM_SERVER_PASSWORD: supa|^|pazz
183+
"""
184+
* The Custom Resource is present
185+
"""
186+
apiVersion: psmdb.percona.com
187+
kind: PerconaServerMongoDB
188+
metadata:
189+
name: minimal-cluster
190+
annotations:
191+
service.binding/replset: path={.spec.replsets[0].name}
192+
service.binding/host: path={.status.host}
193+
service.binding/username: path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_USER
194+
service.binding/password: path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_PASSWORD
195+
spec:
196+
crVersion: 1.9.0
197+
image: percona/percona-server-mongodb:4.4.8-9
198+
allowUnsafeConfigurations: true
199+
upgradeOptions:
200+
apply: 4.4-recommended
201+
schedule: "0 2 * * *"
202+
secrets:
203+
users: minimal-cluster-secrets
204+
replsets:
205+
- name: rs0
206+
size: 1
207+
volumeSpec:
208+
persistentVolumeClaim:
209+
resources:
210+
requests:
211+
storage: 1Gi
212+
sharding:
213+
enabled: false
214+
"""
215+
When Service Binding is applied
216+
"""
217+
apiVersion: binding.operators.coreos.com/v1alpha1
218+
kind: ServiceBinding
219+
metadata:
220+
name: $scenario_id
221+
spec:
222+
services:
223+
- group: psmdb.percona.com
224+
version: v1-10-0
225+
kind: PerconaServerMongoDB
226+
name: minimal-cluster
227+
application:
228+
name: $scenario_id
229+
group: apps
230+
version: v1
231+
resource: deployments
232+
"""
233+
Then Service Binding is ready
234+
And Kind PerconaServerMongoDB with apiVersion psmdb.percona.com/v1-10-0 is listed in bindable kinds
235+
And Content of file "/bindings/$scenario_id/MONGODB_BACKUP_USER" in application pod is
236+
"""
237+
backup
238+
"""
239+
And Content of file "/bindings/$scenario_id/MONGODB_BACKUP_PASSWORD" in application pod is
240+
"""
241+
backup123456
242+
"""
243+
And Content of file "/bindings/$scenario_id/MONGODB_CLUSTER_ADMIN_USER" in application pod is
244+
"""
245+
clusterAdmin
246+
"""
247+
And Content of file "/bindings/$scenario_id/MONGODB_CLUSTER_ADMIN_PASSWORD" in application pod is
248+
"""
249+
clusterAdmin123456
250+
"""
251+
And Content of file "/bindings/$scenario_id/MONGODB_CLUSTER_MONITOR_USER" in application pod is
252+
"""
253+
clusterMonitor
254+
"""
255+
And Content of file "/bindings/$scenario_id/MONGODB_CLUSTER_MONITOR_PASSWORD" in application pod is
256+
"""
257+
clusterMonitor123456
258+
"""
259+
And Content of file "/bindings/$scenario_id/MONGODB_USER_ADMIN_USER" in application pod is
260+
"""
261+
userAdmin
262+
"""
263+
And Content of file "/bindings/$scenario_id/MONGODB_USER_ADMIN_PASSWORD" in application pod is
264+
"""
265+
userAdmin123456
266+
"""
267+
And Content of file "/bindings/$scenario_id/PMM_SERVER_USER" in application pod is
268+
"""
269+
pmm
270+
"""
271+
And Content of file "/bindings/$scenario_id/PMM_SERVER_PASSWORD" in application pod is
272+
"""
273+
supa|^|pazz
274+
"""
275+
And Content of file "/bindings/$scenario_id/replset" in application pod is
276+
"""
277+
rs0
278+
"""
279+
And File "/bindings/$scenario_id/host" exists in application pod

0 commit comments

Comments
 (0)