Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url list routes and ingress #3305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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