Skip to content

Commit

Permalink
url list routes and ingress (redhat-developer#3305)
Browse files Browse the repository at this point in the history
* list routes and ingress

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* add unit tests

* add integration tests and describe partially works

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* finished unit test and integration for describe urls

* address review comments

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* add more unit tests

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* fix unit test failure

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* fix integration test failure

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* use ownerreference to distinguish real route vs route created from ingress

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* fix integration test

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* address review comment

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* fix a bug

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* fix a bug

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* also test secure state in url describe and list

Signed-off-by: Stephanie <stephanie.cao@ibm.com>

* try to avoid G404 error in unit test

Signed-off-by: Stephanie <stephanie.cao@ibm.com>
  • Loading branch information
Stephanie Cao authored and cdrage committed Jun 17, 2020
1 parent ba1b84f commit 84ac7a2
Show file tree
Hide file tree
Showing 8 changed files with 672 additions and 211 deletions.
20 changes: 17 additions & 3 deletions pkg/odo/cli/url/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"text/tabwriter"

"github.com/openshift/odo/pkg/envinfo"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/odo/util/pushtarget"

routev1 "github.com/openshift/api/route/v1"
Expand Down Expand Up @@ -104,19 +105,32 @@ func (o *URLDescribeOptions) Run() (err error) {
}
} else {
componentName := o.EnvSpecificInfo.GetName()
u, err := url.GetIngress(o.KClient, o.EnvSpecificInfo, o.url, componentName)
oclient, err := occlient.New()
if err != nil {
return err
}
oclient.Namespace = o.KClient.Namespace
routeSupported, err := oclient.IsRouteSupported()
if err != nil {
return err
}
u, err := url.GetIngressOrRoute(oclient, o.KClient, o.EnvSpecificInfo, o.url, componentName, routeSupported)
if err != nil {
return err
}
if log.IsJSON() {
machineoutput.OutputSuccess(u)
} else {
tabWriterURL := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT", "\t", "SECURE")
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT", "\t", "SECURE", "\t", "KIND")

// are there changes between local and cluster states?
outOfSync := false
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, url.ConvertIngressURLToIngress(u, componentName), experimental.IsExperimentalModeEnabled()), "", u.Spec.Host, experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure)
if u.Spec.Kind == envinfo.ROUTE {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(u.Spec.Protocol, u.Spec.Host, "", experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure, "\t", u.Spec.Kind)
} else {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, url.ConvertIngressURLToIngress(u, componentName)), "", u.Spec.Host, experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure, "\t", u.Spec.Kind)
}
if u.Status.State != url.StateTypePushed {
outOfSync = true
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/odo/cli/url/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"strconv"
"text/tabwriter"

routev1 "github.com/openshift/api/route/v1"
"github.com/openshift/odo/pkg/envinfo"
"github.com/openshift/odo/pkg/occlient"

"github.com/openshift/odo/pkg/odo/util/pushtarget"

"github.com/openshift/odo/pkg/odo/util/experimental"

routev1 "github.com/openshift/api/route/v1"
"github.com/openshift/odo/pkg/config"
"github.com/openshift/odo/pkg/lclient"
"github.com/openshift/odo/pkg/log"
Expand Down Expand Up @@ -114,7 +115,16 @@ func (o *URLListOptions) Run() (err error) {
}
} else {
componentName := o.EnvSpecificInfo.GetName()
urls, err := url.ListIngressURL(o.KClient, o.EnvSpecificInfo, componentName)
oclient, err := occlient.New()
if err != nil {
return err
}
oclient.Namespace = o.KClient.Namespace
routeSupported, err := oclient.IsRouteSupported()
if err != nil {
return err
}
urls, err := url.ListIngressAndRoute(oclient, o.KClient, o.EnvSpecificInfo, componentName, routeSupported)
if err != nil {
return err
}
Expand All @@ -124,19 +134,23 @@ func (o *URLListOptions) Run() (err error) {
if len(urls.Items) == 0 {
return fmt.Errorf("no URLs found for component %v", componentName)
}

log.Infof("Found the following URLs for component %v", componentName)
tabWriterURL := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT", "\t", "SECURE")
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT", "\t", "SECURE", "\t", "KIND")

// are there changes between local and cluster states?
outOfSync := false
for _, u := range urls.Items {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, url.ConvertIngressURLToIngress(u, componentName), experimental.IsExperimentalModeEnabled()), "", u.Spec.Host, experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure)
if u.Spec.Kind == envinfo.ROUTE {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(u.Spec.Protocol, u.Spec.Host, "", experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure, "\t", u.Spec.Kind)
} else {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, url.ConvertIngressURLToIngress(u, o.EnvSpecificInfo.GetName())), "", u.Spec.Host, experimental.IsExperimentalModeEnabled()), "\t", u.Spec.Port, "\t", u.Spec.Secure, "\t", u.Spec.Kind)
}
if u.Status.State != url.StateTypePushed {
outOfSync = true
}
}

tabWriterURL.Flush()
if outOfSync {
log.Info("There are local changes. Please run 'odo push'.")
Expand Down
14 changes: 7 additions & 7 deletions pkg/url/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type URL struct {

// URLSpec is
type URLSpec struct {
Host string `json:"host,omitempty"`
Protocol string `json:"protocol,omitempty"`
Port int `json:"port,omitempty"`
Secure bool `json:"secure"`
urlKind envinfo.URLKind
TLSSecret string `json:"tlssecret,omitempty"`
ExternalPort int `json:"externalport,omitempty"`
Host string `json:"host,omitempty"`
Protocol string `json:"protocol,omitempty"`
Port int `json:"port,omitempty"`
Secure bool `json:"secure"`
Kind envinfo.URLKind `json:"kind,omitempty"`
TLSSecret string `json:"tlssecret,omitempty"`
ExternalPort int `json:"externalport,omitempty"`
}

// AppList is a list of applications
Expand Down
Loading

0 comments on commit 84ac7a2

Please sign in to comment.