Skip to content

Commit

Permalink
Rebase alterations
Browse files Browse the repository at this point in the history
  • Loading branch information
valaparthvi committed Jun 6, 2022
1 parent 471f826 commit 3b5ab3e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 116 deletions.
33 changes: 0 additions & 33 deletions pkg/binding/add_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<name> (<kind>.<group>)`
serviceName := fmt.Sprintf("%s (%s.%s)", item.GetName(), item.GetKind(), item.GroupVersionKind().Group)
bindableObjectMap[serviceName] = item
}

}

return bindableObjectMap, nil
}
33 changes: 33 additions & 0 deletions pkg/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<name> (<kind>.<group>)`
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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/binding/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
113 changes: 32 additions & 81 deletions pkg/binding/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b5ab3e

Please sign in to comment.