Skip to content

Commit d2d4763

Browse files
authored
Merge pull request #39357 from ktania46/sbo
[MULTIARCH-1073, 1074]:SBO updates for OCP 4.9 from P and Z
2 parents e74370b + b1ddf51 commit d2d4763

7 files changed

+444
-0
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,8 @@ Topics:
15841584
File: installing-sbo
15851585
- Name: Getting started with service binding
15861586
File: getting-started-with-service-binding
1587+
- Name: Getting started with service binding on IBM Power Systems, IBM Z, and LinuxONE
1588+
File: getting-started-with-service-binding-ibm-power-ibm-z
15871589
- Name: Exposing binding data from a service
15881590
File: exposing-binding-data-from-a-service
15891591
- Name: Projecting binding data
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[id="getting-started-with-service-binding-ibm-power-ibm-z"]
2+
= Getting started with service binding on IBM Power Systems, IBM Z, and LinuxONE
3+
include::modules/common-attributes.adoc[]
4+
include::modules/servicebinding-document-attributes.adoc[]
5+
:context: getting-started-with-service-binding-ibm-power-ibm-z
6+
7+
toc::[]
8+
9+
The {servicebinding-title} manages the data plane for workloads and backing services. This guide provides instructions with examples to help you create a database instance, deploy an application, and use the {servicebinding-title} to create a binding connection between the application and the database service.
10+
11+
// Prerequisites for getting started with Service Binding Operator
12+
[discrete]
13+
== Prerequisites
14+
15+
* You have access to an {product-title} cluster using an account with `cluster-admin` permissions.
16+
* You have installed the `oc` CLI.
17+
* You have installed PostgreSQL `psql` CLI.
18+
* You have installed the {servicebinding-title} from OperatorHub.
19+
20+
//Deploying PostgreSQL operator
21+
include::modules/sbo-deploying-a-postgresql-database-operator-power-z.adoc[leveloffset=+1]
22+
23+
//Creating a PostgreSQL database instance
24+
include::modules/sbo-creating-a-postgresql-database-instance-power-z.adoc[leveloffset=+1]
25+
26+
//Deploying the Spring PetClinic sample application
27+
include::modules/sbo-deploying-the-spring-petclinic-sample-application-power-z.adoc[leveloffset=+1]
28+
29+
//Connecting the Spring PetClinic sample application to the PostgreSQL database service
30+
include::modules/sbo-connecting-spring-petclinic-sample-app-to-postgresql-database-service-power-z.adoc[leveloffset=+1]
31+
32+
[id="additional-resources_getting-started-with-service-binding-ibm-power-ibm-z"]
33+
34+
== Additional Resources
35+
* xref:../../applications/connecting_applications_to_services/installing-sbo.adoc#installing-sbo[Installing Service Binding Operator]
36+
* xref:../../applications/creating_applications/odc-creating-applications-using-developer-perspective.adoc#odc-creating-applications-using-developer-perspective[Creating applications using the Developer perspective]
37+
* xref:../../operators/understanding/crds/crd-managing-resources-from-crds.adoc[Managing resources from custom resource definitions]

images/img_power.png

52.8 KB
Loading
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
[id="sbo-connecting-spring-petclinic-sample-app-to-postgresql-database-service-ibm-power-z_{context}"]
2+
= Connecting the Spring PetClinic sample application to the PostgreSQL database service
3+
4+
To connect the sample application to the database service, you must create a `ServiceBinding` custom resource (CR) that triggers the {servicebinding-title} to project the binding data into the application.
5+
6+
[discrete]
7+
.Procedure
8+
9+
. Create a `ServiceBinding` CR to project the binding data:
10+
+
11+
[source,terminal]
12+
----
13+
$ oc apply -f - << EOD
14+
---
15+
apiVersion: binding.operators.coreos.com/v1alpha1
16+
kind: ServiceBinding
17+
metadata:
18+
name: spring-petclinic-rest
19+
namespace: my-postgresql
20+
spec:
21+
services: <1>
22+
- group: postgresql.dev4devs.com
23+
version: v1beta1
24+
kind: Database <2>
25+
name: sampledatabase
26+
version: v1alpha1
27+
application: <3>
28+
name: spring-petclinic-rest
29+
group: apps
30+
version: v1
31+
resource: deployments
32+
EOD
33+
----
34+
<1> Specifies a list of service resources.
35+
<2> The CR of the database.
36+
<3> The sample application that points to a Deployment or any other similar resource with an embedded PodSpec.
37+
+
38+
The output verifies that the `ServiceBinding` CR is created to project the binding data into the sample application.
39+
+
40+
.Example output
41+
[source,terminal]
42+
----
43+
servicebinding.binding.operators.coreos.com/spring-petclinic-rest created
44+
----
45+
46+
. To verify that the binding is successful, check the status conditions of the binding resource:
47+
+
48+
[source,terminal]
49+
----
50+
$ oc get servicebindings spring-petclinic-rest -n my-postgresql -o jsonpath-as-json='{.status.conditions}'
51+
----
52+
+
53+
.Example output
54+
[source,terminal]
55+
----
56+
[
57+
[
58+
{
59+
"lastTransitionTime": "2021-09-06T13:42:28Z",
60+
"message": "",
61+
"reason": "DataCollected",
62+
"status": "True",
63+
"type": "CollectionReady",
64+
},
65+
{
66+
"lastTransitionTime": "2021-09-06T13:42:28Z",
67+
"message": "",
68+
"reason": "ApplicationUpdated",
69+
"status": "True",
70+
"type": "InjectionReady",
71+
},
72+
{
73+
"lastTransitionTime": "2021-09-06T13:42:28Z",
74+
"message": "",
75+
"reason": "ApplicationsBound",
76+
"status": "True",
77+
"type": "Ready",
78+
},
79+
],
80+
]
81+
----
82+
+
83+
By default, the values from the binding data of the database service are projected as files into the workload container that runs the sample application.
84+
85+
. Once this is created, you can go to the topology to see the visual connection.
86+
+
87+
.Connecting spring-petclinic-rest to sampledatabase
88+
image::img_power.png[]
89+
90+
. Set up the port forwarding from the application port to access the sample application from your local environment:
91+
+
92+
[source,terminal]
93+
----
94+
$ oc port-forward --address 0.0.0.0 svc/spring-petclinic-rest 9966:80 -n my-postgresql
95+
----
96+
97+
. Access link:http://localhost:9966/petclinic[http://localhost:9966/petclinic].
98+
+
99+
You can now remotely access the Spring PetClinic sample application at localhost:9966.
100+
101+
. To verify that the application is now connected to the database service, access the list of all pets:
102+
+
103+
[source,terminal]
104+
----
105+
$ curl -X GET "http://localhost:9966/petclinic/api/pets" -H "accept: application/json"
106+
----
107+
+
108+
.Example output
109+
[source,terminal]
110+
----
111+
[{"id":1,"name":"Leo","birthDate":"2000/09/07","type":{"id":1,"name":"cat"},
112+
"owner":{"id":1,"firstName":"George","lastName":"Franklin","address":"110...
113+
----
114+
+
115+
The previous output shows the initially configured sample data and verifies that the application is now connected to the database service.
116+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[id="sbo-creating-a-postgresql-database-instance-power-z_{context}"]
2+
= Creating a PostgreSQL database instance
3+
4+
To create a PostgreSQL database instance, you must create a `Database` custom resource (CR) and configure the database.
5+
6+
.Procedure
7+
8+
. Create the `Database` CR and the `my-postgresql` namespace by running the following command in shell:
9+
+
10+
[source,terminal]
11+
----
12+
$ oc apply -f - << EOD
13+
apiVersion: postgresql.dev4devs.com/v1alpha1
14+
kind: Database
15+
metadata:
16+
name: sampledatabase
17+
namespace: my-postgresql
18+
annotations:
19+
host: sampledatabase
20+
type: postgresql
21+
port: "5432"
22+
service.binding/database: 'path={.spec.databaseName}'
23+
service.binding/port: 'path={.metadata.annotations.port}'
24+
service.binding/password: 'path={.spec.databasePassword}'
25+
service.binding/username: 'path={.spec.databaseUser}'
26+
service.binding/type: 'path={.metadata.annotations.type}'
27+
service.binding/host: 'path={.metadata.annotations.host}'
28+
spec:
29+
databaseCpu: 30m
30+
databaseCpuLimit: 60m
31+
databaseMemoryLimit: 512Mi
32+
databaseMemoryRequest: 128Mi
33+
databaseName: "sampledb"
34+
databaseNameKeyEnvVar: POSTGRESQL_DATABASE
35+
databasePassword: "samplepwd"
36+
databasePasswordKeyEnvVar: POSTGRESQL_PASSWORD
37+
databaseStorageRequest: 1Gi
38+
databaseUser: "sampleuser"
39+
databaseUserKeyEnvVar: POSTGRESQL_USER
40+
image: registry.redhat.io/rhel8/postgresql-96:latest
41+
databaseStorageClassName: nfs-storage-provisioner
42+
size: 1
43+
EOD
44+
----
45+
+
46+
The annotations added in this `Database` CR enable the service binding connection and trigger the Operator reconciliation.
47+
+
48+
The output verifies that the database instance is created:
49+
+
50+
.Example output
51+
[source,terminal]
52+
----
53+
database.postgresql.dev4devs.com/sampledatabase created
54+
----
55+
56+
. After you have created the database instance, ensure that all the pods in the `my-postgresql` namespace are running (it will take a few minutes):
57+
+
58+
[source,terminal]
59+
----
60+
$ oc get pods -n my-postgresql
61+
----
62+
+
63+
The output verifies that the database is created:
64+
+
65+
.Example output
66+
[source,terminal]
67+
----
68+
NAME READY STATUS RESTARTS AGE
69+
sampledatabase-cbc655488-74kss 0/1 Running 0 32s
70+
----
71+
+
72+
73+
The new database is empty at this stage. You can set its schema and project a sample data set to interact with the sample application.
74+
75+
. Initialize the database with the schema and sample data. To do so, use the following custom shell script by copying the code into the shell and running it:
76+
+
77+
[source,terminal]
78+
----
79+
$ cat << EOD | bash
80+
#!/bin/bash
81+
82+
export pgo_cluster_name=sampledb
83+
export cluster_namespace=my-postgresql
84+
export pgo_cluster_username=sampleuser
85+
nohup oc -n "\${cluster_namespace}" port-forward svc/sampledatabase 5432:5432 &
86+
sleep 5
87+
curl -LO https://raw.githubusercontent.com/spring-petclinic/spring-petclinic-rest/master/src/main/resources/db/postgresql/initDB.sql
88+
psql -h localhost -U "\${pgo_cluster_username}" "\${pgo_cluster_name}" -f initDB.sql
89+
curl -LO https://raw.githubusercontent.com/spring-petclinic/spring-petclinic-rest/master/src/main/resources/db/postgresql/populateDB.sql
90+
psql -h localhost -U "\${pgo_cluster_username}" "\${pgo_cluster_name}" -f populateDB.sql
91+
EOD
92+
----
93+
94+
The output in the terminal shows you that the database is being configured for the application.
95+
96+
After the database is configured, you can deploy the sample application and connect it to the database service.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[id="sbo-deploying-a-postgresql-operator-instance-power-z_{context}"]
2+
= Deploying a PostgreSQL Operator
3+
4+
* To deploy the Dev4Devs PostgreSQL Operator in the `my-postgresql` namespace run the following command in shell:
5+
6+
[source,terminal]
7+
----
8+
$ oc apply -f - << EOD
9+
---
10+
apiVersion: v1
11+
kind: Namespace
12+
metadata:
13+
name: my-postgresql
14+
---
15+
apiVersion: operators.coreos.com/v1
16+
kind: OperatorGroup
17+
metadata:
18+
name: postgres-operator-group
19+
namespace: my-postgresql
20+
---
21+
apiVersion: operators.coreos.com/v1alpha1
22+
kind: CatalogSource
23+
metadata:
24+
name: ibm-multiarch-catalog
25+
namespace: openshift-marketplace
26+
spec:
27+
sourceType: grpc
28+
image: quay.io/ibm/operator-registry-<architecture> <1>
29+
imagePullPolicy: IfNotPresent
30+
displayName: ibm-multiarch-catalog
31+
updateStrategy:
32+
registryPoll:
33+
interval: 30m
34+
---
35+
apiVersion: operators.coreos.com/v1alpha1
36+
kind: Subscription
37+
metadata:
38+
name: postgresql-operator-dev4devs-com
39+
namespace: openshift-operators
40+
spec:
41+
channel: alpha
42+
installPlanApproval: Automatic
43+
name: postgresql-operator-dev4devs-com
44+
source: ibm-multiarch-catalog
45+
sourceNamespace: openshift-marketplace
46+
---
47+
apiVersion: rbac.authorization.k8s.io/v1
48+
kind: ClusterRole
49+
metadata:
50+
name: database-view
51+
labels:
52+
servicebinding.io/controller: "true"
53+
rules:
54+
- apiGroups:
55+
- postgresql.dev4devs.com
56+
resources:
57+
- databases
58+
verbs:
59+
- get
60+
- list
61+
EOD
62+
----
63+
<1> The Operator image.
64+
* For IBM Power Systems: `quay.io/ibm/operator-registry-ppc64le:release-4.9`
65+
* For IBM Z and LinuxONE: `quay.io/ibm/operator-registry-s390x:release-4.8`
66+
67+
After the operator is installed, list the operator subscriptions in `openshift-operators` namespace:
68+
[source,terminal]
69+
----
70+
$ oc get subs -n openshift-operators
71+
----
72+
.Example output
73+
[source,terminal]
74+
----
75+
NAME PACKAGE SOURCE CHANNEL
76+
postgresql-operator-dev4devs-com postgresql-operator-dev4devs-com ibm-multiarch-catalog alpha
77+
rh-service-binding-operator rh-service-binding-operator redhat-operators stable
78+
----

0 commit comments

Comments
 (0)