Skip to content

Commit

Permalink
Make Devfile the default deployment mechanism for odo 2.0.0
Browse files Browse the repository at this point in the history
**What type of PR is this?**
> Uncomment only one ` /kind` line, and delete the rest.
> For example, `> /kind bug` would simply become: `/kind bug`

/kind feature

**What does does this PR do / why we need it**:

Makes Devfile the default deployment mechanism, removing S2I in favour
of Devfile deployment.

**Which issue(s) this PR fixes**:

redhat-developer#3550

**How to test changes / Special notes to the reviewer**:

Run:

```sh
odo preference set experimental false
odo create --starter nodejs
odo push
```

And it should deploy devfile.
  • Loading branch information
cdrage committed Jul 17, 2020
1 parent 378f4b8 commit 2196ce8
Show file tree
Hide file tree
Showing 30 changed files with 1,049 additions and 1,070 deletions.
34 changes: 14 additions & 20 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/openshift/odo/pkg/exec"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/odo/util/validation"
"github.com/openshift/odo/pkg/preference"
"github.com/openshift/odo/pkg/storage"
Expand Down Expand Up @@ -545,7 +544,6 @@ func ValidateComponentCreateRequest(client *occlient.Client, componentSettings c
// Returns:
// err: Errors if any else nil
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool) (err error) {
isExperimentalModeEnabled := experimental.IsExperimentalModeEnabled()

if client == nil {
var err error
Expand All @@ -556,23 +554,20 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
client.Namespace = envSpecificInfo.GetNamespace()
}

if !isExperimentalModeEnabled {
// if component exist then only call the update function
if cmpExist {
if err = Update(client, componentConfig, componentConfig.GetSourceLocation(), stdout); err != nil {
return err
}
// if component exist then only call the update function
if cmpExist {
if err = Update(client, componentConfig, componentConfig.GetSourceLocation(), stdout); err != nil {
return err
}
}

var componentName string
var applicationName string
if !isExperimentalModeEnabled || kClient == nil {
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
} else {
componentName = envSpecificInfo.GetName()
}
// Devfile
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
// NOTE: This used to be an if statement, use this for s2i only:
componentName = envSpecificInfo.GetName()

isRouteSupported := false
isRouteSupported, err = client.IsRouteSupported()
Expand All @@ -581,12 +576,11 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
}

return urlpkg.Push(client, kClient, urlpkg.PushParameters{
ComponentName: componentName,
ApplicationName: applicationName,
ConfigURLs: componentConfig.GetURL(),
EnvURLS: envSpecificInfo.GetURL(),
IsRouteSupported: isRouteSupported,
IsExperimentalModeEnabled: isExperimentalModeEnabled,
ComponentName: componentName,
ApplicationName: applicationName,
ConfigURLs: componentConfig.GetURL(),
EnvURLS: envSpecificInfo.GetURL(),
IsRouteSupported: isRouteSupported,
})
}

Expand Down
23 changes: 10 additions & 13 deletions pkg/component/component_full_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/openshift/odo/pkg/config"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/storage"
urlpkg "github.com/openshift/odo/pkg/url"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -190,20 +189,18 @@ func (cfd *ComponentFullDescription) Print(client *occlient.Client) error {
if len(cfd.Spec.URL.Items) > 0 {
var output string

if !experimental.IsExperimentalModeEnabled() {
// if the component is not pushed
for i, componentURL := range cfd.Spec.URL.Items {
if componentURL.Status.State == urlpkg.StateTypePushed {
output += fmt.Sprintf(" · %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, "", experimental.IsExperimentalModeEnabled()), componentURL.Spec.Port)
// if the component is not pushed
for i, componentURL := range cfd.Spec.URL.Items {
if componentURL.Status.State == urlpkg.StateTypePushed {
output += fmt.Sprintf(" · %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, ""), componentURL.Spec.Port)
} else {
var p string
if i >= len(cfd.Spec.Ports) {
p = cfd.Spec.Ports[len(cfd.Spec.Ports)-1]
} else {
var p string
if i >= len(cfd.Spec.Ports) {
p = cfd.Spec.Ports[len(cfd.Spec.Ports)-1]
} else {
p = cfd.Spec.Ports[i]
}
output += fmt.Sprintf(" · URL named %s will be exposed via %v\n", componentURL.Name, p)
p = cfd.Spec.Ports[i]
}
output += fmt.Sprintf(" · URL named %s will be exposed via %v\n", componentURL.Name, p)
}
}
// Cut off the last newline and output
Expand Down
7 changes: 1 addition & 6 deletions pkg/occlient/occlient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/openshift/odo/pkg/config"
"github.com/openshift/odo/pkg/devfile/adapters/common"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/preference"
"github.com/openshift/odo/pkg/util"

Expand Down Expand Up @@ -751,11 +750,7 @@ func (c *Client) GetImageStream(imageNS string, imageName string, imageTag strin
}
}
if e != nil && err != nil {
// Imagestream not found in openshift and current namespaces
if experimental.IsExperimentalModeEnabled() {
return nil, fmt.Errorf("component type %q not found", imageName)
}
return nil, err
return nil, fmt.Errorf("component type %q not found", imageName)
}

// Required tag not in openshift and current namespaces
Expand Down
106 changes: 52 additions & 54 deletions pkg/odo/cli/catalog/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/odo/util/pushtarget"
"github.com/openshift/odo/pkg/util"
pkgUtil "github.com/openshift/odo/pkg/util"
Expand Down Expand Up @@ -61,11 +60,14 @@ func (o *DescribeComponentOptions) Complete(name string, cmd *cobra.Command, arg
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogList, err := catalog.ListComponents(o.Client)
if err != nil {
if experimental.IsExperimentalModeEnabled() {
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")
} else {
errChannel <- err
}
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")

// S2I Only
/*
} else {
errChannel <- err
}
*/
}
for _, image := range catalogList.Items {
if image.Name == o.componentName {
Expand All @@ -75,18 +77,16 @@ func (o *DescribeComponentOptions) Complete(name string, cmd *cobra.Command, arg
}})
}

if experimental.IsExperimentalModeEnabled() {
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogDevfileList, err := catalog.ListDevfileComponents("")
if catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
o.GetDevfileComponentsByName(catalogDevfileList)
}})
}
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogDevfileList, err := catalog.ListDevfileComponents("")
if catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
o.GetDevfileComponentsByName(catalogDevfileList)
}})

return tasks.Run()
}
Expand All @@ -102,50 +102,48 @@ func (o *DescribeComponentOptions) Validate() (err error) {

// Run contains the logic for the command associated with DescribeComponentOptions
func (o *DescribeComponentOptions) Run() (err error) {
if experimental.IsExperimentalModeEnabled() {
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
if log.IsJSON() {
if len(o.devfileComponents) > 0 {
for _, devfileComponent := range o.devfileComponents {
devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

machineoutput.OutputSuccess(devObj)
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
if log.IsJSON() {
if len(o.devfileComponents) > 0 {
for _, devfileComponent := range o.devfileComponents {
devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

machineoutput.OutputSuccess(devObj)
}
} else {
if len(o.devfileComponents) > 1 {
log.Warningf("There are multiple components named \"%s\" in different multiple devfile registries.\n", o.componentName)
}
if len(o.devfileComponents) > 0 {
fmt.Fprintln(w, "Devfile Component(s):")
}
} else {
if len(o.devfileComponents) > 1 {
log.Warningf("There are multiple components named \"%s\" in different multiple devfile registries.\n", o.componentName)
}
if len(o.devfileComponents) > 0 {
fmt.Fprintln(w, "Devfile Component(s):")

for _, devfileComponent := range o.devfileComponents {
fmt.Fprintln(w, "\n* Registry: "+devfileComponent.Registry.Name)
for _, devfileComponent := range o.devfileComponents {
fmt.Fprintln(w, "\n* Registry: "+devfileComponent.Registry.Name)

devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}
devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

projects := devObj.Data.GetProjects()
// only print project info if there is at least one project in the devfile
err = o.PrintDevfileProjects(w, projects, devObj)
if err != nil {
return err
}
projects := devObj.Data.GetProjects()
// only print project info if there is at least one project in the devfile
err = o.PrintDevfileProjects(w, projects, devObj)
if err != nil {
return err
}
} else {
fmt.Fprintln(w, "There are no Odo devfile components with the name \""+o.componentName+"\"")
}
if o.component != "" {
fmt.Fprintln(w, "\nS2I Based Components:")
fmt.Fprintln(w, "-"+o.component)
}
fmt.Fprintln(w)
} else {
fmt.Fprintln(w, "There are no Odo devfile components with the name \""+o.componentName+"\"")
}
if o.component != "" {
fmt.Fprintln(w, "\nS2I Based Components:")
fmt.Fprintln(w, "-"+o.component)
}
fmt.Fprintln(w)
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/odo/cli/catalog/describe/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package describe

import (
"fmt"
"os"
"strings"

"github.com/olekukonko/tablewriter"
"github.com/openshift/odo/pkg/odo/genericclioptions"
svc "github.com/openshift/odo/pkg/service"
"github.com/spf13/cobra"
ktemplates "k8s.io/kubectl/pkg/util/templates"
"os"
"strings"
)

const serviceRecommendedCommandName = "service"
Expand Down
51 changes: 22 additions & 29 deletions pkg/odo/cli/catalog/list/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/openshift/odo/pkg/machineoutput"
catalogutil "github.com/openshift/odo/pkg/odo/cli/catalog/util"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/odo/util/pushtarget"
"github.com/openshift/odo/pkg/util"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -51,28 +50,24 @@ func (o *ListComponentsOptions) Complete(name string, cmd *cobra.Command, args [
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
o.catalogList, err = catalog.ListComponents(o.Client)
if err != nil {
if experimental.IsExperimentalModeEnabled() {
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")
} else {
errChannel <- err
}
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")
// S2I Only
// errChannel <- err
} else {
o.catalogList.Items = catalogutil.FilterHiddenComponents(o.catalogList.Items)
}
}})
}

if experimental.IsExperimentalModeEnabled() {
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
o.catalogDevfileList, err = catalog.ListDevfileComponents("")
if o.catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
}})
}
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
o.catalogDevfileList, err = catalog.ListDevfileComponents("")
if o.catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
}})

return tasks.Run()
}
Expand Down Expand Up @@ -101,19 +96,17 @@ func (o *ListComponentsOptions) Run() (err error) {
supported, _ := catalog.SliceSupportedTags(image)
o.catalogList.Items[i].Spec.SupportedTags = supported
}
if experimental.IsExperimentalModeEnabled() {
combinedList := combinedCatalogList{
TypeMeta: metav1.TypeMeta{
Kind: "List",
APIVersion: "odo.dev/v1alpha1",
},
S2iItems: o.catalogList.Items,
DevfileItems: o.catalogDevfileList.Items,
}
machineoutput.OutputSuccess(combinedList)
} else {
machineoutput.OutputSuccess(o.catalogList)
combinedList := combinedCatalogList{
TypeMeta: metav1.TypeMeta{
Kind: "List",
APIVersion: "odo.dev/v1alpha1",
},
S2iItems: o.catalogList.Items,
DevfileItems: o.catalogDevfileList.Items,
}
machineoutput.OutputSuccess(combinedList)
// S2I Only
// machineoutput.OutputSuccess(o.catalogList)
} else {
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
var supCatalogList, unsupCatalogList []catalog.ComponentType
Expand Down
1 change: 1 addition & 0 deletions pkg/odo/cli/catalog/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package list

import (
"fmt"

"github.com/openshift/odo/pkg/odo/util"
"github.com/spf13/cobra"
)
Expand Down
Loading

0 comments on commit 2196ce8

Please sign in to comment.