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

Make Devfile the default deployment mechanism #3705

Merged
merged 7 commits into from
Sep 10, 2020
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
23 changes: 11 additions & 12 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
parsercommon "github.com/openshift/odo/pkg/devfile/parser/data/common"
"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 @@ -565,10 +564,10 @@ func ensureAndLogProperResourceUsage(resourceMin, resourceMax *string, resourceN
// envSpecificInfo: Component environment specific information, available if uses devfile
// cmpExist: true if components exists in the cluster
// endpointMap: value is devfile endpoint entry, key is the TargetPort for each enpoint entry
// 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 []parsercommon.DevfileComponent) (err error) {
isExperimentalModeEnabled := experimental.IsExperimentalModeEnabled()
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool, containerComponents []parsercommon.DevfileComponent, isS2I bool) (err error) {

if client == nil {
var err error
Expand All @@ -580,7 +579,7 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf
client.Namespace = kClient.Namespace
}

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 @@ -591,7 +590,7 @@ func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConf

var componentName string
var applicationName string
if !isExperimentalModeEnabled || kClient == nil {
if isS2I || kClient == nil {
johnmcollier marked this conversation as resolved.
Show resolved Hide resolved
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
} else {
Expand All @@ -605,13 +604,13 @@ 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,
ContainerComponents: containerComponents,
ComponentName: componentName,
ApplicationName: applicationName,
ConfigURLs: componentConfig.GetURL(),
EnvURLS: envSpecificInfo.GetURL(),
IsRouteSupported: isRouteSupported,
ContainerComponents: containerComponents,
IsS2I: isS2I,
})
}

Expand Down
23 changes: 10 additions & 13 deletions pkg/component/component_full_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/openshift/odo/pkg/config"
"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/storage"
urlpkg "github.com/openshift/odo/pkg/url"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -192,22 +191,20 @@ func (cfd *ComponentFullDescription) Print(client *occlient.Client) error {
if len(cfd.Spec.URL.Items) > 0 {
var output string

if !experimental.IsExperimentalModeEnabled() {
// if the component is not pushed
for i, componentURL := range cfd.Spec.URL.Items {
if componentURL.Status.State == urlpkg.StateTypePushed {
output += fmt.Sprintf(" · %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, "", experimental.IsExperimentalModeEnabled()), componentURL.Spec.Port)
for i, componentURL := range cfd.Spec.URL.Items {
if componentURL.Status.State == urlpkg.StateTypePushed {
output += fmt.Sprintf(" · %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, "", true), componentURL.Spec.Port)
} else {
var p string
if i >= len(cfd.Spec.Ports) {
p = cfd.Spec.Ports[len(cfd.Spec.Ports)-1]
} else {
var p string
if i >= len(cfd.Spec.Ports) {
p = cfd.Spec.Ports[len(cfd.Spec.Ports)-1]
} else {
p = cfd.Spec.Ports[i]
}
output += fmt.Sprintf(" · URL named %s will be exposed via %v\n", componentURL.Name, p)
p = cfd.Spec.Ports[i]
}
output += fmt.Sprintf(" · URL named %s will be exposed via %v\n", componentURL.Name, p)
}
}

// Cut off the last newline and output
if len(output) > 0 {
output = output[:len(output)-1]
Expand Down
6 changes: 3 additions & 3 deletions pkg/debug/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func NewDefaultPortForwarder(componentName, appName string, projectName string,
// portPair is a pair of port in format "localPort:RemotePort" that is to be forwarded
// stop Chan is used to stop port forwarding
// ready Chan is used to signal failure to the channel receiver
func (f *DefaultPortForwarder) ForwardPorts(portPair string, stopChan, readyChan chan struct{}, isExperimental bool) error {
func (f *DefaultPortForwarder) ForwardPorts(portPair string, stopChan, readyChan chan struct{}, isDevfile bool) error {
var pod *corev1.Pod
var conf *rest.Config
var err error

if f.kClient != nil && isExperimental {
if f.kClient != nil && isDevfile {
conf, err = f.kClient.KubeConfig.ClientConfig()
if err != nil {
return err
Expand Down Expand Up @@ -78,7 +78,7 @@ func (f *DefaultPortForwarder) ForwardPorts(portPair string, stopChan, readyChan
}

var req *rest.Request
if f.kClient != nil && isExperimental {
if f.kClient != nil && isDevfile {
req = f.kClient.GeneratePortForwardReq(pod.Name)
} else {
req = f.client.BuildPortForwardReq(pod.Name)
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 @@ -167,7 +167,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, containerComponents)
err = component.ApplyConfig(nil, &a.Client, config.LocalConfigInfo{}, parameters.EnvSpecificInfo, color.Output, componentExists, containerComponents, false)
if err != nil {
odoutil.LogErrorAndExit(err, "Failed to update config to component deployed.")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/validate/components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestValidateComponents(t *testing.T) {
got := validateComponents(components)
want := "size randomgarbage for volume component myvol is invalid"

if !strings.Contains(got.Error(), want) {
if got != nil && !strings.Contains(got.Error(), want) {
t.Errorf("TestValidateComponents error - got: '%v', want substring: '%v'", got.Error(), want)
}
})
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 @@ -719,11 +718,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
109 changes: 52 additions & 57 deletions pkg/odo/cli/catalog/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/machineoutput"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/odo/util/pushtarget"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
Expand Down Expand Up @@ -62,11 +61,11 @@ func (o *DescribeComponentOptions) Complete(name string, cmd *cobra.Command, arg
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogList, err := catalog.ListComponents(o.Client)
if err != nil {
if experimental.IsExperimentalModeEnabled() {
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")
} else {
errChannel <- err
}
// TODO:
// This MAY have to change in the future.. There is no good way to determine whether the user
// wants to list OpenShift or Kubernetes components. So we simply just warn in debug V(4) if
// we are unable to list anything from OpenShift.
klog.V(4).Info("Please log in to an OpenShift cluster to list OpenShift/s2i components")
}
for _, image := range catalogList.Items {
if image.Name == o.componentName {
Expand All @@ -76,18 +75,16 @@ func (o *DescribeComponentOptions) Complete(name string, cmd *cobra.Command, arg
}})
}

if experimental.IsExperimentalModeEnabled() {
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogDevfileList, err := catalog.ListDevfileComponents("")
if catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
o.GetDevfileComponentsByName(catalogDevfileList)
}})
}
tasks.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
catalogDevfileList, err := catalog.ListDevfileComponents("")
if catalogDevfileList.DevfileRegistries == nil {
log.Warning("Please run 'odo registry add <registry name> <registry URL>' to add registry for listing devfile components\n")
}
if err != nil {
errChannel <- err
}
o.GetDevfileComponentsByName(catalogDevfileList)
}})

return tasks.Run()
}
Expand All @@ -103,50 +100,48 @@ func (o *DescribeComponentOptions) Validate() (err error) {

// Run contains the logic for the command associated with DescribeComponentOptions
func (o *DescribeComponentOptions) Run() (err error) {
if experimental.IsExperimentalModeEnabled() {
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
if log.IsJSON() {
if len(o.devfileComponents) > 0 {
for _, devfileComponent := range o.devfileComponents {
devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

machineoutput.OutputSuccess(devObj)
w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
if log.IsJSON() {
if len(o.devfileComponents) > 0 {
for _, devfileComponent := range o.devfileComponents {
devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

machineoutput.OutputSuccess(devObj)
}
} else {
if len(o.devfileComponents) > 1 {
log.Warningf("There are multiple components named \"%s\" in different multiple devfile registries.\n", o.componentName)
}
if len(o.devfileComponents) > 0 {
fmt.Fprintln(w, "Devfile Component(s):")

for _, devfileComponent := range o.devfileComponents {
fmt.Fprintln(w, "\n* Registry: "+devfileComponent.Registry.Name)

devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

projects := devObj.Data.GetStarterProjects()
// only print project info if there is at least one project in the devfile
err = o.PrintDevfileStarterProjects(w, projects, devObj)
if err != nil {
return err
}
}
} else {
if len(o.devfileComponents) > 1 {
log.Warningf("There are multiple components named \"%s\" in different multiple devfile registries.\n", o.componentName)
}
if len(o.devfileComponents) > 0 {
fmt.Fprintln(w, "Devfile Component(s):")

for _, devfileComponent := range o.devfileComponents {
fmt.Fprintln(w, "\n* Registry: "+devfileComponent.Registry.Name)

devObj, err := GetDevfile(devfileComponent)
if err != nil {
return err
}

projects := devObj.Data.GetStarterProjects()
// only print project info if there is at least one project in the devfile
err = o.PrintDevfileStarterProjects(w, projects, devObj)
if err != nil {
return err
}
} else {
fmt.Fprintln(w, "There are no Odo devfile components with the name \""+o.componentName+"\"")
}
if o.component != "" {
fmt.Fprintln(w, "\nS2I Based Components:")
fmt.Fprintln(w, "-"+o.component)
}
fmt.Fprintln(w)
} else {
fmt.Fprintln(w, "There are no Odo devfile components with the name \""+o.componentName+"\"")
}
if o.component != "" {
fmt.Fprintln(w, "\nS2I Based Components:")
fmt.Fprintln(w, "-"+o.component)
}
fmt.Fprintln(w)
}

return nil
Expand Down
Loading