Skip to content

Commit

Permalink
Merge 489855e into f1b2c72
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Jun 2, 2022
2 parents f1b2c72 + 489855e commit 92603c9
Show file tree
Hide file tree
Showing 19 changed files with 1,388 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: odo describe binding
---

## Description

`odo describe binding` command is useful for getting information about service bindings.

This command supports the service bindings added with the command `odo add binding` and bindings added manually to the Devfile, using a `ServiceBinding` resource from one of these apiVersion:
- `binding.operators.coreos.com/v1alpha1`
- `servicebinding.io/v1alpha3`

## Running the Command

There are 2 ways to describe a service binding:
- [Describe with access to Devfile](#describe-with-access-to-devfile)
- [Describe without access to Devfile](#describe-without-access-to-devfile)

### Describe with access to Devfile

This command returns information extracted from the Devfile and, if possible, from the cluster.

The command lists the Kubernetes resources declared in the Devfile as a Kubernetes component,
with the kind `ServiceBinding` and one of these apiVersion:
- `binding.operators.coreos.com/v1alpha1`
- `servicebinding.io/v1alpha3`

For each of these resources, the following information is displayed:
- the resource name,
- the list of the services to which the component is bound using this service binding,
- if the variables are bound as files or as environment variables,
- if the binding information is auto-detected.

When the service binding are not deployed yet to the cluster:

```shell
$ odo describe binding
ServiceBinding used by the current component:

Service Binding Name: my-nodejs-app-cluster-sample
Services:
• cluster-sample (Cluster.postgresql.k8s.enterprisedb.io)
Bind as files: false
Detect binding resources: true
Available binding information: unknown

Service Binding Name: my-nodejs-app-redis-standalone
Services:
• redis-standalone (Redis.redis.redis.opstreelabs.in)
Bind as files: false
Detect binding resources: true
Available binding information: unknown

Binding information for one or more ServiceBinding is not available because they don't exist on the cluster yet.
Start "odo dev" first to see binding information.
```
When the resources have been deployed to the cluster, the command also extracts information from the status of the resources to display information about the variables that can be used from the component.
```shell
$ odo describe binding
ServiceBinding used by the current component:
Service Binding Name: my-nodejs-app-cluster-sample-2
Services:
• cluster-sample-2 (Cluster.postgresql.k8s.enterprisedb.io)
Bind as files: false
Detect binding resources: true
Available binding information:
• CLUSTER_PASSWORD
• CLUSTER_PROVIDER
• CLUSTER_TLS.CRT
• CLUSTER_TLS.KEY
• CLUSTER_USERNAME
• CLUSTER_CA.KEY
• CLUSTER_CLUSTERIP
• CLUSTER_HOST
• CLUSTER_PGPASS
• CLUSTER_TYPE
• CLUSTER_CA.CRT
• CLUSTER_DATABASE
Service Binding Name: my-nodejs-app-redis-standalone
Services:
• redis-standalone (Redis.redis.redis.opstreelabs.in)
Bind as files: false
Detect binding resources: true
Available binding information:
• REDIS_CLUSTERIP
• REDIS_HOST
• REDIS_PASSWORD
• REDIS_TYPE
```
### Describe without access to Devfile
```shell
odo describe binding --name <component_name>
```
The command extracts information from the cluster.
The command searches for a resource in the current namespace with the given name, the kind `ServiceBinding` and one of these apiVersion:
- `binding.operators.coreos.com/v1alpha1`
- `servicebinding.io/v1alpha3`
If a resource is found, it displays information about the service binding and the variables that can be used from the component.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: odo describe
title: odo describe component
---

`odo describe component` command is useful for getting information about a component managed by `odo`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,113 @@ $ odo registry --details -o json
},
}, [...]
]
```

## odo describe binding -o json

The `odo describe binding` command lists all the service binding resources declared in the devfile
and, if the resource is deployed to the cluster, also displays the variables that can be used from
the component.

If a name is given, the command does not extract information from the Devfile, but instead extracts
information from the deployed resource with the given name.

Without a name, the output of the command is a list of service binding details, for example:

```shell
$ odo describe binding -o json
[
{
"name": "my-first-binding",
"spec": {
"services": [
{
"apiVersion": "postgresql.k8s.enterprisedb.io/v1",
"kind": "Cluster",
"name": "cluster-sample"
}
],
"detectBindingResources": false,
"bindAsFiles": true
},
"status": {
"bindingsFiles": [
"${SERVICE_BINDING_ROOT}/my-first-binding/host",
"${SERVICE_BINDING_ROOT}/my-first-binding/password",
"${SERVICE_BINDING_ROOT}/my-first-binding/pgpass",
"${SERVICE_BINDING_ROOT}/my-first-binding/provider",
"${SERVICE_BINDING_ROOT}/my-first-binding/type",
"${SERVICE_BINDING_ROOT}/my-first-binding/username",
"${SERVICE_BINDING_ROOT}/my-first-binding/database"
],
"bindingEnvVars": [
"PASSWD"
]
}
},
{
"name": "my-second-binding",
"spec": {
"services": [
{
"apiVersion": "postgresql.k8s.enterprisedb.io/v1",
"kind": "Cluster",
"name": "cluster-sample-2"
}
],
"detectBindingResources": true,
"bindAsFiles": true
},
"status": {
"bindingsFiles": [
"${SERVICE_BINDING_ROOT}/my-second-binding/ca.crt",
"${SERVICE_BINDING_ROOT}/my-second-binding/clusterIP",
"${SERVICE_BINDING_ROOT}/my-second-binding/database",
"${SERVICE_BINDING_ROOT}/my-second-binding/host",
"${SERVICE_BINDING_ROOT}/my-second-binding/ca.key",
"${SERVICE_BINDING_ROOT}/my-second-binding/password",
"${SERVICE_BINDING_ROOT}/my-second-binding/pgpass",
"${SERVICE_BINDING_ROOT}/my-second-binding/provider",
"${SERVICE_BINDING_ROOT}/my-second-binding/tls.crt",
"${SERVICE_BINDING_ROOT}/my-second-binding/tls.key",
"${SERVICE_BINDING_ROOT}/my-second-binding/type",
"${SERVICE_BINDING_ROOT}/my-second-binding/username"
]
}
}
]
```

When specifying a name, the output is a unique service binding:

```shell
$ odo describe binding --name my-first-binding -o json
{
"name": "my-first-binding",
"spec": {
"services": [
{
"apiVersion": "postgresql.k8s.enterprisedb.io/v1",
"kind": "Cluster",
"name": "cluster-sample"
}
],
"detectBindingResources": false,
"bindAsFiles": true
},
"status": {
"bindingsFiles": [
"${SERVICE_BINDING_ROOT}/my-first-binding/host",
"${SERVICE_BINDING_ROOT}/my-first-binding/password",
"${SERVICE_BINDING_ROOT}/my-first-binding/pgpass",
"${SERVICE_BINDING_ROOT}/my-first-binding/provider",
"${SERVICE_BINDING_ROOT}/my-first-binding/type",
"${SERVICE_BINDING_ROOT}/my-first-binding/username",
"${SERVICE_BINDING_ROOT}/my-first-binding/database"
],
"bindingEnvVars": [
"PASSWD"
]
}
}
```
63 changes: 63 additions & 0 deletions pkg/api/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package api

import (
bindingApi "github.com/redhat-developer/service-binding-operator/apis/binding/v1alpha1"
specApi "github.com/redhat-developer/service-binding-operator/apis/spec/v1alpha3"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// ServiceBinding describes a service binding, from group binding.operators.coreos.com/v1alpha1 or servicebinding.io/v1alpha3
type ServiceBinding struct {
Name string `json:"name"`
Spec ServiceBindingSpec `json:"spec"`
Status *ServiceBindingStatus `json:"status,omitempty"`
}

type ServiceBindingSpec struct {
Services []specApi.ServiceBindingServiceReference `json:"services"`
DetectBindingResources bool `json:"detectBindingResources"`
BindAsFiles bool `json:"bindAsFiles"`
}

type ServiceBindingStatus struct {
BindingFiles []string `json:"bindingsFiles,omitempty"`
BindingEnvVars []string `json:"bindingEnvVars,omitempty"`
}

// ServiceBindingFromBinding returns a common api.ServiceBinding structure
// from a ServiceBinding.binding.operators.coreos.com/v1alpha1
func ServiceBindingFromBinding(binding bindingApi.ServiceBinding) ServiceBinding {

var dstSvcs []specApi.ServiceBindingServiceReference
for _, srcSvc := range binding.Spec.Services {
dstSvc := specApi.ServiceBindingServiceReference{
Name: srcSvc.Name,
}
dstSvc.APIVersion, dstSvc.Kind = schema.GroupVersion{
Group: srcSvc.Group,
Version: srcSvc.Version,
}.WithKind(srcSvc.Kind).ToAPIVersionAndKind()
dstSvcs = append(dstSvcs, dstSvc)
}
return ServiceBinding{
Name: binding.Name,
Spec: ServiceBindingSpec{
Services: dstSvcs,
DetectBindingResources: binding.Spec.DetectBindingResources,
BindAsFiles: binding.Spec.BindAsFiles,
},
}
}

// ServiceBindingFromSpec returns a common api.ServiceBinding structure
// from a ServiceBinding.servicebinding.io/v1alpha3
func ServiceBindingFromSpec(spec specApi.ServiceBinding) ServiceBinding {
return ServiceBinding{
Name: spec.Name,
Spec: ServiceBindingSpec{
Services: []specApi.ServiceBindingServiceReference{spec.Spec.Service},
DetectBindingResources: false,
BindAsFiles: true,
},
}
}
Loading

0 comments on commit 92603c9

Please sign in to comment.