Skip to content

Commit

Permalink
Refactors url List() to use URL Client
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-dass committed Jan 18, 2021
1 parent 5b5f24f commit d3124f4
Show file tree
Hide file tree
Showing 14 changed files with 872 additions and 1,163 deletions.
25 changes: 16 additions & 9 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pkg/errors"
"k8s.io/klog"

devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
applabels "github.com/openshift/odo/pkg/application/labels"
"github.com/openshift/odo/pkg/catalog"
componentlabels "github.com/openshift/odo/pkg/component/labels"
Expand Down Expand Up @@ -599,7 +598,7 @@ func ensureAndLogProperResourceUsage(resourceMin, resourceMax *string, resourceN
// 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, containerComponents []devfilev1.Component, isS2I bool) (err error) {
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 @@ -611,6 +610,7 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
client.Namespace = kClient.Namespace
}

var localConfig localConfigProvider.LocalConfigProvider
if isS2I {
// if component exist then only call the update function
if cmpExist {
Expand All @@ -625,9 +625,11 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
if isS2I || kClient == nil {
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
localConfig = &componentConfig
} else {
componentName = envSpecificInfo.GetName()
applicationName = envSpecificInfo.GetApplication()
localConfig = &envSpecificInfo
}

isRouteSupported := false
Expand All @@ -636,14 +638,19 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
isRouteSupported = false
}

return urlpkg.Push(client, kClient, urlpkg.PushParameters{
ComponentName: componentName,
ApplicationName: applicationName,
ConfigURLs: componentConfig.ListURLs(),
EnvURLS: envSpecificInfo.ListURLs(),
urlClient := urlpkg.NewClient(urlpkg.ClientOptions{
OCClient: *client,
IsRouteSupported: isRouteSupported,
ContainerComponents: containerComponents,
IsS2I: isS2I,
LocalConfigProvider: localConfig,
})

return urlpkg.Push(client, kClient, urlpkg.PushParameters{
ComponentName: componentName,
ApplicationName: applicationName,
LocalConfig: localConfig,
URLClient: urlClient,
IsRouteSupported: isRouteSupported,
IsS2I: isS2I,
})
}

Expand Down
19 changes: 13 additions & 6 deletions pkg/component/component_full_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/openshift/odo/pkg/localConfigProvider"
"strings"

devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
devfileParser "github.com/devfile/library/pkg/devfile/parser"
"github.com/openshift/odo/pkg/envinfo"
"github.com/openshift/odo/pkg/kclient"
Expand Down Expand Up @@ -122,10 +121,10 @@ func NewComponentFullDescriptionFromClientAndLocalConfig(client *occlient.Client
cfd := &ComponentFullDescription{}
state := GetComponentState(client, componentName, applicationName)
var componentDesc Component
var devfile devfileParser.DevfileObj

var err error
if envInfo != nil {
componentDesc, devfile, err = GetComponentFromDevfile(envInfo)
componentDesc, _, err = GetComponentFromDevfile(envInfo)
} else {
componentDesc, err = GetComponentFromConfig(localConfigInfo)
}
Expand Down Expand Up @@ -156,13 +155,21 @@ func NewComponentFullDescriptionFromClientAndLocalConfig(client *occlient.Client
if e != nil {
return cfd, e
}
var components []devfilev1.Component

var configProvider localConfigProvider.LocalConfigProvider = localConfigInfo
if envInfo != nil {
configProvider = envInfo
components = devfile.Data.GetDevfileContainerComponents()
} else if localConfigInfo != nil {
configProvider = localConfigInfo
}
urls, err = urlpkg.ListIngressAndRoute(client, configProvider, components, componentName, routeSupported)

urlClient := urlpkg.NewClient(urlpkg.ClientOptions{
LocalConfigProvider: configProvider,
OCClient: *client,
IsRouteSupported: routeSupported,
})

urls, err = urlClient.List()
if err != nil {
log.Warningf("URLs couldn't not be retrieved: %v", err)
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/config/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ func (lc *LocalConfig) ListURLs() []localConfigProvider.LocalURL {
if lc.componentSettings.URL == nil {
return []localConfigProvider.LocalURL{}
}
return *lc.componentSettings.URL
var resultURLs []localConfigProvider.LocalURL
for _, url := range *lc.componentSettings.URL {
resultURLs = append(resultURLs, localConfigProvider.LocalURL{
Name: url.Name,
Port: url.Port,
Secure: url.Secure,
Host: url.Host,
Path: "/",
Kind: localConfigProvider.ROUTE,
})
}
return resultURLs
}

// DeleteURL is used to delete config from local odo config
Expand Down
4 changes: 2 additions & 2 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (a Adapter) Push(parameters common.PushParameters) (err error) {
if currentMode != previousMode {
parameters.RunModeChanged = true
}
containerComponents := a.Devfile.Data.GetDevfileContainerComponents()

err = a.createOrUpdateComponent(componentExists, parameters.EnvSpecificInfo)
if err != nil {
Expand All @@ -177,7 +176,8 @@ 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, containerComponents, false)
parameters.EnvSpecificInfo.SetDevfileObj(a.Devfile)
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
68 changes: 51 additions & 17 deletions pkg/envinfo/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,6 @@ func (ei *EnvInfo) GetURL(name string) *localConfigProvider.LocalURL {
return &url
}
}

// since listURL currently only returns URLs from the env
// search in the devfile too and fill the data from the endpoint
for _, component := range ei.devfileObj.Data.GetDevfileContainerComponents() {
for _, endpoint := range component.Container.Endpoints {
return &localConfigProvider.LocalURL{
Name: endpoint.Name,
Port: endpoint.TargetPort,
Secure: endpoint.Secure,
Path: endpoint.Path,
Container: component.Name,
}
}
}
return nil
}

Expand Down Expand Up @@ -229,10 +215,58 @@ func (esi *EnvSpecificInfo) CreateURL(url localConfigProvider.LocalURL) error {
// TODO return URLs from the devfile too
// ListURLs returns the urls from the env and devfile, returns default if nil
func (ei *EnvInfo) ListURLs() []localConfigProvider.LocalURL {
if ei.componentSettings.URL == nil {
return []localConfigProvider.LocalURL{}

envMap := make(map[string]localConfigProvider.LocalURL)
if ei.componentSettings.URL != nil {
for _, url := range *ei.componentSettings.URL {
envMap[url.Name] = url
}
}

var urls []localConfigProvider.LocalURL

if ei.devfileObj.Data == nil {
return urls
}

for _, comp := range ei.devfileObj.Data.GetDevfileContainerComponents() {
for _, localEndpoint := range comp.Container.Endpoints {
// only exposed endpoint will be shown as a URL in `odo url list`
if localEndpoint.Exposure == devfilev1.NoneEndpointExposure || localEndpoint.Exposure == devfilev1.InternalEndpointExposure {
continue
}

path := "/"
if localEndpoint.Path != "" {
path = localEndpoint.Path
}

secure := false
if localEndpoint.Secure || localEndpoint.Protocol == "https" || localEndpoint.Protocol == "wss" {
secure = true
}

url := localConfigProvider.LocalURL{
Name: localEndpoint.Name,
Port: localEndpoint.TargetPort,
Secure: secure,
Path: path,
Container: comp.Name,
}

if envInfoURL, exist := envMap[localEndpoint.Name]; exist {
url.Host = envInfoURL.Host
url.TLSSecret = envInfoURL.TLSSecret
url.Kind = envInfoURL.Kind
} else {
url.Kind = localConfigProvider.ROUTE
}

urls = append(urls, url)
}
}
return *ei.componentSettings.URL

return urls
}

// DeleteURL is used to delete environment specific info for url from envinfo and devfile
Expand Down
3 changes: 1 addition & 2 deletions pkg/odo/cli/component/common_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"

devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"
"github.com/fatih/color"
"github.com/openshift/odo/pkg/component"
Expand Down Expand Up @@ -128,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, []devfilev1.Component{}, true)
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
1 change: 1 addition & 0 deletions pkg/odo/cli/component/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (so *StatusOptions) Complete(name string, cmd *cobra.Command, args []string
return err
}
so.devObj = devObj
so.EnvSpecificInfo.SetDevfileObj(so.devObj)

var platformContext interface{}
if !pushtarget.IsPushTargetDocker() {
Expand Down
Loading

0 comments on commit d3124f4

Please sign in to comment.