Repository: redhat-developer/service-binding-operator
Pull request #103 (2019-08-08 06:30:39)

Adds secret name in service binding status
Partially solves: https://jira.coreos.com/browse/ODC-1327

This PR exposes the secret name in service binding status.

ToDo:
- [x] Update README

openshift-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **dhritishikhar**
You can assign the PR to them by writing `/assign @dhritishikhar` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=redhat-developer%2Fservice-binding-operator).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/redhat-developer/service-binding-operator/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["dhritishikhar"]} -->
baijum: Do we need this as it is always the name of CR.
codecov[bot]: # [Codecov](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@7ed2726`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `66.66%`.

[![Impacted file tree graph](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103/graphs/tree.svg?width=650&token=CICBeVWlrC&height=150&src=pr)](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=tree)

```diff
@@           Coverage Diff            @@
##             master    #103   +/-   ##
========================================
  Coverage          ?   59.1%           
========================================
  Files             ?       6           
  Lines             ?     401           
  Branches          ?       0           
========================================
  Hits              ?     237           
  Misses            ?     137           
  Partials          ?      27
```


| [Impacted Files](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/controller/servicebindingrequest/status.go](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103/diff?src=pr&el=tree#diff-cGtnL2NvbnRyb2xsZXIvc2VydmljZWJpbmRpbmdyZXF1ZXN0L3N0YXR1cy5nbw==) | `50% <100%> (ø)` | |
| [pkg/controller/servicebindingrequest/reconciler.go](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103/diff?src=pr&el=tree#diff-cGtnL2NvbnRyb2xsZXIvc2VydmljZWJpbmRpbmdyZXF1ZXN0L3JlY29uY2lsZXIuZ28=) | `44.76% <50%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=footer). Last update [7ed2726...8bd122f](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/103?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

sbose78: Yes
- to inform the user that we created a `secret`
- we might change the naming convention in future to accommodate conflicts.
baijum: /lgtm
/approve
openshift-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/redhat-developer/service-binding-operator/pull/103#issuecomment-519781326" title="Approved">baijum</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=redhat-developer%2Fservice-binding-operator).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/redhat-developer/service-binding-operator/blob/master/OWNERS)~~ [baijum]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/README.md b/README.md
index b1d0df28..8e610024 100644
--- a/README.md
+++ b/README.md
@@ -276,6 +276,7 @@ spec:
 
 | Field | Description |
 |-------|-------------|
-| Status | the binding status of Service Binding Request |
+| BindingStatus | The binding status of Service Binding Request |
+| Secret | The name of the intermediate secret |
 
 That's it, folks!
diff --git a/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go b/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
index 1793b315..278bed84 100644
--- a/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
+++ b/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
@@ -84,6 +84,8 @@ const (
 type ServiceBindingRequestStatus struct {
 	// BindingStatus is the status of the service binding request. Possible values are Success, Failure, InProgress.
 	BindingStatus BindingStatus `json:"BindingStatus"`
+	// Secret is the name of the intermediate secret
+	Secret string `json:"Secret"`
 }
 
 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
diff --git a/pkg/controller/servicebindingrequest/reconciler.go b/pkg/controller/servicebindingrequest/reconciler.go
index 896ee0d4..dc787da9 100644
--- a/pkg/controller/servicebindingrequest/reconciler.go
+++ b/pkg/controller/servicebindingrequest/reconciler.go
@@ -116,6 +116,13 @@ func (r *Reconciler) Reconcile(request reconcile.Request) (reconcile.Result, err
 	logger.WithValues("ServiceBindingRequest.Name", instance.Name).
 		Info("Found service binding request to inspect")
 
+	// Set secret name
+	r.setSecretStatus(instance)
+	err = r.client.Status().Update(context.TODO(), instance)
+	if err != nil {
+		return reconcile.Result{}, err
+	}
+
 	plnr := planner.NewPlanner(ctx, r.client, request.Namespace, instance)
 	plan, err := plnr.Plan()
 	if err != nil {
diff --git a/pkg/controller/servicebindingrequest/status.go b/pkg/controller/servicebindingrequest/status.go
index 4744b8d3..aca06b3b 100644
--- a/pkg/controller/servicebindingrequest/status.go
+++ b/pkg/controller/servicebindingrequest/status.go
@@ -15,3 +15,7 @@ func (r *Reconciler) setBindingInProgressStatus(sbr *v1alpha1.ServiceBindingRequ
 func (r *Reconciler) setBindingFailStatus(sbr *v1alpha1.ServiceBindingRequest) {
 	sbr.Status.BindingStatus = v1alpha1.BindingFail
 }
+
+func (r *Reconciler) setSecretStatus(sbr *v1alpha1.ServiceBindingRequest) {
+	sbr.Status.Secret = sbr.GetName()
+}


Test patch:
diff --git a/pkg/controller/servicebindingrequest/reconciler_test.go b/pkg/controller/servicebindingrequest/reconciler_test.go
index 47a99283..212e80eb 100644
--- a/pkg/controller/servicebindingrequest/reconciler_test.go
+++ b/pkg/controller/servicebindingrequest/reconciler_test.go
@@ -87,6 +87,7 @@ func TestReconcilerNew(t *testing.T) {
 		sbrOutput := v1alpha1.ServiceBindingRequest{}
 		require.Nil(t, reconcilerFakeClient.Get(context.TODO(), namespacedName, &sbrOutput))
 		require.Equal(t, v1alpha1.BindingSuccess, sbrOutput.Status.BindingStatus)
+		require.Equal(t, reconcilerName, sbrOutput.Status.Secret)
 	})
 
 }