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

List created components for devfile v2 #3505

Merged

Conversation

girishramnani
Copy link
Contributor

@girishramnani girishramnani commented Jul 7, 2020

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:
support listing of components for devfilev2. The --path flag and json output would be added as a follow up.

Which issue(s) this PR fixes:

Fixes #2835
Fixes #3050

How to test changes / Special notes to the reviewer:
odo create nodejs
odo push
odo list

Created a follow up issue #3521 for stuff not covered by the issue story #2835


})

It("checks devfile and s2i components together", func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fun one

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes.

For some reason there's an issue deploying however..

I used odo create nodejs --starter

~/openshift/stuff                                                                                                                                                                                                                                                               ⍉
▶ odo push

Validation
 ✓  Validating the devfile [44773ns]

Initialization
 ✓  Initializing the component [3s]

Creating Docker resources for component nodejs
 ✓  Pulling image registry.access.redhat.com/ubi8/nodejs-12:1-36 [16s]
 ✓  Starting container for registry.access.redhat.com/ubi8/nodejs-12:1-36 [1s]

Syncing to component nodejs
 ✓  Checking files for pushing [678074ns]
 ✓  Syncing files to the component [331ms]

Executing devfile commands for component nodejs
 ✓  Executing install command "npm install" [2s]
 ✓  Executing run command "npm start" [1s]

Pushing devfile component nodejs
 ✓  Changes successfully pushed to component

~/openshift/stuff                                                                                                                                                                                                                                                                
▶ odo list
Experimental mode is enabled, use at your own risk

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1591280]

goroutine 1 [running]:
github.com/openshift/odo/pkg/kclient.(*Client).ListDeployments(0x0, 0x1c59402, 0x3, 0x10, 0xc000a4b8c0, 0xc000787b00)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/kclient/deployments.go:50 +0xf0
github.com/openshift/odo/pkg/odo/cli/component.(*ListOptions).Run(0xc000050e00, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/cli/component/list.go:169 +0x1578
github.com/openshift/odo/pkg/odo/genericclioptions.GenericRun(0x1f73640, 0xc000050e00, 0xc0000e6a00, 0x2fe0750, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/genericclioptions/runnable.go:31 +0x13c
github.com/openshift/odo/pkg/odo/cli/component.NewCmdList.func1(0xc0000e6a00, 0x2fe0750, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/cli/component/list.go:277 +0x5e
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).execute(0xc0000e6a00, 0x2fe0750, 0x0, 0x0, 0xc0000e6a00, 0x2fe0750)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:830 +0x2aa
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc00045e500, 0x1d6cc10, 0xc000529860, 0x1)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:914 +0x2fb
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:864
main.main()
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/cmd/odo/odo.go:67 +0x32a

})
}

func (c *Client) ListAllDeployments() (*appsv1.DeploymentList, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -42,6 +44,18 @@ func getDeploymentCondition(status appsv1.DeploymentStatus, condType appsv1.Depl
return nil
}

func (c *Client) ListDeployments(appName string) (*appsv1.DeploymentList, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

if len(lo.pathFlag) != 0 {

if experimental.IsExperimentalModeEnabled() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something or was this moved from somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component list didn't support experimental mode yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the --path flag support for experimental mode will be added as a follow up PR as the changes in this PR are already quite wide spread already

var dpl *appsv1.DeploymentList
var err error

// TODO: wrap this into a component list for docker support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a TODO here by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker support marker for someone who would implement it

components, err = component.List(lo.Client, lo.Application, lo.LocalConfigInfo)
if err != nil {
return errors.Wrapf(err, "failed to fetch components list")
klog.V(4).Infof("the components are %+v", components)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove this debug before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added by tomas like 8 months ago https://github.com/openshift/odo/blob/master/pkg/odo/cli/component/list.go#L143, I can remove this if you want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

if err != nil {
return err
return errors.Wrapf(err, "failed to fetch components list")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failed to fetch component list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@cdrage
Copy link
Member

cdrage commented Jul 7, 2020

Tried again with the newest changes and I still get an issue:

~/openshift/foobar                                                                                                                                                                                                                                                               
▶ odo create nodejs --starter
Experimental mode is enabled, use at your own risk

Validation
 ✓  Checking devfile existence [76586ns]
 ✓  Checking devfile compatibility [1ms]
 ✓  Creating a devfile component from registry: DefaultDevfileRegistry [1ms]
 ✓  Validating devfile component [338458ns]

Please use `odo push` command to create the component with source deployed

~/openshift/foobar                                                                                                                                                                                                                                                               
▶ odo push

Validation
 ✓  Validating the devfile [21778ns]

Syncing to component nodejs
 ✓  Checking file changes for pushing [451061ns]
 ✓  Syncing files to the component [364ms]

Executing devfile commands for component nodejs
 ✓  Executing install command "npm install" [1s]
 ✓  Executing run command "npm start" [2s]

Pushing devfile component nodejs
 ✓  Changes successfully pushed to component

~/openshift/foobar                                                                                                                                                                                                                                                               
▶ odo list
Experimental mode is enabled, use at your own risk

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1591280]

goroutine 1 [running]:
github.com/openshift/odo/pkg/kclient.(*Client).ListDeployments(0x0, 0xc0007212d0, 0x3, 0x10, 0xc00066a720, 0xc0006d1100)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/kclient/deployments.go:50 +0xf0
github.com/openshift/odo/pkg/odo/cli/component.(*ListOptions).Run(0xc000051e40, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/cli/component/list.go:169 +0x1578
github.com/openshift/odo/pkg/odo/genericclioptions.GenericRun(0x1f73640, 0xc000051e40, 0xc0002bc000, 0x2fe0750, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/genericclioptions/runnable.go:31 +0x13c
github.com/openshift/odo/pkg/odo/cli/component.NewCmdList.func1(0xc0002bc000, 0x2fe0750, 0x0, 0x0)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/pkg/odo/cli/component/list.go:277 +0x5e
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).execute(0xc0002bc000, 0x2fe0750, 0x0, 0x0, 0xc0002bc000, 0x2fe0750)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:830 +0x2aa
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000136000, 0x1d6cc10, 0xc0004ff620, 0x1)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:914 +0x2fb
github.com/openshift/odo/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/vendor/github.com/spf13/cobra/command.go:864
main.main()
        /home/wikus/syncthing/files/dev/go/src/github.com/openshift/odo/cmd/odo/odo.go:67 +0x32a

@girishramnani
Copy link
Contributor Author

I followed the same approach

girish@MacBook-Pro bbb % odo create nodejs --starter
Experimental mode is enabled, use at your own risk

Validation
 ✓  Checking devfile existence [55782ns]
 ✓  Checking devfile compatibility [172449ns]
 ✓  Creating a devfile component from registry: DefaultDevfileRegistry [168786ns]
 ✓  Validating devfile component [213798ns]

Please use `odo push` command to create the component with source deployed
girish@MacBook-Pro bbb % odo push                   

Validation
 ✓  Validating the devfile [126889ns]

Creating Kubernetes resources for component nodejs
 ✓  Waiting for component to start [4s]

Applying URL changes
 ✓  URLs are synced with the cluster, no changes are required.

Syncing to component nodejs
 ✓  Checking files for pushing [2ms]
 ✓  Syncing files to the component [4s]

Executing devfile commands for component nodejs
 ✓  Executing install command "npm install" [5s]
 ✓  Executing run command "npm start" [5s]

Pushing devfile component nodejs
 ✓  Changes successfully pushed to component
girish@MacBook-Pro bbb % odo list
Experimental mode is enabled, use at your own risk

Devfile Components: 
APP     NAME       PROJECT     TYPE       REVISION
app     nodejs     asdf        nodejs     1

can you share any pre-steps you are performing?

@girishramnani
Copy link
Contributor Author

Tried again on a kuberenetes cluster -

girish@MacBook-Pro bbb % odo create nodejs --starter
Experimental mode is enabled, use at your own risk

Validation
 ✓  Checking devfile existence [54923ns]
 ✓  Checking devfile compatibility [157220ns]
 ✓  Creating a devfile component from registry: DefaultDevfileRegistry [169341ns]
 ✓  Validating devfile component [991819ns]

Please use `odo push` command to create the component with source deployed
girish@MacBook-Pro bbb % odo push

Validation
 ✓  Validating the devfile [33293ns]

Creating Kubernetes resources for component nodejs
 ✓  Waiting for component to start [1m]

Applying URL changes
 ✓  URLs are synced with the cluster, no changes are required.

Syncing to component nodejs
 ✓  Checking files for pushing [889725ns]
 ✓  Syncing files to the component [310ms]

Executing devfile commands for component nodejs
 ✓  Executing install command "npm install" [3s]
 ✓  Executing run command "npm start" [1s]

Pushing devfile component nodejs
 ✓  Changes successfully pushed to component
girish@MacBook-Pro bbb % odo list
Experimental mode is enabled, use at your own risk

Devfile Components: 
APP     NAME       PROJECT     TYPE       REVISION
app     nodejs     default     nodejs     1

@girishramnani
Copy link
Contributor Author

@cdrage addressed all your comments

@girishramnani
Copy link
Contributor Author

/retest

2 similar comments
@girishramnani
Copy link
Contributor Author

/retest

@girishramnani
Copy link
Contributor Author

/retest

Comment on lines 3296 to 3303
list, err := c.discoveryClient.ServerResourcesForGroupVersion(groupVersion)
if kerrors.IsNotFound(err) {
return false, nil
} else if err != nil {
return false, err
}

for _, resources := range list.APIResources {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use isResourceSupported() for checking the existence of a resource.

Comment on lines 66 to 93
if util.CheckKubeConfigExist() {
klog.V(4).Infof("New Context")
lo.Context = genericclioptions.NewContext(cmd)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

lo.Client = genericclioptions.Client(cmd)
dcSupport, err := lo.Client.IsDeploymentConfigSupported()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe assign to lo.hasDCSupport directly here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if len(lo.Application) != 0 && lo.allAppsFlag {
klog.V(4).Infof("either --app and --all-apps both provided or provided --all-apps in a folder has app, use --all-apps anyway")
}

if experimental.IsExperimentalModeEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe store the value somewhere and use it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if experimental.IsExperimentalModeEnabled() {

var dpl *appsv1.DeploymentList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something better than dpl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for _, comp := range dpl.Items {
app := comp.Labels[applabels.ApplicationLabel]
cmpType := comp.Labels[componentlabels.ComponentTypeLabel]
revision := comp.Annotations["deployment.kubernetes.io/revision"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to display the revision?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allowed me to understand that my application was updated or not, does it reduce the UX?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems s2i components don't have this column. Can we have the component STATE instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Context("push with listing the devfile component", func() {

It("checks components in a specific app and all apps", func() {
helper.Chdir(currentWorkingDirectory)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to change directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, not changing the dir now

@girishramnani
Copy link
Contributor Author

/retest

const Group = "apps.openshift.io"
const Version = "v1"

return c.isResourceSupported(Group, Version, "DeploymentConfig")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to panic for me, when run against a s2i component in experimental mode, as the client is nil


panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1c29be0]

goroutine 1 [running]:
github.com/openshift/odo/pkg/occlient.(*Client).isResourceSupported(0x0, 0x24f97a2, 0x11, 0x24ea377, 0x2, 0x24f7688, 0x10, 0xc000261300, 0x0, 0x0)
        /home/mrinaldas/go/src/github.com/openshift/odo/pkg/occlient/occlient.go:3341 +0xf0
github.com/openshift/odo/pkg/occlient.(*Client).IsDeploymentConfigSupported(0x0, 0x0, 0x0, 0x0)
        /home/mrinaldas/go/src/github.com/openshift/odo/pkg/occlient/occlient.go:3295 +0x8c
github.com/openshift/odo/pkg/odo/cli/component.(*ListOptions).Complete(0xc0003ceac0, 0x24eafa4, 0x4, 0xc0006a3680, 0x39712d8, 0x0, 0x0, 0x0, 0x0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even fails for devfile components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved, so we cannot create the Client only if the resource exists as thats a catch 22 situation.

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Jul 21, 2020
Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good! Thanks for the update @girishramnani but this LGTM.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 21, 2020
@girishramnani
Copy link
Contributor Author

/retest

Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mik-dass

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Jul 22, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@dharmit
Copy link
Member

dharmit commented Jul 22, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@dharmit
Copy link
Member

dharmit commented Jul 22, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@openshift-merge-robot openshift-merge-robot merged commit f40bf97 into redhat-developer:master Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

app.kubernetes.io/managed-by label Support listing devfile v2 components in odo
8 participants