Repository: redhat-developer/service-binding-operator
Pull request #302 (2020-01-23 03:53:19)

Use GroupVersionKind in BackingServiceSelector
Fixes https://issues.redhat.com/browse/APPSVC-378


### Motivation

Be consistent with Kubernetes APIs

### Changes

GroupVersionKind

### Testing

Existing tests have been modified.



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 **baijum**
You can assign the PR to them by writing `/assign @baijum` 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":["baijum"]} -->
Avni-Sharma: /lgtm
codecov[bot]: # [Codecov](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/302?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@7180de9`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff            @@
##             master     #302   +/-   ##
=========================================
  Coverage          ?   59.81%           
=========================================
  Files             ?       17           
  Lines             ?     1294           
  Branches          ?        0           
=========================================
  Hits              ?      774           
  Misses            ?      388           
  Partials          ?      132
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/302?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/302?src=pr&el=footer). Last update [7180de9...4363fb7](https://codecov.io/gh/redhat-developer/service-binding-operator/pull/302?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Avni-Sharma: /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/302#issuecomment-577510228" title="Approved">Avni-Sharma</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)~~ [Avni-Sharma]

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/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go b/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
index 1edc387c..2ecac642 100644
--- a/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
+++ b/pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
@@ -53,10 +53,8 @@ type ServiceBindingRequestStatus struct {
 // BackingServiceSelector defines the selector based on resource name, version, and resource kind
 // +k8s:openapi-gen=true
 type BackingServiceSelector struct {
-	Group       string `json:"group"`
-	Version     string `json:"version"`
-	Kind        string `json:"kind"`
-	ResourceRef string `json:"resourceRef"`
+	metav1.GroupVersionKind `json:",inline"`
+	ResourceRef             string `json:"resourceRef"`
 }
 
 // ApplicationSelector defines the selector based on labels and GVR
diff --git a/pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go
index c6f68995..5b64c5b7 100644
--- a/pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/apps/v1alpha1/zz_generated.deepcopy.go
@@ -35,6 +35,7 @@ func (in *ApplicationSelector) DeepCopy() *ApplicationSelector {
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *BackingServiceSelector) DeepCopyInto(out *BackingServiceSelector) {
 	*out = *in
+	out.GroupVersionKind = in.GroupVersionKind
 	return
 }
 


Test patch:
diff --git a/pkg/controller/servicebindingrequest/sbrcontroller_test.go b/pkg/controller/servicebindingrequest/sbrcontroller_test.go
index 99ec7b6c..9b43e365 100644
--- a/pkg/controller/servicebindingrequest/sbrcontroller_test.go
+++ b/pkg/controller/servicebindingrequest/sbrcontroller_test.go
@@ -29,20 +29,16 @@ func TestSBRControllerBuildSBRPredicate(t *testing.T) {
 		sbrA := &v1alpha1.ServiceBindingRequest{
 			Spec: v1alpha1.ServiceBindingRequestSpec{
 				BackingServiceSelector: v1alpha1.BackingServiceSelector{
-					Group:       "test",
-					Version:     "v1alpha1",
-					Kind:        "TestHost",
-					ResourceRef: "",
+					GroupVersionKind: metav1.GroupVersionKind{Group: "test", Version: "v1alpha1", Kind: "TestHost"},
+					ResourceRef:      "",
 				},
 			},
 		}
 		sbrB := &v1alpha1.ServiceBindingRequest{
 			Spec: v1alpha1.ServiceBindingRequestSpec{
 				BackingServiceSelector: v1alpha1.BackingServiceSelector{
-					Group:       "test",
-					Version:     "v1",
-					Kind:        "TestHost",
-					ResourceRef: "",
+					GroupVersionKind: metav1.GroupVersionKind{Group: "test", Version: "v1", Kind: "TestHost"},
+					ResourceRef:      "",
 				},
 			},
 		}
diff --git a/test/e2e/servicebindingrequest_test.go b/test/e2e/servicebindingrequest_test.go
index 4068f9e2..eeeec12b 100644
--- a/test/e2e/servicebindingrequest_test.go
+++ b/test/e2e/servicebindingrequest_test.go
@@ -4,13 +4,14 @@ import (
 	"bytes"
 	"context"
 	"fmt"
-	"github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/apimachinery/pkg/runtime/schema"
 	"math/rand"
 	"testing"
 	"time"
 
+	"github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/runtime/schema"
+
 	pgsqlapis "github.com/operator-backing-service-samples/postgresql-operator/pkg/apis"
 	pgv1alpha1 "github.com/operator-backing-service-samples/postgresql-operator/pkg/apis/postgresql/v1alpha1"
 	olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
@@ -377,10 +378,8 @@ func CreateSBR(
 // setSBRBackendGVK sets backend service selector
 func setSBRBackendGVK(sbr *v1alpha1.ServiceBindingRequest, resourceRef string, backendGVK schema.GroupVersionKind) {
 	sbr.Spec.BackingServiceSelector = v1alpha1.BackingServiceSelector{
-		Group:       backendGVK.Group,
-		Version:     backendGVK.Version,
-		Kind:        backendGVK.Kind,
-		ResourceRef: resourceRef,
+		GroupVersionKind: metav1.GroupVersionKind{Group: backendGVK.Group, Version: backendGVK.Version, Kind: backendGVK.Kind},
+		ResourceRef:      resourceRef,
 	}
 }
 
diff --git a/test/mocks/mocks.go b/test/mocks/mocks.go
index 3201bbff..324a203d 100644
--- a/test/mocks/mocks.go
+++ b/test/mocks/mocks.go
@@ -405,10 +405,8 @@ func ServiceBindingRequestMock(
 		},
 	}
 	sbr.Spec.BackingServiceSelector = v1alpha1.BackingServiceSelector{
-		Group:       CRDName,
-		Version:     CRDVersion,
-		Kind:        CRDKind,
-		ResourceRef: backingServiceResourceRef,
+		GroupVersionKind: metav1.GroupVersionKind{Group: CRDName, Version: CRDVersion, Kind: CRDKind},
+		ResourceRef:      backingServiceResourceRef,
 	}
 	return sbr
 }