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

Support creation of managed secret without associating it to a workload #350

Merged
2 changes: 0 additions & 2 deletions deploy/crds/apps.openshift.io_servicebindingrequests_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ spec:
mountPathPrefix:
description: MountPathPrefix is the prefix for volume mount
type: string
required:
- applicationSelector
type: object
status:
description: ServiceBindingRequestStatus defines the observed state of ServiceBindingRequest
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/apps/v1alpha1/servicebindingrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ServiceBindingRequestSpec struct {

// ApplicationSelector is used to identify the application connecting to the
// backing service operator.
// +optional
ApplicationSelector ApplicationSelector `json:"applicationSelector"`

// DetectBindingResources is flag used to bind all non-bindable variables from
Expand Down
29 changes: 14 additions & 15 deletions pkg/apis/apps/v1alpha1/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
return map[string]common.OpenAPIDefinition{
"./pkg/apis/apps/v1alpha1.ApplicationSelector": schema_pkg_apis_apps_v1alpha1_ApplicationSelector(ref),
"./pkg/apis/apps/v1alpha1.BackingServiceSelector": schema_pkg_apis_apps_v1alpha1_BackingServiceSelector(ref),
"./pkg/apis/apps/v1alpha1.ServiceBindingRequest": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequest(ref),
"./pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref),
"./pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestStatus(ref),
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ApplicationSelector": schema_pkg_apis_apps_v1alpha1_ApplicationSelector(ref),
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BackingServiceSelector": schema_pkg_apis_apps_v1alpha1_BackingServiceSelector(ref),
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequest": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequest(ref),
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref),
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus": schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestStatus(ref),
Comment on lines -14 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the first time I've seen this; why generated files are being generated differently between developers?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe because of operator-sdk versions? I'm using 0.5.2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mine is different:

➜  service-binding-operator git:(generic) ✗ operator-sdk version                                                         
operator-sdk version: "v0.15.0-37-g0eac8a11", commit: "0eac8a1169dfc0a8918b9e41ada6278307a0852b", go version: "go1.13.6 linux/amd64"

Copy link
Member

@sbose78 sbose78 Mar 7, 2020

Choose a reason for hiding this comment

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

You definitely got to update your operator-sdk CLI
:-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I am on 0.15.2 and even for me these changes are happening

}
}

Expand Down Expand Up @@ -136,19 +136,19 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequest(ref common.ReferenceCal
},
"spec": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec"),
},
},
"status": {
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus"),
},
},
},
},
},
Dependencies: []string{
"./pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec", "./pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestSpec", "github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ServiceBindingRequestStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref common.Referenc
"backingServiceSelector": {
SchemaProps: spec.SchemaProps{
Description: "BackingServiceSelector is used to identify the backing service operator. Deprecation Notice: In the upcoming release, this field would be depcreated. It would be mandatory to set \"backingServiceSelectors\".",
Ref: ref("./pkg/apis/apps/v1alpha1.BackingServiceSelector"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BackingServiceSelector"),
},
},
"backingServiceSelectors": {
Expand All @@ -199,7 +199,7 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref common.Referenc
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/apps/v1alpha1.BackingServiceSelector"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BackingServiceSelector"),
},
},
},
Expand All @@ -208,7 +208,7 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref common.Referenc
"applicationSelector": {
SchemaProps: spec.SchemaProps{
Description: "ApplicationSelector is used to identify the application connecting to the backing service operator.",
Ref: ref("./pkg/apis/apps/v1alpha1.ApplicationSelector"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ApplicationSelector"),
},
},
"detectBindingResources": {
Expand All @@ -219,11 +219,10 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestSpec(ref common.Referenc
},
},
},
Required: []string{"applicationSelector"},
},
},
Dependencies: []string{
"./pkg/apis/apps/v1alpha1.ApplicationSelector", "./pkg/apis/apps/v1alpha1.BackingServiceSelector", "k8s.io/api/core/v1.EnvVar"},
"github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.ApplicationSelector", "github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BackingServiceSelector", "k8s.io/api/core/v1.EnvVar"},
}
}

Expand Down Expand Up @@ -268,7 +267,7 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestStatus(ref common.Refere
Items: &spec.SchemaOrArray{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Ref: ref("./pkg/apis/apps/v1alpha1.BoundApplication"),
Ref: ref("github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BoundApplication"),
},
},
},
Expand All @@ -278,6 +277,6 @@ func schema_pkg_apis_apps_v1alpha1_ServiceBindingRequestStatus(ref common.Refere
},
},
Dependencies: []string{
"./pkg/apis/apps/v1alpha1.BoundApplication", "github.com/openshift/custom-resource-status/conditions/v1.Condition"},
"github.com/openshift/custom-resource-status/conditions/v1.Condition", "github.com/redhat-developer/service-binding-operator/pkg/apis/apps/v1alpha1.BoundApplication"},
}
}
75 changes: 75 additions & 0 deletions pkg/controller/servicebindingrequest/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,78 @@ func TestReconcilerReconcileUsingVolumes(t *testing.T) {
require.Equal(t, reconcilerName, volumes[0].VolumeSource.Secret.SecretName)
})
}

func TestReconcilerGenericBinding(t *testing.T) {
ctx := context.TODO()
backingServiceResourceRef := "backingService1"
matchLabels := map[string]string{
"connects-to": "database",
"environment": "reconciler",
}
f := mocks.NewFake(t, reconcilerNs)
f.AddMockedUnstructuredServiceBindingRequest(reconcilerName, backingServiceResourceRef, "", deploymentsGVR, matchLabels)
f.AddMockedUnstructuredCSV("cluster-service-version-list")
f.AddMockedUnstructuredDatabaseCRD()
f.AddMockedUnstructuredDatabaseCR(backingServiceResourceRef)
f.AddMockedSecret("db-credentials")

fakeClient := f.FakeClient()
reconciler := &Reconciler{client: fakeClient, dynClient: f.FakeDynClient(), scheme: f.S}

// Reconcile without deployment
res, err := reconciler.Reconcile(reconcileRequest())
require.NoError(t, err)
require.True(t, res.Requeue)

namespacedName := types.NamespacedName{Namespace: reconcilerNs, Name: reconcilerName}
sbrOutput, err := reconciler.getServiceBindingRequest(namespacedName)
require.NoError(t, err)

require.Equal(t, "BindingFail", sbrOutput.Status.BindingStatus)
require.Equal(t, corev1.ConditionFalse, sbrOutput.Status.Conditions[0].Status)
require.Equal(t, 0, len(sbrOutput.Status.ApplicationObjects))

// Reconcile with deployment
f.AddMockedUnstructuredDeployment(reconcilerName, matchLabels)

fakeClient = f.FakeClient()
reconciler = &Reconciler{client: fakeClient, dynClient: f.FakeDynClient(), scheme: f.S}
res, err = reconciler.Reconcile(reconcileRequest())
require.NoError(t, err)
require.False(t, res.Requeue)

d := appsv1.Deployment{}
require.NoError(t, fakeClient.Get(ctx, namespacedName, &d))

sbrOutput2, err := reconciler.getServiceBindingRequest(namespacedName)
require.NoError(t, err)

require.Equal(t, "BindingSuccess", sbrOutput2.Status.BindingStatus)
require.Equal(t, reconcilerName, sbrOutput2.Status.Secret)
require.Equal(t, corev1.ConditionTrue, sbrOutput2.Status.Conditions[0].Status)
require.Equal(t, 1, len(sbrOutput2.Status.ApplicationObjects))

// Update Credentials
s := corev1.Secret{}
secretNamespaced := types.NamespacedName{Namespace: reconcilerNs, Name: "db-credentials"}
require.NoError(t, fakeClient.Get(ctx, secretNamespaced, &s))
s.Data["password"] = []byte("abc123")
require.NoError(t, fakeClient.Update(ctx, &s))

reconciler = &Reconciler{client: fakeClient, dynClient: f.FakeDynClient(), scheme: f.S}
res, err = reconciler.Reconcile(reconcileRequest())
require.NoError(t, err)
require.False(t, res.Requeue)

sbrOutput3, err := reconciler.getServiceBindingRequest(namespacedName)
require.NoError(t, err)

d = appsv1.Deployment{}
require.NoError(t, fakeClient.Get(ctx, namespacedName, &d))

require.Equal(t, "BindingSuccess", sbrOutput3.Status.BindingStatus)
require.Equal(t, corev1.ConditionTrue, sbrOutput3.Status.Conditions[0].Status)
require.Equal(t, reconcilerName, sbrOutput3.Status.Secret)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have sbrOutput3.Status.BindingData.Name . Now that the bindingData can be either in a Secret or a ConfigMap according to #366 . Refer https://github.com/redhat-developer/service-binding-operator/pull/366/files#diff-14a37dadc390fc3ec23459efc088de8eR164-R180 cc @sbose78

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but #366 is not merged yet

Copy link
Contributor

Choose a reason for hiding this comment

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

we can track this and send a new PR :)

require.Equal(t, s.Data["password"], []byte("abc123"))
require.Equal(t, 1, len(sbrOutput3.Status.ApplicationObjects))
}