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

Commit 84f931d

Browse files
sadlerappedjak
authored andcommitted
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 2969ffd commit 84f931d

File tree

6 files changed

+148
-5
lines changed

6 files changed

+148
-5
lines changed

config/rbac/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ resources:
1515
- crunchy_postgres_clusterrole.yaml
1616
- percona_mysql_clusterrole.yaml
1717
- cloud_native_postgres_clusterrole.yaml
18+
- percona_mongodb_clusterrole.yaml
1819
# Comment the following 4 lines if you want to disable
1920
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
2021
# 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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,23 @@ var bindingAnnotations = map[schema.GroupVersionKind]map[string]string{
6161
"service.binding": "path={.spec.secretsName},objectType=Secret",
6262
"service.binding/host": "path={.status.host}",
6363
"service.binding/username": "root",
64-
"service.binding/password": "path={.spec.secretsName},objectType=Secret,sourceKey=root",
64+
"service.binding/password": "path={.spec.secretsName},objectTyp=Secret,sourceKey=root",
65+
},
66+
schema.GroupVersionKind{Group: "psmdb.percona.com", Version: "v1-9-0", Kind: "PerconaServerMongoDB"}: {
67+
"service.binding/type": "mongodb",
68+
"service.binding/provider": "percona",
69+
"service.binding": "path={.spec.secrets.users},objectType=Secret",
70+
"service.binding/username": "path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_USER",
71+
"service.binding/password": "path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_PASSWORD",
72+
"service.binding/host": "path={.status.host}",
73+
},
74+
schema.GroupVersionKind{Group: "psmdb.percona.com", Version: "v1-10-0", Kind: "PerconaServerMongoDB"}: {
75+
"service.binding/type": "mongodb",
76+
"service.binding/provider": "percona",
77+
"service.binding": "path={.spec.secrets.users},objectType=Secret",
78+
"service.binding/username": "path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_USER",
79+
"service.binding/password": "path={.spec.secrets.users},objectType=Secret,sourceKey=MONGODB_USER_ADMIN_PASSWORD",
80+
"service.binding/host": "path={.status.host}",
6581
},
6682
schema.GroupVersionKind{Group: "postgresql.k8s.enterprisedb.io", Version: "v1", Kind: "Cluster"}: {
6783
"service.binding/type": "postgresql",

pkg/util/util_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func TestService(t *testing.T) {
1515
var _ = Describe("Merge Map", func() {
1616

1717
It("should merge two maps", func() {
18-
m1 := map[string]string {
18+
m1 := map[string]string{
1919
"foo": "bar",
2020
}
21-
m2 := map[string]string {
21+
m2 := map[string]string{
2222
"bar": "foo",
2323
}
2424
m3 := MergeMaps(m1, m2)
@@ -30,15 +30,15 @@ var _ = Describe("Merge Map", func() {
3030

3131
It("should return src map if dst is uninitialized", func() {
3232
var m1 map[string]string
33-
m2 := map[string]string {
33+
m2 := map[string]string{
3434
"bar": "foo",
3535
}
3636
m3 := MergeMaps(m1, m2)
3737
Expect(m3).To(Equal(m2))
3838
})
3939
It("should return dst map if src is uninitialized", func() {
4040
var m1 map[string]string
41-
m2 := map[string]string {
41+
m2 := map[string]string{
4242
"bar": "foo",
4343
}
4444
m3 := MergeMaps(m2, m1)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
operator.openshift.operators_namespace = context.namespace.name
22+
if not operator.is_running():
23+
subscription = f'''
24+
---
25+
apiVersion: operators.coreos.com/v1
26+
kind: OperatorGroup
27+
metadata:
28+
name: operatorgroup
29+
namespace: {operator.openshift.operators_namespace}
30+
spec:
31+
targetNamespaces:
32+
- {operator.openshift.operators_namespace}
33+
---
34+
apiVersion: operators.coreos.com/v1alpha1
35+
kind: Subscription
36+
metadata:
37+
name: '{operator.name}'
38+
namespace: {operator.openshift.operators_namespace}
39+
spec:
40+
channel: '{operator.operator_catalog_channel}'
41+
installPlanApproval: Automatic
42+
name: '{operator.package_name}'
43+
source: '{operator.operator_catalog_source_name}'
44+
sourceNamespace: {operator.openshift.olm_namespace}
45+
'''
46+
print(subscription)
47+
operator.openshift.apply(subscription)
48+
operator.is_running(wait=True)
49+
print("Percona MongoDB operator is running")

test/acceptance/features/supportExistingOperatorBackedServices.feature

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,66 @@ Feature: Support a number of existing operator-backed services out of the box
290290
app
291291
"""
292292
And File "/bindings/$scenario_id/password" exists in application pod
293+
294+
Scenario: Bind test application to MongoDB provisioned by Percona's MongoDB operator
295+
Given Percona MongoDB operator is running
296+
* Generic test application is running
297+
* The Custom Resource is present
298+
"""
299+
apiVersion: psmdb.percona.com/v1-9-0
300+
kind: PerconaServerMongoDB
301+
metadata:
302+
name: minimal-cluster
303+
spec:
304+
crVersion: 1.9.0
305+
image: percona/percona-server-mongodb:4.4.8-9
306+
allowUnsafeConfigurations: true
307+
upgradeOptions:
308+
apply: 4.4-recommended
309+
schedule: "0 2 * * *"
310+
secrets:
311+
users: minimal-cluster-secrets
312+
replsets:
313+
- name: rs0
314+
size: 1
315+
volumeSpec:
316+
persistentVolumeClaim:
317+
resources:
318+
requests:
319+
storage: 1Gi
320+
sharding:
321+
enabled: false
322+
"""
323+
When Service Binding is applied
324+
"""
325+
apiVersion: binding.operators.coreos.com/v1alpha1
326+
kind: ServiceBinding
327+
metadata:
328+
name: $scenario_id
329+
spec:
330+
services:
331+
- group: psmdb.percona.com
332+
version: v1-9-0
333+
kind: PerconaServerMongoDB
334+
name: minimal-cluster
335+
application:
336+
name: $scenario_id
337+
group: apps
338+
version: v1
339+
resource: deployments
340+
"""
341+
Then Service Binding is ready
342+
And Kind PerconaServerMongoDB with apiVersion psmdb.percona.com/v1-9-0 is listed in bindable kinds
343+
And Content of file "/bindings/$scenario_id/type" in application pod is
344+
"""
345+
mongodb
346+
"""
347+
And Content of file "/bindings/$scenario_id/username" in application pod is
348+
"""
349+
userAdmin
350+
"""
351+
And File "/bindings/$scenario_id/password" exists in application pod
352+
And Content of file "/bindings/$scenario_id/host" in application pod is
353+
"""
354+
minimal-cluster-rs0.$NAMESPACE.svc.cluster.local
355+
"""

0 commit comments

Comments
 (0)