Fixes odo url list for s2i components (#3728)

* Fixes odo url list for s2i components

* Renames odoUtil to odoutil
This commit is contained in:
Mrinal Das
2020-08-21 05:00:30 +05:30
committed by GitHub
parent 4a67c9adaf
commit 2e5a781b28
2 changed files with 26 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package url
import (
"fmt"
"os"
"path/filepath"
"strconv"
"text/tabwriter"
@@ -18,10 +19,12 @@ import (
"github.com/openshift/odo/pkg/lclient"
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/openshift/odo/pkg/odo/cli/component"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util"
odoutil "github.com/openshift/odo/pkg/odo/util"
"github.com/openshift/odo/pkg/odo/util/completion"
"github.com/openshift/odo/pkg/url"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
ktemplates "k8s.io/kubectl/pkg/util/templates"
@@ -41,6 +44,8 @@ var (
type URLListOptions struct {
componentContext string
*genericclioptions.Context
isDevfile bool
}
// NewURLListOptions creates a new URLCreateOptions instance
@@ -50,7 +55,8 @@ func NewURLListOptions() *URLListOptions {
// Complete completes URLListOptions after they've been Listed
func (o *URLListOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
if experimental.IsExperimentalModeEnabled() {
o.isDevfile = util.CheckPathExists(filepath.Join(o.componentContext, component.DevfilePath))
if o.isDevfile {
o.Context = genericclioptions.NewDevfileContext(cmd)
o.EnvSpecificInfo, err = envinfo.NewEnvSpecificInfo(o.componentContext)
} else {
@@ -65,12 +71,12 @@ func (o *URLListOptions) Complete(name string, cmd *cobra.Command, args []string
// Validate validates the URLListOptions based on completed values
func (o *URLListOptions) Validate() (err error) {
return util.CheckOutputFlag(o.OutputFlag)
return odoutil.CheckOutputFlag(o.OutputFlag)
}
// Run contains the logic for the odo url list command
func (o *URLListOptions) Run() (err error) {
if experimental.IsExperimentalModeEnabled() {
if o.isDevfile {
if pushtarget.IsPushTargetDocker() {
componentName := o.EnvSpecificInfo.GetName()
client, err := lclient.New()

View File

@@ -394,5 +394,21 @@ var _ = Describe("odo devfile url command tests", func() {
output := helper.CmdShouldPass("oc", "get", "routes", "--namespace", namespace)
Expect(output).Should(ContainSubstring(url1))
})
// remove once https://github.com/openshift/odo/issues/3550 is resolved
It("should list URLs for s2i components", func() {
url1 := helper.RandString(5)
url2 := helper.RandString(5)
componentName := helper.RandString(6)
helper.CopyExample(filepath.Join("source", "nodejs"), context)
helper.CmdShouldPass("odo", "create", "nodejs", "--context", context, "--project", namespace, componentName, "--s2i")
helper.CmdShouldPass("odo", "url", "create", url1, "--port", "8080", "--context", context)
helper.CmdShouldPass("odo", "url", "create", url2, "--port", "8080", "--context", context, "--ingress", "--host", "com")
stdout := helper.CmdShouldPass("odo", "url", "list", "--context", context)
helper.MatchAllInOutput(stdout, []string{url1, url2})
})
})
})