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 redhat-developer#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 Jul 24, 2020
1 parent c89c1ab commit 5e30032
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 140 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 @@ -542,10 +541,10 @@ func ValidateComponentCreateRequest(client *occlient.Client, componentSettings c
// 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 @@ -556,7 +555,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 @@ -567,7 +566,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 @@ -581,12 +580,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
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
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
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
32 changes: 16 additions & 16 deletions pkg/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type CreateParameters struct {

// Create creates a URL and returns url string and error if any
// portNumber is the target port number for the route and is -1 in case no port number is specified in which case it is automatically detected for components which expose only one service port)
func Create(client *occlient.Client, kClient *kclient.Client, parameters CreateParameters, isRouteSupported bool, isExperimental bool) (string, error) {
func Create(client *occlient.Client, kClient *kclient.Client, parameters CreateParameters, isRouteSupported bool, isS2I bool) (string, error) {

if parameters.urlKind != envinfo.INGRESS && parameters.urlKind != envinfo.ROUTE {
return "", fmt.Errorf("urlKind %s is not supported for URL creation", parameters.urlKind)
Expand All @@ -256,7 +256,7 @@ func Create(client *occlient.Client, kClient *kclient.Client, parameters CreateP

serviceName := ""

if isExperimental && parameters.urlKind == envinfo.INGRESS && kClient != nil {
if !isS2I && parameters.urlKind == envinfo.INGRESS && kClient != nil {
if parameters.host == "" {
return "", errors.Errorf("the host cannot be empty")
}
Expand Down Expand Up @@ -318,14 +318,14 @@ func Create(client *occlient.Client, kClient *kclient.Client, parameters CreateP
if err != nil {
return "", errors.Wrap(err, "unable to create ingress")
}
return GetURLString(GetProtocol(routev1.Route{}, *ingress), "", ingressDomain, isExperimental), nil
return GetURLString(GetProtocol(routev1.Route{}, *ingress), "", ingressDomain, false), nil
} else {
if !isRouteSupported {
return "", errors.Errorf("routes are not available on non OpenShift clusters")
}

var ownerReference metav1.OwnerReference
if !isExperimental || kClient == nil {
if isS2I || kClient == nil {
var err error
parameters.urlName, err = util.NamespaceOpenShiftObject(parameters.urlName, parameters.applicationName)
if err != nil {
Expand Down Expand Up @@ -360,7 +360,7 @@ func Create(client *occlient.Client, kClient *kclient.Client, parameters CreateP
if err != nil {
return "", errors.Wrap(err, "unable to create route")
}
return GetURLString(GetProtocol(*route, iextensionsv1.Ingress{}), route.Spec.Host, "", isExperimental), nil
return GetURLString(GetProtocol(*route, iextensionsv1.Ingress{}), route.Spec.Host, "", true), nil
}

}
Expand Down Expand Up @@ -684,8 +684,8 @@ func ConvertEnvinfoURL(envinfoURL envinfo.EnvInfoURL, serviceName string) URL {
}

// GetURLString returns a string representation of given url
func GetURLString(protocol, URL string, ingressDomain string, isExperimentalMode bool) string {
if isExperimentalMode && URL == "" {
func GetURLString(protocol, URL string, ingressDomain string, isS2I bool) string {
if !isS2I && URL == "" {
return protocol + "://" + ingressDomain
}
return protocol + "://" + URL
Expand Down Expand Up @@ -862,12 +862,12 @@ func getMachineReadableFormatDocker(internalPort int, externalPort int, hostIP s
}

type PushParameters struct {
ComponentName string
ApplicationName string
ConfigURLs []config.ConfigURL
EnvURLS []envinfo.EnvInfoURL
IsRouteSupported bool
IsExperimentalModeEnabled bool
ComponentName string
ApplicationName string
ConfigURLs []config.ConfigURL
EnvURLS []envinfo.EnvInfoURL
IsRouteSupported bool
IsS2I bool
}

// Push creates and deletes the required URLs
Expand All @@ -876,7 +876,7 @@ func Push(client *occlient.Client, kClient *kclient.Client, parameters PushParam

// in case the component is a s2i one
// kClient will be nil
if parameters.IsExperimentalModeEnabled && kClient != nil {
if !parameters.IsS2I && kClient != nil {
urls := parameters.EnvURLS
for _, url := range urls {
if url.Kind != envinfo.DOCKER {
Expand Down Expand Up @@ -905,7 +905,7 @@ func Push(client *occlient.Client, kClient *kclient.Client, parameters PushParam
}

urlCLUSTER := make(map[string]URL)
if parameters.IsExperimentalModeEnabled && kClient != nil {
if !parameters.IsS2I && kClient != nil {
urlList, err := ListPushedIngress(kClient, parameters.ComponentName)
if err != nil {
return err
Expand Down Expand Up @@ -992,7 +992,7 @@ func Push(client *occlient.Client, kClient *kclient.Client, parameters PushParam
secretName: urlInfo.Spec.TLSSecret,
urlKind: urlInfo.Spec.Kind,
}
host, err := Create(client, kClient, createParameters, parameters.IsRouteSupported, parameters.IsExperimentalModeEnabled)
host, err := Create(client, kClient, createParameters, parameters.IsRouteSupported, parameters.IsS2I)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 5e30032

Please sign in to comment.