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

Commit

Permalink
refactor: 🎨 rename methods and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Sutton Lopes committed Apr 18, 2020
1 parent 5ab5f39 commit 2f27151
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/servicebindingrequest/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func BuildServiceBinder(options *ServiceBinderOptions) (*ServiceBinder, error) {
Binder: NewBinder(ctx, options.Client, options.DynClient, options.SBR, retriever.VolumeKeys),
DynClient: options.DynClient,
SBR: options.SBR,
Objects: serviceCtxs.GetCRs(),
Objects: serviceCtxs.GetObjects(),
Data: envVars,
Secret: secret,
}, nil
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/servicebindingrequest/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,14 @@ func buildServiceContexts(
s.Namespace = &ns
}

gvk := schema.GroupVersionKind{Kind: s.Kind, Version: s.Version, Group: s.Group}

cr, err := findCR(client, s)
obj, err := findCR(client, s)
if err != nil {
return nil, err
}

// attempt to search the CRD of given gvk and bail out right away if a CRD can't be found; this
// means also a CRDDescription can't exist or if it does exist it is not meaningful.
gvk := schema.GroupVersionKind{Kind: s.Kind, Version: s.Version, Group: s.Group}
crd, err := findCRD(client, gvk)
if err != nil {
return nil, err
Expand All @@ -173,7 +172,7 @@ func buildServiceContexts(
}

// and finally override collected annotations with CR annotations
err = mergo.Merge(&anns, cr.GetAnnotations(), mergo.WithOverride)
err = mergo.Merge(&anns, obj.GetAnnotations(), mergo.WithOverride)
if err != nil {
return nil, err
}
Expand All @@ -185,7 +184,7 @@ func buildServiceContexts(
h, err := annotations.BuildHandler(annotations.HandlerArgs{
Name: n,
Value: v,
Resource: cr,
Resource: obj,
Client: client,
})
if err != nil {
Expand All @@ -209,7 +208,7 @@ func buildServiceContexts(

serviceCtx := &ServiceContext{
CRDDescription: crdDescription,
CR: cr,
Object: obj,
EnvVars: envVars,
VolumeKeys: volumeKeys,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/servicebindingrequest/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func TestPlannerWithExplicitBackingServiceNamespace(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, plan)
require.NotEmpty(t, plan.ServiceContexts)
require.NotEmpty(t, plan.ServiceContexts.GetCRs())
require.Equal(t, backingServiceNamespace, plan.ServiceContexts.GetCRs()[0].GetNamespace())
require.NotEmpty(t, plan.ServiceContexts.GetObjects())
require.Equal(t, backingServiceNamespace, plan.ServiceContexts.GetObjects()[0].GetNamespace())
require.Equal(t, ns, plan.Ns)
require.Equal(t, name, plan.Name)

Expand Down
14 changes: 7 additions & 7 deletions pkg/controller/servicebindingrequest/servicecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ type ServiceContext struct {
// CRDDescription is the description of the resources CRD, either built from a manifest from the
// cluster or composed through annotations in the CRD.
CRDDescription *v1alpha1.CRDDescription
// CR is the resource being used as reference.
CR *unstructured.Unstructured
// EnvVars is the composition of all collected data for the reference CR.
// Object is the resource being used as reference.
Object *unstructured.Unstructured
// EnvVars contains the service's contributed environment variables.
EnvVars map[string]interface{}
// VolumeKeys contains the keys that should be mounted as volume from the binding secret.
VolumeKeys []string
Expand All @@ -21,11 +21,11 @@ type ServiceContext struct {
// ServiceContexts contains a collection of service contexts.
type ServiceContexts []*ServiceContext

// GetCRs returns a slice of unstructured CRs contained in the collection.
func (rr ServiceContexts) GetCRs() []*unstructured.Unstructured {
// GetObjects returns a slice of service unstructured objects contained in the collection.
func (sc ServiceContexts) GetObjects() []*unstructured.Unstructured {
var crs []*unstructured.Unstructured
for _, r := range rr {
crs = append(crs, r.CR)
for _, s := range sc {
crs = append(crs, s.Object)
}
return crs
}

0 comments on commit 2f27151

Please sign in to comment.