Skip to content

Commit

Permalink
Update catalog for devfile v2 registry
Browse files Browse the repository at this point in the history
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
  • Loading branch information
maysunfaisal committed Jun 3, 2020
1 parent a82ca62 commit 13d67fc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
49 changes: 34 additions & 15 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package catalog
import (
"encoding/json"
"fmt"
"github.com/openshift/odo/pkg/preference"
"sort"
"strings"
"sync"

"github.com/openshift/odo/pkg/preference"

imagev1 "github.com/openshift/api/image/v1"
"github.com/openshift/odo/pkg/devfile/adapters/common"
parserCommon "github.com/openshift/odo/pkg/devfile/parser/data/common"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/util"
Expand All @@ -23,12 +25,6 @@ const (
apiVersion = "odo.dev/v1alpha1"
)

// DevfileRegistries contains the links of all devfile registries
var DevfileRegistries = []string{
"https://raw.githubusercontent.com/elsony/devfile-registry/master",
"https://che-devfile-registry.openshift.io/",
}

// GetDevfileRegistries gets devfile registries from preference file,
// if registry name is specified return the specific registry, otherwise return all registries
func GetDevfileRegistries(registryName string) (map[string]Registry, error) {
Expand Down Expand Up @@ -111,13 +107,17 @@ func GetDevfile(devfileLink string) (Devfile, error) {
// 3. Devfile has run command
// 4. Devfile has build command
func IsDevfileComponentSupported(devfile Devfile) bool {
hasDockerImage := false
hasAlias := false
hasRunCommand := false
hasBuildCommand := false
hasDockerImage := false // should be removed when v1 support ends
hasAlias := false // should be removed when v1 support ends
hasRunCommand := false // should be removed when v1 support ends
hasBuildCommand := false // should be removed when v1 support ends

hasComponentContainer := false
hasComponentContainerName := false
hasRunGroupCommand := false

for _, component := range devfile.Components {
if hasDockerImage && hasAlias {
if (hasDockerImage && hasAlias) || (hasComponentContainer && hasComponentContainerName) {
break
}

Expand All @@ -128,20 +128,31 @@ func IsDevfileComponentSupported(devfile Devfile) bool {
if !hasAlias {
hasAlias = len(component.Alias) > 0
}

if !hasComponentContainer {
hasComponentContainer = component.Container != nil
}

if hasComponentContainer && !hasComponentContainerName {
hasComponentContainerName = len(component.Container.Name) > 0
}
}

for _, command := range devfile.Commands {
if hasRunCommand && hasBuildCommand {
if (hasRunCommand && hasBuildCommand) || hasRunGroupCommand {
break
}

if !hasRunCommand {
hasRunCommand = strings.Contains(strings.ToLower(command.Name), string(common.DefaultDevfileRunCommand))
}

if !hasRunGroupCommand {
hasRunGroupCommand = command.Exec != nil && command.Exec.Group != nil && command.Exec.Group.Kind == string(parserCommon.RunCommandGroupType)
}
}

if hasDockerImage && hasAlias && hasRunCommand {
if (hasDockerImage && hasAlias && hasRunCommand) || (hasComponentContainer && hasComponentContainerName && hasRunGroupCommand) {
return true
}

Expand Down Expand Up @@ -207,9 +218,17 @@ func ListDevfileComponents(registryName string) (DevfileComponentTypeList, error
return
}

var componentName string

if devfile.MetaData.GenerateName != "" {
componentName = strings.TrimSuffix(devfile.MetaData.GenerateName, "-")
} else if devfile.MetaData.Name != "" {
componentName = strings.TrimSuffix(devfile.MetaData.Name, "-")
}

// Populate devfile component with devfile data and form devfile component list
catalogDevfile := DevfileComponentType{
Name: strings.TrimSuffix(devfile.MetaData.GenerateName, "-"),
Name: componentName,
DisplayName: devfileIndex.DisplayName,
Description: devfileIndex.Description,
Link: devfileIndex.Links.Link,
Expand Down
17 changes: 13 additions & 4 deletions pkg/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ type DevfileIndexEntry struct {
type Devfile struct {
APIVersion string `yaml:"apiVersion"`
MetaData struct {
GenerateName string `yaml:"generateName"`
GenerateName string `yaml:"generateName"` // should be removed when v1 support ends
Name string `yaml:"name"`
} `yaml:"metadata"`
Components []struct {
Type string `yaml:"type"`
Alias string `yaml:"alias"`
Type string `yaml:"type"` // should be removed when v1 support ends
Alias string `yaml:"alias"` // should be removed when v1 support ends
Container *struct {
Name string `yaml:"name"`
} `yaml:"container"`
} `yaml:"components"`
Commands []struct {
Name string `yaml:"name"`
Name string `yaml:"name"` // should be removed when v1 support ends
Exec *struct {
Group *struct {
Kind string `yaml:"kind"`
} `yaml:"group"`
} `yaml:"exec"`
} `yaml:"commands"`
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/preference/preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ const (

// DefaultDevfileRegistryURL is the URL of default devfile registry
DefaultDevfileRegistryURL = "https://raw.githubusercontent.com/elsony/devfile-registry/master"

// DefaultDevfileV2RegistryName is the name of default devfile v2 registry
DefaultDevfileV2RegistryName = "DefaultDevfileV2Registry"

// DefaultDevfileV2RegistryURL is the URL of default devfile registry
DefaultDevfileV2RegistryURL = "https://raw.githubusercontent.com/elsony/devfile2-registry/master"
)

// TimeoutSettingDescription is human-readable description for the timeout setting
Expand Down Expand Up @@ -214,9 +220,13 @@ func NewPreferenceInfo() (*PreferenceInfo, error) {
URL: CheDevfileRegistryURL,
},
{
Name: DefaultDevfileRegistryName,
Name: DefaultDevfileRegistryName, // should be removed when v1 support ends
URL: DefaultDevfileRegistryURL,
},
{
Name: DefaultDevfileV2RegistryName,
URL: DefaultDevfileV2RegistryURL,
},
}
c.OdoSettings.RegistryList = &defaultRegistryList
}
Expand Down

0 comments on commit 13d67fc

Please sign in to comment.