Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include::modules/servicebinding-document-attributes.adoc[]

toc::[]

[role="_abstract"]
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.

// Prerequisites for getting started with Service Binding Operator
Expand All @@ -15,7 +16,6 @@ The {servicebinding-title} manages the data plane for workloads and backing serv

* You have access to an {product-title} cluster using an account with `cluster-admin` permissions.
* You have installed the `oc` CLI.
* You have installed PostgreSQL `psql` CLI.
* You have installed the {servicebinding-title} from OperatorHub.

//Deploying PostgreSQL operator
Expand All @@ -30,9 +30,8 @@ include::modules/sbo-deploying-the-spring-petclinic-sample-application-power-z.a
//Connecting the Spring PetClinic sample application to the PostgreSQL database service
include::modules/sbo-connecting-spring-petclinic-sample-app-to-postgresql-database-service-power-z.adoc[leveloffset=+1]

[id="additional-resources_getting-started-with-service-binding-ibm-power-ibm-z"]

[role="_additional-resources"]
[id="additional-resources_getting-started-with-service-binding-ibm-power-ibm-z"]
== Additional resources
* xref:../../applications/connecting_applications_to_services/installing-sbo.adoc#installing-sbo[Installing Service Binding Operator]
* xref:../../applications/creating_applications/odc-creating-applications-using-developer-perspective.adoc#odc-creating-applications-using-developer-perspective[Creating applications using the Developer perspective]
Expand Down
Binary file modified images/img_power.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[id="sbo-connecting-spring-petclinic-sample-app-to-postgresql-database-service-ibm-power-z_{context}"]
= Connecting the Spring PetClinic sample application to the PostgreSQL database service

[role="_abstract"]
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.

[discrete]
Expand All @@ -11,25 +12,23 @@ To connect the sample application to the database service, you must create a `Se
+
[source,terminal]
----
$ oc apply -f - << EOD
$ oc apply -n my-petclinic -f - << EOD
---
apiVersion: binding.operators.coreos.com/v1alpha1
kind: ServiceBinding
metadata:
name: spring-petclinic-rest
namespace: my-postgresql
name: spring-petclinic-pgcluster
spec:
services: <1>
services: <1>
- group: postgresql.dev4devs.com
version: v1beta1
kind: Database <2>
name: sampledatabase
version: v1alpha1
application: <3>
name: spring-petclinic-rest
group: apps
version: v1
resource: deployments
application: <3>
name: spring-petclinic
group: apps
version: v1
resource: deployments
EOD
----
<1> Specifies a list of service resources.
Expand All @@ -41,77 +40,45 @@ The output verifies that the `ServiceBinding` CR is created to project the bindi
.Example output
[source,terminal]
----
servicebinding.binding.operators.coreos.com/spring-petclinic-rest created
servicebinding.binding.operators.coreos.com/spring-petclinic created
----

. To verify that the binding is successful, check the status conditions of the binding resource:
. Verify that the request for service binding is successful:
+
[source,terminal]
----
$ oc get servicebindings spring-petclinic-rest -n my-postgresql -o jsonpath-as-json='{.status.conditions}'
$ oc get servicebindings -n my-petclinic
----
+
.Example output
[source,terminal]
----
[
[
{
"lastTransitionTime": "2021-09-06T13:42:28Z",
"message": "",
"reason": "DataCollected",
"status": "True",
"type": "CollectionReady",
},
{
"lastTransitionTime": "2021-09-06T13:42:28Z",
"message": "",
"reason": "ApplicationUpdated",
"status": "True",
"type": "InjectionReady",
},
{
"lastTransitionTime": "2021-09-06T13:42:28Z",
"message": "",
"reason": "ApplicationsBound",
"status": "True",
"type": "Ready",
},
],
]
NAME READY REASON AGE
spring-petclinic-postgresql True ApplicationsBound 47m
----
+
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.
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. For example, all the values from the Secret resource are projected into the `bindings/spring-petclinic-pgcluster` directory.

. Once this is created, you can go to the topology to see the visual connection.
+
.Connecting spring-petclinic-rest to sampledatabase
.Connecting spring-petclinic to a sample database
image::img_power.png[]

. Set up the port forwarding from the application port to access the sample application from your local environment:
+
[source,terminal]
----
$ oc port-forward --address 0.0.0.0 svc/spring-petclinic-rest 9966:80 -n my-postgresql
----

. Access link:http://localhost:9966/petclinic[http://localhost:9966/petclinic].
+
You can now remotely access the Spring PetClinic sample application at localhost:9966.

. To verify that the application is now connected to the database service, access the list of all pets:
+
[source,terminal]
----
$ curl -X GET "http://localhost:9966/petclinic/api/pets" -H "accept: application/json"
$ oc port-forward --address 0.0.0.0 svc/spring-petclinic 8080:80 -n my-petclinic
----
+
.Example output
[source,terminal]
----
[{"id":1,"name":"Leo","birthDate":"2000/09/07","type":{"id":1,"name":"cat"},
"owner":{"id":1,"firstName":"George","lastName":"Franklin","address":"110...
Forwarding from 0.0.0.0:8080 -> 8080
Handling connection for 8080
----

. Access link:http://localhost:8080[http://localhost:8080].
+
The previous output shows the initially configured sample data and verifies that the application is now connected to the database service.
You can now remotely access the Spring PetClinic sample application at localhost:8080 and see that the application is now connected to the database service.

37 changes: 7 additions & 30 deletions modules/sbo-creating-a-postgresql-database-instance-power-z.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
[id="sbo-creating-a-postgresql-database-instance-power-z_{context}"]
= Creating a PostgreSQL database instance

[role="_abstract"]
To create a PostgreSQL database instance, you must create a `Database` custom resource (CR) and configure the database.

.Procedure

. Create the `Database` CR and the `my-postgresql` namespace by running the following command in shell:
. Create the `Database` CR in the `my-petclinic` namespace by running the following command in shell:
+
[source,terminal]
----
Expand All @@ -15,7 +16,7 @@ apiVersion: postgresql.dev4devs.com/v1alpha1
kind: Database
metadata:
name: sampledatabase
namespace: my-postgresql
namespace: my-petclinic
annotations:
host: sampledatabase
type: postgresql
Expand All @@ -38,7 +39,7 @@ spec:
databaseStorageRequest: 1Gi
databaseUser: "sampleuser"
databaseUserKeyEnvVar: POSTGRESQL_USER
image: registry.redhat.io/rhel8/postgresql-96:latest
image: registry.redhat.io/rhel8/postgresql-13:latest
databaseStorageClassName: nfs-storage-provisioner
size: 1
EOD
Expand All @@ -54,44 +55,20 @@ The output verifies that the database instance is created:
database.postgresql.dev4devs.com/sampledatabase created
----

. 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):
. After you have created the database instance, ensure that all the pods in the `my-petclinic` namespace are running:
+
[source,terminal]
----
$ oc get pods -n my-postgresql
$ oc get pods -n my-petclinic
----
+
The output verifies that the database is created:
The output, which takes a few minutes to display, verifies that the database is created and configured:
+
.Example output
[source,terminal]
----
NAME READY STATUS RESTARTS AGE
sampledatabase-cbc655488-74kss 0/1 Running 0 32s
----
+

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.

. 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:
+
[source,terminal]
----
$ cat << EOD | bash
#!/bin/bash

export pgo_cluster_name=sampledb
export cluster_namespace=my-postgresql
export pgo_cluster_username=sampleuser
nohup oc -n "\${cluster_namespace}" port-forward svc/sampledatabase 5432:5432 &
sleep 5
curl -LO https://raw.githubusercontent.com/spring-petclinic/spring-petclinic-rest/master/src/main/resources/db/postgresql/initDB.sql
psql -h localhost -U "\${pgo_cluster_username}" "\${pgo_cluster_name}" -f initDB.sql
curl -LO https://raw.githubusercontent.com/spring-petclinic/spring-petclinic-rest/master/src/main/resources/db/postgresql/populateDB.sql
psql -h localhost -U "\${pgo_cluster_username}" "\${pgo_cluster_name}" -f populateDB.sql
EOD
----

The output in the terminal shows you that the database is being configured for the application.
Comment on lines -72 to -95

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this to populate the DB with the sample data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the new app, there is no need for populating the DB with the sample data, the application should initialize the DB o its own.


After the database is configured, you can deploy the sample application and connect it to the database service.
15 changes: 11 additions & 4 deletions modules/sbo-deploying-a-postgresql-database-operator-power-z.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
:_content-type: PROCEDURE
[id="sbo-deploying-a-postgresql-operator-instance-power-z_{context}"]
= Deploying a PostgreSQL Operator

* To deploy the Dev4Devs PostgreSQL Operator in the `my-postgresql` namespace run the following command in shell:
.Procedure

. To deploy the Dev4Devs PostgreSQL Operator in the `my-petclinic` namespace run the following command in shell:

[source,terminal]
----
Expand All @@ -10,13 +13,13 @@ $ oc apply -f - << EOD
apiVersion: v1
kind: Namespace
metadata:
name: my-postgresql
name: my-petclinic
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: postgres-operator-group
namespace: my-postgresql
namespace: my-petclinic
---
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
Expand Down Expand Up @@ -64,11 +67,15 @@ EOD
* For IBM Power: `quay.io/ibm/operator-registry-ppc64le:release-4.9`
* For IBM Z and LinuxONE: `quay.io/ibm/operator-registry-s390x:release-4.8`

After the operator is installed, list the operator subscriptions in `openshift-operators` namespace:
.Verification

. After the operator is installed, list the operator subscriptions in the `openshift-operators` namespace:
+
[source,terminal]
----
$ oc get subs -n openshift-operators
----
+
.Example output
[source,terminal]
----
Expand Down
Loading