diff --git a/pkg/binding/add_binding.go b/pkg/binding/add_binding.go index 2c2786db712..abd6827db28 100644 --- a/pkg/binding/add_binding.go +++ b/pkg/binding/add_binding.go @@ -81,36 +81,3 @@ func (o *BindingClient) AddBinding(bindingName string, bindAsFiles bool, unstruc return libdevfile.AddKubernetesComponentToDevfile(string(yamlDesc), serviceBinding.Name, obj) } - -func (o *BindingClient) GetServiceInstances() (map[string]unstructured.Unstructured, error) { - // Get the BindableKinds/bindable-kinds object - bindableKind, err := o.kubernetesClient.GetBindableKinds() - if err != nil { - return nil, err - } - - // get a list of restMappings of all the GVKs present in bindableKind's Status - bindableKindRestMappings, err := o.kubernetesClient.GetBindableKindStatusRestMapping(bindableKind.Status) - if err != nil { - return nil, err - } - - var bindableObjectMap = map[string]unstructured.Unstructured{} - for _, restMapping := range bindableKindRestMappings { - // TODO: Debug into why List returns all the versions instead of the GVR version - // List all the instances of the restMapping object - resources, err := o.kubernetesClient.ListDynamicResources(restMapping.Resource) - if err != nil { - return nil, err - } - - for _, item := range resources.Items { - // format: ` (.)` - serviceName := fmt.Sprintf("%s (%s.%s)", item.GetName(), item.GetKind(), item.GroupVersionKind().Group) - bindableObjectMap[serviceName] = item - } - - } - - return bindableObjectMap, nil -} diff --git a/pkg/binding/binding.go b/pkg/binding/binding.go index bbe974c5d4c..08652edc93f 100644 --- a/pkg/binding/binding.go +++ b/pkg/binding/binding.go @@ -56,6 +56,39 @@ func (o *BindingClient) GetFlags(flags map[string]string) map[string]string { return bindingFlags } +func (o *BindingClient) GetServiceInstances() (map[string]unstructured.Unstructured, error) { + // Get the BindableKinds/bindable-kinds object + bindableKind, err := o.kubernetesClient.GetBindableKinds() + if err != nil { + return nil, err + } + + // get a list of restMappings of all the GVKs present in bindableKind's Status + bindableKindRestMappings, err := o.kubernetesClient.GetBindableKindStatusRestMapping(bindableKind.Status) + if err != nil { + return nil, err + } + + var bindableObjectMap = map[string]unstructured.Unstructured{} + for _, restMapping := range bindableKindRestMappings { + // TODO: Debug into why List returns all the versions instead of the GVR version + // List all the instances of the restMapping object + resources, err := o.kubernetesClient.ListDynamicResources(restMapping.Resource) + if err != nil { + return nil, err + } + + for _, item := range resources.Items { + // format: ` (.)` + serviceName := fmt.Sprintf("%s (%s.%s)", item.GetName(), item.GetKind(), item.GroupVersionKind().Group) + bindableObjectMap[serviceName] = item + } + + } + + return bindableObjectMap, nil +} + // GetBindingsFromDevfile returns all ServiceBinding resources declared as Kubernertes component from a Devfile // from group binding.operators.coreos.com/v1alpha1 or servicebinding.io/v1alpha3 func (o *BindingClient) GetBindingsFromDevfile(devfileObj parser.DevfileObj, context string) ([]api.ServiceBinding, error) { diff --git a/pkg/binding/interface.go b/pkg/binding/interface.go index 070ce2a3571..c96463a11c8 100644 --- a/pkg/binding/interface.go +++ b/pkg/binding/interface.go @@ -10,6 +10,8 @@ import ( type Client interface { // GetFlags gets the necessary flags for binding GetFlags(flags map[string]string) map[string]string + // GetServiceInstances returns a map of bindable instance name with its unstructured.Unstructured object, and an error + GetServiceInstances() (map[string]unstructured.Unstructured, error) // GetBindingsFromDevfile returns the bindings defined in the devfile with the status extracted from cluster GetBindingsFromDevfile(devfileObj parser.DevfileObj, context string) ([]api.ServiceBinding, error) // GetBindingFromCluster returns information about a binding in the cluster (either from group binding.operators.coreos.com or servicebinding.io) @@ -27,8 +29,6 @@ type Client interface { AskBindAsFiles(flags map[string]string) (bool, error) // AddBinding adds the ServiceBinding manifest to the devfile AddBinding(bindingName string, bindAsFiles bool, unstructuredService unstructured.Unstructured, obj parser.DevfileObj, componentContext string) (parser.DevfileObj, error) - // GetServiceInstances returns a map of bindable instance name with its unstructured.Unstructured object, and an error - GetServiceInstances() (map[string]unstructured.Unstructured, error) // remove_binding.go diff --git a/pkg/binding/mock.go b/pkg/binding/mock.go index 84f8abde6ee..36e98a35e5a 100644 --- a/pkg/binding/mock.go +++ b/pkg/binding/mock.go @@ -35,68 +35,36 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { return m.recorder } -<<<<<<< HEAD -// AddBinding mocks base method. -func (m *MockClient) AddBinding(bindingName string, bindAsFiles bool, unstructuredService unstructured.Unstructured, obj parser.DevfileObj, componentContext string) (parser.DevfileObj, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AddBinding", bindingName, bindAsFiles, unstructuredService, obj, componentContext) - ret0, _ := ret[0].(parser.DevfileObj) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// AddBinding indicates an expected call of AddBinding. -func (mr *MockClientMockRecorder) AddBinding(bindingName, bindAsFiles, unstructuredService, obj, componentContext interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddBinding", reflect.TypeOf((*MockClient)(nil).AddBinding), bindingName, bindAsFiles, unstructuredService, obj, componentContext) -} - -// AskBindAsFiles mocks base method. -func (m *MockClient) AskBindAsFiles(flags map[string]string) (bool, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AskBindAsFiles", flags) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// AskBindAsFiles indicates an expected call of AskBindAsFiles. -func (mr *MockClientMockRecorder) AskBindAsFiles(flags interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AskBindAsFiles", reflect.TypeOf((*MockClient)(nil).AskBindAsFiles), flags) -} - -// AskBindingName mocks base method. -func (m *MockClient) AskBindingName(serviceName, componentName string, flags map[string]string) (string, error) { +// GetFlags mocks base method +func (m *MockClient) GetFlags(flags map[string]string) map[string]string { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AskBindingName", serviceName, componentName, flags) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret := m.ctrl.Call(m, "GetFlags", flags) + ret0, _ := ret[0].(map[string]string) + return ret0 } -// AskBindingName indicates an expected call of AskBindingName. -func (mr *MockClientMockRecorder) AskBindingName(serviceName, componentName, flags interface{}) *gomock.Call { +// GetFlags indicates an expected call of GetFlags +func (mr *MockClientMockRecorder) GetFlags(flags interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AskBindingName", reflect.TypeOf((*MockClient)(nil).AskBindingName), serviceName, componentName, flags) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFlags", reflect.TypeOf((*MockClient)(nil).GetFlags), flags) } -// GetBinding mocks base method. -func (m *MockClient) GetBinding(name string) (api.ServiceBinding, error) { +// GetServiceInstances mocks base method +func (m *MockClient) GetServiceInstances() (map[string]unstructured.Unstructured, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetBinding", name) - ret0, _ := ret[0].(api.ServiceBinding) + ret := m.ctrl.Call(m, "GetServiceInstances") + ret0, _ := ret[0].(map[string]unstructured.Unstructured) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetBinding indicates an expected call of GetBinding. -func (mr *MockClientMockRecorder) GetBinding(name interface{}) *gomock.Call { +// GetServiceInstances indicates an expected call of GetServiceInstances +func (mr *MockClientMockRecorder) GetServiceInstances() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBinding", reflect.TypeOf((*MockClient)(nil).GetBinding), name) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServiceInstances", reflect.TypeOf((*MockClient)(nil).GetServiceInstances)) } -// GetBindingsFromDevfile mocks base method. +// GetBindingsFromDevfile mocks base method func (m *MockClient) GetBindingsFromDevfile(devfileObj parser.DevfileObj, context string) ([]api.ServiceBinding, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetBindingsFromDevfile", devfileObj, context) @@ -105,41 +73,39 @@ func (m *MockClient) GetBindingsFromDevfile(devfileObj parser.DevfileObj, contex return ret0, ret1 } -// GetBindingsFromDevfile indicates an expected call of GetBindingsFromDevfile. +// GetBindingsFromDevfile indicates an expected call of GetBindingsFromDevfile func (mr *MockClientMockRecorder) GetBindingsFromDevfile(devfileObj, context interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBindingsFromDevfile", reflect.TypeOf((*MockClient)(nil).GetBindingsFromDevfile), devfileObj, context) } -// GetFlags mocks base method. -======= -// GetFlags mocks base method ->>>>>>> 3ca8c2463 (odo remove binding) -func (m *MockClient) GetFlags(flags map[string]string) map[string]string { +// GetBindingFromCluster mocks base method +func (m *MockClient) GetBindingFromCluster(name string) (api.ServiceBinding, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetFlags", flags) - ret0, _ := ret[0].(map[string]string) - return ret0 + ret := m.ctrl.Call(m, "GetBindingFromCluster", name) + ret0, _ := ret[0].(api.ServiceBinding) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// GetFlags indicates an expected call of GetFlags -func (mr *MockClientMockRecorder) GetFlags(flags interface{}) *gomock.Call { +// GetBindingFromCluster indicates an expected call of GetBindingFromCluster +func (mr *MockClientMockRecorder) GetBindingFromCluster(name interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFlags", reflect.TypeOf((*MockClient)(nil).GetFlags), flags) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBindingFromCluster", reflect.TypeOf((*MockClient)(nil).GetBindingFromCluster), name) } -// Validate mocks base method -func (m *MockClient) Validate(flags map[string]string) error { +// ValidateAddBinding mocks base method +func (m *MockClient) ValidateAddBinding(flags map[string]string) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Validate", flags) + ret := m.ctrl.Call(m, "ValidateAddBinding", flags) ret0, _ := ret[0].(error) return ret0 } -// Validate indicates an expected call of Validate -func (mr *MockClientMockRecorder) Validate(flags interface{}) *gomock.Call { +// ValidateAddBinding indicates an expected call of ValidateAddBinding +func (mr *MockClientMockRecorder) ValidateAddBinding(flags interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validate", reflect.TypeOf((*MockClient)(nil).Validate), flags) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateAddBinding", reflect.TypeOf((*MockClient)(nil).ValidateAddBinding), flags) } // SelectServiceInstance mocks base method @@ -202,21 +168,6 @@ func (mr *MockClientMockRecorder) AddBinding(bindingName, bindAsFiles, unstructu return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddBinding", reflect.TypeOf((*MockClient)(nil).AddBinding), bindingName, bindAsFiles, unstructuredService, obj, componentContext) } -// GetServiceInstances mocks base method -func (m *MockClient) GetServiceInstances() (map[string]unstructured.Unstructured, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetServiceInstances") - ret0, _ := ret[0].(map[string]unstructured.Unstructured) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetServiceInstances indicates an expected call of GetServiceInstances -func (mr *MockClientMockRecorder) GetServiceInstances() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServiceInstances", reflect.TypeOf((*MockClient)(nil).GetServiceInstances)) -} - // ValidateRemoveBinding mocks base method func (m *MockClient) ValidateRemoveBinding(flags map[string]string) error { m.ctrl.T.Helper()