Skip to content

Commit

Permalink
odo registry -o json (redhat-developer#5739)
Browse files Browse the repository at this point in the history
* Doc odo registry

* JSON output

* Move structure for JSON output to api package

* Doc for json output

* Add integration tests

* Review

* Do not rely on devfile version for tests as it is too unstable
  • Loading branch information
feloy authored and cdrage committed Aug 31, 2022
1 parent 2cc7ed7 commit c47233f
Show file tree
Hide file tree
Showing 30 changed files with 1,170 additions and 944 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,14 @@ The `odo list` command returns information about components running on a specifi

The `components` field lists the components either deployed in the cluster, or defined in the local Devfile.

The `componentsInDevfile` field lists the names of components present in the `components` list that are defined in the local Devfile.
The `componentInDevfile` field gives the name of the component present in the `components` list that is defined in the local Devfile, or is empty if no local Devfile is present.

In this example, the `component2` component is running in Deploy mode, and the command has been executed from a directory containing a Devfile defining a `component1` component, not running.

```bash
$ odo list --namespace project1
{
"componentsInDevfile": [
"component1"
],
"componentInDevfile": "component1",
"components": [
{
"name": "component2",
Expand All @@ -183,5 +181,77 @@ $ odo list --namespace project1
}
]
}
```

## odo registry -o json

The `odo registry` command lists all the Devfile stacks from Devfile registries. You can get the available flag in the [registry command reference](registry.md).

The default output will return information found into the registry index for stacks:

```shell
$ odo registry -o json
[
{
"name": "python-django",
"displayName": "Django",
"description": "Python3.7 with Django",
"registry": {
"name": "DefaultDevfileRegistry",
"url": "https://registry.devfile.io",
"secure": false
},
"language": "python",
"tags": [
"Python",
"pip",
"Django"
],
"projectType": "django",
"version": "1.0.0",
"starterProjects": [
"django-example"
]
}, [...]
]
```

Using the `--details` flag, you will also get information about the Devfile:

```shell
$ odo registry --details -o json
[
{
"name": "python-django",
"displayName": "Django",
"description": "Python3.7 with Django",
"registry": {
"name": "DefaultDevfileRegistry",
"url": "https://registry.devfile.io",
"secure": false
},
"language": "python",
"tags": [
"Python",
"pip",
"Django"
],
"projectType": "django",
"version": "1.0.0",
"starterProjects": [
"django-example"
],
"devfileData": {
"devfile": {
"schemaVersion": "2.0.0",
[ devfile.yaml file content ]
},
"supportedOdoFeatures": {
"dev": true,
"deploy": false,
"debug": true
}
},
}, [...]
]

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: odo registry
sidebar_position: 1
---

The `odo registry` command lists all the Devfile stacks from Devfile registries.

The Devfile registries that are taken into account are the registries added with the command
`odo preference registry`.

## Available Flags

By default, `odo registry` lists all the Devfile stacks from all the Devfile registries.

These flags let you filter the listed Devfile stacks:

* `--devfile <name>` to list the Devfile stacks with this exact name
* `--devfile-registry <name>` to list the Devfile stack of this registry (this is the `name` used
when adding the registry to the preferences with `odo preference registry add <name> <url>`)
* `--filter <term>` to list the Devfile for which the term is found in the devfile name or description

By default, the name, registry and description
of the Devfile stacks are displayed on a table.

This flag lets you change the content of the output:

* `--details` to display details about the Devfile stacks
* `-o json` to output the information in a JSON format

## Examples

For these examples, we consider we have two registries in our preferences:

```
shell
$ odo preference registry list
NAME URL SECURE
Staging https://registry.stage.devfile.io No
DefaultDevfileRegistry https://registry.devfile.io No
```

To get the complete list of accessible Devfile stacks:

```shell
$ odo registry
NAME REGISTRY DESCRIPTION
dotnet50 Staging Stack with .NET 5.0
dotnet50 DefaultDevfileRegistry Stack with .NET 5.0
dotnet60 Staging Stack with .NET 6.0
dotnet60 DefaultDevfileRegistry Stack with .NET 6.0
dotnetcore31 Staging Stack with .NET Core 3.1
dotnetcore31 DefaultDevfileRegistry Stack with .NET Core 3.1
go Staging Stack with the latest Go version
go DefaultDevfileRegistry Stack with the latest Go version
java-maven Staging Upstream Maven and OpenJDK 11
java-maven DefaultDevfileRegistry Upstream Maven and OpenJDK 11
[...]
```

To list the Devfile stacks from the Staging registry only:

```shell
$ odo registry --devfile-registry Staging
NAME REGISTRY DESCRIPTION
dotnet50 Staging Stack with .NET 5.0
dotnet60 Staging Stack with .NET 6.0
dotnetcore31 Staging Stack with .NET Core 3.1
go Staging Stack with the latest Go version
java-maven Staging Upstream Maven and OpenJDK 11
[...]
```

To list the Devfile stacks related to Maven:

```shell
$ odo registry --filter Maven
NAME REGISTRY DESCRIPTION
java-maven Staging Upstream Maven and OpenJDK 11
java-maven DefaultDevfileRegistry Upstream Maven and OpenJDK 11
java-openliberty Staging Java application Maven-built stack using...
java-openliberty DefaultDevfileRegistry Java application Maven-built stack using...
java-websphereliberty Staging Java application Maven-built stack using...
java-websphereliberty DefaultDevfileRegistry Java application Maven-built stack using...
java-wildfly-bootable-jar Staging Java stack with WildFly in bootable Jar ...
java-wildfly-bootable-jar DefaultDevfileRegistry Java stack with WildFly in bootable Jar ...
```

To get the details of the `java-maven` Devfile in the Staging registry:

```shell
$ odo registry --devfile java-maven --devfile-registry Staging --details
Name: java-maven
Display Name: Maven Java
Registry: Staging
Registry URL: https://registry.stage.devfile.io
Version: 1.1.0
Description: Upstream Maven and OpenJDK 11
Tags: Java, Maven
Project Type: maven
Language: java
Starter Projects:
- springbootproject
Supported odo Features:
- Dev: Y
- Deploy: N
- Debug: Y
```
8 changes: 4 additions & 4 deletions pkg/alizer/alizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func NewAlizerClient(registryClient registry.Client) *Alizer {

// DetectFramework uses the alizer library in order to detect the devfile
// to use depending on the files in the path
func (o *Alizer) DetectFramework(path string) (recognizer.DevFileType, registry.Registry, error) {
func (o *Alizer) DetectFramework(path string) (recognizer.DevFileType, api.Registry, error) {
types := []recognizer.DevFileType{}
components, err := o.registryClient.ListDevfileStacks("", "", "", false)
if err != nil {
return recognizer.DevFileType{}, registry.Registry{}, err
return recognizer.DevFileType{}, api.Registry{}, err
}
for _, component := range components.Items {
types = append(types, recognizer.DevFileType{
Expand All @@ -36,7 +36,7 @@ func (o *Alizer) DetectFramework(path string) (recognizer.DevFileType, registry.
}
typ, err := recognizer.SelectDevFileFromTypes(path, types)
if err != nil {
return recognizer.DevFileType{}, registry.Registry{}, err
return recognizer.DevFileType{}, api.Registry{}, err
}

// TODO(feloy): This part won't be necessary when SelectDevFileFromTypes returns the index
Expand All @@ -51,7 +51,7 @@ func (o *Alizer) DetectFramework(path string) (recognizer.DevFileType, registry.
return typ, registry, nil
}

func GetDevfileLocationFromDetection(typ recognizer.DevFileType, registry registry.Registry) *api.DevfileLocation {
func GetDevfileLocationFromDetection(typ recognizer.DevFileType, registry api.Registry) *api.DevfileLocation {
return &api.DevfileLocation{
Devfile: typ.Name,
DevfileRegistry: registry.Name,
Expand Down
13 changes: 7 additions & 6 deletions pkg/alizer/alizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/redhat-developer/odo/pkg/api"
"github.com/redhat-developer/odo/pkg/registry"
)

Expand All @@ -17,13 +18,13 @@ func GetTestProjectPath(folder string) string {
return filepath.Join(basepath, "..", "..", "tests/examples/source/", folder)
}

var types = []registry.DevfileStack{
var types = []api.DevfileStack{
{
Name: "java-maven",
Language: "java",
ProjectType: "maven",
Tags: []string{"Java", "Maven"},
Registry: registry.Registry{
Registry: api.Registry{
Name: "registry1",
},
},
Expand All @@ -32,7 +33,7 @@ var types = []registry.DevfileStack{
Language: "java",
ProjectType: "quarkus",
Tags: []string{"Java", "Quarkus"},
Registry: registry.Registry{
Registry: api.Registry{
Name: "registry1",
},
},
Expand All @@ -41,7 +42,7 @@ var types = []registry.DevfileStack{
Language: "java",
ProjectType: "wildfly",
Tags: []string{"Java", "WildFly"},
Registry: registry.Registry{
Registry: api.Registry{
Name: "registry2",
},
},
Expand All @@ -50,7 +51,7 @@ var types = []registry.DevfileStack{
Language: "javascript",
ProjectType: "nodejs",
Tags: []string{"NodeJS", "Express", "ubi8"},
Registry: registry.Registry{
Registry: api.Registry{
Name: "registry2",
},
},
Expand All @@ -59,7 +60,7 @@ var types = []registry.DevfileStack{
Language: "python",
ProjectType: "python",
Tags: []string{"Python", "pip"},
Registry: registry.Registry{
Registry: api.Registry{
Name: "registry3",
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/alizer/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package alizer

import (
"github.com/redhat-developer/alizer/go/pkg/apis/recognizer"
"github.com/redhat-developer/odo/pkg/registry"
"github.com/redhat-developer/odo/pkg/api"
)

type Client interface {
DetectFramework(path string) (recognizer.DevFileType, registry.Registry, error)
DetectFramework(path string) (recognizer.DevFileType, api.Registry, error)
}
6 changes: 3 additions & 3 deletions pkg/alizer/mock.go

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

24 changes: 24 additions & 0 deletions pkg/api/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

// Registry is the main struct of devfile registry
type Registry struct {
Name string `json:"name"`
URL string `json:"url"`
Secure bool `json:"secure"`
// Priority of the registry for listing purposes. The higher the number, the higher the priority
Priority int `json:"-"`
}

// DevfileStack is the main struct for devfile stack
type DevfileStack struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
Registry Registry `json:"registry"`
Language string `json:"language"`
Tags []string `json:"tags"`
ProjectType string `json:"projectType"`
Version string `json:"version"`
StarterProjects []string `json:"starterProjects"`
DevfileData *DevfileData `json:"devfileData,omitempty"`
}
Loading

0 comments on commit c47233f

Please sign in to comment.