-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
556 additions
and
154 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
docs/website/versioned_docs/version-3.0.0/command-reference/remove-binding.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: odo remove binding | ||
--- | ||
|
||
## Description | ||
The `odo remove binding` command removes the link created between the component and a service via Service Binding. | ||
|
||
## Running the Command | ||
Running this command removes the reference from the devfile, but does not necessarily remove it from the cluster. To remove the ServiceBinding from the cluster, you must run `odo dev`, or `odo deploy`. | ||
|
||
The command takes a required `--name` flag that points to the name of the Service Binding to be removed. | ||
```shell | ||
odo remove binding --name <ServiceBinding_name> | ||
``` | ||
|
||
## Examples | ||
```shell | ||
$ odo remove binding --name redis-service-my-nodejs-app | ||
``` | ||
|
||
There is no interactive mode for this command at the moment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package binding | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/devfile/library/pkg/devfile/parser" | ||
sboApi "github.com/redhat-developer/service-binding-operator/apis/binding/v1alpha1" | ||
"gopkg.in/yaml.v2" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
backendpkg "github.com/redhat-developer/odo/pkg/binding/backend" | ||
"github.com/redhat-developer/odo/pkg/kclient" | ||
"github.com/redhat-developer/odo/pkg/libdevfile" | ||
) | ||
|
||
// ValidateAddBinding calls Validate method of the adequate backend | ||
func (o *BindingClient) ValidateAddBinding(flags map[string]string) error { | ||
var backend backendpkg.AddBindingBackend | ||
if len(flags) == 0 { | ||
backend = o.interactiveBackend | ||
} else { | ||
backend = o.flagsBackend | ||
} | ||
return backend.Validate(flags) | ||
} | ||
|
||
func (o *BindingClient) SelectServiceInstance(flags map[string]string, serviceMap map[string]unstructured.Unstructured) (string, error) { | ||
var backend backendpkg.AddBindingBackend | ||
if len(flags) == 0 { | ||
backend = o.interactiveBackend | ||
} else { | ||
backend = o.flagsBackend | ||
} | ||
return backend.SelectServiceInstance(flags[backendpkg.FLAG_SERVICE], serviceMap) | ||
} | ||
|
||
func (o *BindingClient) AskBindingName(serviceName, componentName string, flags map[string]string) (string, error) { | ||
var backend backendpkg.AddBindingBackend | ||
if len(flags) == 0 { | ||
backend = o.interactiveBackend | ||
} else { | ||
backend = o.flagsBackend | ||
} | ||
defaultBindingName := fmt.Sprintf("%v-%v", componentName, serviceName) | ||
return backend.AskBindingName(defaultBindingName, flags) | ||
} | ||
|
||
func (o *BindingClient) AskBindAsFiles(flags map[string]string) (bool, error) { | ||
var backend backendpkg.AddBindingBackend | ||
if len(flags) == 0 { | ||
backend = o.interactiveBackend | ||
} else { | ||
backend = o.flagsBackend | ||
} | ||
return backend.AskBindAsFiles(flags) | ||
} | ||
|
||
func (o *BindingClient) AddBinding(bindingName string, bindAsFiles bool, unstructuredService unstructured.Unstructured, obj parser.DevfileObj, componentContext string) (parser.DevfileObj, error) { | ||
service, err := o.kubernetesClient.NewServiceBindingServiceObject(unstructuredService, bindingName) | ||
if err != nil { | ||
return obj, err | ||
} | ||
|
||
deploymentName := fmt.Sprintf("%s-app", obj.GetMetadataName()) | ||
deploymentGVR, err := o.kubernetesClient.GetDeploymentAPIVersion() | ||
if err != nil { | ||
return obj, err | ||
} | ||
|
||
serviceBinding := kclient.NewServiceBindingObject(bindingName, bindAsFiles, deploymentName, deploymentGVR, []sboApi.Mapping{}, []sboApi.Service{service}) | ||
|
||
// Note: we cannot directly marshal the serviceBinding object to yaml because it doesn't do that in the correct k8s manifest format | ||
serviceBindingUnstructured, err := kclient.ConvertK8sResourceToUnstructured(serviceBinding) | ||
if err != nil { | ||
return obj, err | ||
} | ||
yamlDesc, err := yaml.Marshal(serviceBindingUnstructured.UnstructuredContent()) | ||
if err != nil { | ||
return obj, err | ||
} | ||
|
||
return libdevfile.AddKubernetesComponentToDevfile(string(yamlDesc), serviceBinding.Name, obj) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.