Skip to content

Commit

Permalink
Make Devfile the default deployment mechanism for odo
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**:

Closes #3550

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

Run:

```sh
odo preference set experimental false
odo create --starter nodejs
odo push
```
  • Loading branch information
cdrage committed Aug 4, 2020
1 parent 477fe77 commit 5e1dc68
Show file tree
Hide file tree
Showing 31 changed files with 460 additions and 455 deletions.
21 changes: 10 additions & 11 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 @@ -564,10 +563,10 @@ func ensureAndLogProperResourceUsage(resourceMin, resourceMax *string, resourceN
// componentConfig: Component configuration
// envSpecificInfo: Component environment specific information, available if uses devfile
// cmpExist: true if components exists in the cluster
// isS2I: Legacy option. Set as true if you want to use the old S2I method as it differentiates slightly.
// 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()
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool, isS2I bool) (err error) {

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

if !isExperimentalModeEnabled {
if isS2I {
// if component exist then only call the update function
if cmpExist {
if err = Update(client, componentConfig, componentConfig.GetSourceLocation(), stdout); err != nil {
Expand All @@ -589,7 +588,7 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf

var componentName string
var applicationName string
if !isExperimentalModeEnabled || kClient == nil {
if isS2I || kClient == nil {
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
} else {
Expand All @@ -603,12 +602,12 @@ 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,
IsS2I: isS2I,
})
}

Expand Down
25 changes: 12 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,22 +189,22 @@ 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)
// For S2I Only..
// 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, "", true), 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
if len(output) > 0 {
output = output[:len(output)-1]
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {
return errors.Wrapf(err, "unable to get pod for component %s", a.ComponentName)
}

err = component.ApplyConfig(nil, &a.Client, config.LocalConfigInfo{}, parameters.EnvSpecificInfo, color.Output, componentExists)
err = component.ApplyConfig(nil, &a.Client, config.LocalConfigInfo{}, parameters.EnvSpecificInfo, color.Output, componentExists, false)
if err != nil {
odoutil.LogErrorAndExit(err, "Failed to update config to component deployed.")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/validate/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestValidateComponents(t *testing.T) {
got := validateComponents(components)
want := "size randomgarbage for volume component myvol is invalid"

if !strings.Contains(got.Error(), want) {
if got != nil && !strings.Contains(got.Error(), want) {
t.Errorf("TestValidateComponents error - got: '%v', want substring: '%v'", got.Error(), want)
}
})
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
11 changes: 4 additions & 7 deletions pkg/odo/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/openshift/odo/pkg/odo/cli/version"
"github.com/openshift/odo/pkg/odo/util"
odoutil "github.com/openshift/odo/pkg/odo/util"
"github.com/openshift/odo/pkg/odo/util/experimental"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -205,12 +204,10 @@ func odoRootCmd(name, fullName string) *cobra.Command {
debug.NewCmdDebug(debug.RecommendedCommandName, util.GetFullName(fullName, debug.RecommendedCommandName)),
)

if experimental.IsExperimentalModeEnabled() {
rootCmd.AddCommand(
registry.NewCmdRegistry(registry.RecommendedCommandName, util.GetFullName(fullName, registry.RecommendedCommandName)),
component.NewCmdTest(component.TestRecommendedCommandName, util.GetFullName(fullName, component.TestRecommendedCommandName)),
)
}
rootCmd.AddCommand(
registry.NewCmdRegistry(registry.RecommendedCommandName, util.GetFullName(fullName, registry.RecommendedCommandName)),
component.NewCmdTest(component.TestRecommendedCommandName, util.GetFullName(fullName, component.TestRecommendedCommandName)),
)

odoutil.VisitCommands(rootCmd, reconfigureCmdWithSubcmd)

Expand Down
11 changes: 7 additions & 4 deletions pkg/odo/cli/component/common_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/secret"
svc "github.com/openshift/odo/pkg/service"
"github.com/openshift/odo/pkg/util"
Expand All @@ -38,6 +37,8 @@ type commonLinkOptions struct {
secretName string
isTargetAService bool

devfilePath string

suppliedName string
operation func(secretName, componentName, applicationName string) error
operationName string
Expand All @@ -55,12 +56,13 @@ func newCommonLinkOptions() *commonLinkOptions {

// Complete completes LinkOptions after they've been created
func (o *commonLinkOptions) complete(name string, cmd *cobra.Command, args []string) (err error) {

o.operationName = name

suppliedName := args[0]
o.suppliedName = suppliedName

if experimental.IsExperimentalModeEnabled() {
if util.CheckPathExists(o.devfilePath) {
o.Context = genericclioptions.NewDevfileContext(cmd)

oclient, err := occlient.New()
Expand Down Expand Up @@ -161,7 +163,7 @@ func (o *commonLinkOptions) complete(name string, cmd *cobra.Command, args []str

func (o *commonLinkOptions) validate(wait bool) (err error) {

if experimental.IsExperimentalModeEnabled() {
if util.CheckPathExists(o.devfilePath) {
// let's validate if the service exists
svcFullName := strings.Join([]string{o.serviceType, o.serviceName}, "/")
svcExists, err := svc.OperatorSvcExists(o.KClient, svcFullName)
Expand Down Expand Up @@ -227,7 +229,8 @@ func (o *commonLinkOptions) validate(wait bool) (err error) {
}

func (o *commonLinkOptions) run() (err error) {
if experimental.IsExperimentalModeEnabled() {

if util.CheckPathExists(o.devfilePath) {
// convert service binding request into a ma[string]interface{} type so
// as to use it with dynamic client
sbrMap := make(map[string]interface{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/component/common_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (cpo *CommonPushOptions) createCmpIfNotExistsAndApplyCmpConfig(stdout io.Wr
}
}
// Apply config
err := component.ApplyConfig(cpo.Context.Client, nil, *cpo.LocalConfigInfo, envinfo.EnvSpecificInfo{}, stdout, cpo.doesComponentExist)
err := component.ApplyConfig(cpo.Context.Client, nil, *cpo.LocalConfigInfo, envinfo.EnvSpecificInfo{}, stdout, cpo.doesComponentExist, true)
if err != nil {
odoutil.LogErrorAndExit(err, "Failed to update config to component deployed.")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/odo/cli/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func NewCmdComponent(name, fullName string) *cobra.Command {
componentCmd.Flags().AddFlagSet(componentGetCmd.Flags())

componentCmd.AddCommand(componentGetCmd, createCmd, deleteCmd, describeCmd, linkCmd, unlinkCmd, listCmd, logCmd, pushCmd, updateCmd, watchCmd, execCmd)

// Experimental feature to be added, "odo test" command.
if experimental.IsExperimentalModeEnabled() {
componentCmd.AddCommand(testCmd)
}
Expand Down
Loading

0 comments on commit 5e1dc68

Please sign in to comment.