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

Deploy, Events without devfile/adapters #5460

Merged

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Feb 14, 2022

What type of PR is this:

/kind cleanup

What does this PR do / why we need it:

This PR rewrites the part of the devfile/adapters package used to execute commands, for the moment Deploy and Events commands, but can be completed to support other Commands (Build, Run, Test).

The content of the libdevfile package only cares about the devfile structure, and calls methods of the received handler to run the odo specific work. This way, devfile and odo code are clearly separated. The target is to include this code into the devfile/library, if devfile team agrees.

It also includes some convenient functions to create Command and Components of specific types (mostly convenient for writing tests).

The commands using this implementation:

  • the odo deploy and odo delete --deploy commands.
  • the odo push and odo delete commands parts dealing with postStart and preStop events.

It also moves some methods from the devfile/adapters package to the pkg/component package, as these methods are 100% component related and not devfile related.

Which issue(s) this PR fixes:

partially #5298
Fixes #5454

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:
Refer #5460 (comment) if you want to have the devfiles used for testing while working on the code for this PR.

@netlify
Copy link

netlify bot commented Feb 14, 2022

✔️ Deploy Preview for odo-docusaurus-preview ready!

🔨 Explore the source changes: 9f5923c

🔍 Inspect the deploy log: https://app.netlify.com/sites/odo-docusaurus-preview/deploys/6215e4aea703960007ca20d0

😎 Browse the preview: https://deploy-preview-5460--odo-docusaurus-preview.netlify.app

@feloy feloy requested review from valaparthvi, kadel and cdrage and removed request for rnapoles-rh February 14, 2022 17:51
@odo-robot
Copy link

odo-robot bot commented Feb 14, 2022

Unit Tests on commit 1431a1c finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 14, 2022

OpenShift Tests on commit 1431a1c finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 14, 2022

Validate Tests on commit 1431a1c finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 14, 2022

Kubernetes Tests on commit 1431a1c finished with errors.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Feb 14, 2022

Windows Tests (OCP) on commit 1431a1c finished with errors.
View logs: TXT HTML

@feloy feloy force-pushed the without-devfile-adapters branch from d5e9f17 to 51dacab Compare February 15, 2022 12:31
@feloy feloy changed the title Deploy without devfile/adapters Deploy, Events without devfile/adapters Feb 15, 2022
@feloy feloy force-pushed the without-devfile-adapters branch 2 times, most recently from 231ceb6 to f867c10 Compare February 15, 2022 15:10
Copy link
Member

@dharmit dharmit left a comment

Choose a reason for hiding this comment

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

Reviewed only pkg/libdevfile/ yet.

pkg/libdevfile/libdevfile.go Outdated Show resolved Hide resolved
pkg/libdevfile/libdevfile.go Show resolved Hide resolved
pkg/libdevfile/libdevfile.go Outdated Show resolved Hide resolved
pkg/libdevfile/command.go Show resolved Hide resolved
pkg/libdevfile/component.go Show resolved Hide resolved
pkg/libdevfile/component.go Show resolved Hide resolved
Copy link
Member

@dharmit dharmit left a comment

Choose a reason for hiding this comment

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

Only reviewed pkg/component/component.go.

@@ -503,3 +509,87 @@ func setLinksServiceNames(client kclient.ClientInterface, linkedSecrets []Secret
}
return nil
}

Copy link
Member

Choose a reason for hiding this comment

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

Among all the packages we have created the client interface for at business layer, component package has not been modified so far. Does it make sense to do 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.

The component one is the more complex to refactor. I'll need to sleep before ;) Joke aside, no, it will deserve PR all to itself

Copy link
Member

Choose a reason for hiding this comment

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

I'm going to need some sleep myself to form a mental picture of odo's code architecture. You're changing it fast (not complaining, complimenting), and it's tough to keep up at times. 😅

@dharmit
Copy link
Member

dharmit commented Feb 16, 2022

@feloy maybe it's just me, but an example devfile that could be used to test the changes here by stepping through the code would be helpful because the PR is overall about refactoring and introducing a different (new?) code architecture. Do you know of a devfile I can use right away? Preferably a complete devfile, and not something in bits and pieces.

@feloy
Copy link
Contributor Author

feloy commented Feb 16, 2022

@feloy maybe it's just me, but an example devfile that could be used to test the changes here by stepping through the code would be helpful because the PR is overall about refactoring and introducing a different (new?) code architecture. Do you know of a devfile I can use right away? Preferably a complete devfile, and not something in bits and pieces.

I've used this one to test the events: https://github.com/redhat-developer/odo/blob/main/tests/examples/source/devfiles/nodejs/devfile-with-valid-events.yaml
And this one for deploy/undeploy: https://github.com/redhat-developer/odo/blob/main/tests/examples/source/devfiles/nodejs/devfile-deploy.yaml

type command interface {
CheckValidity() error
Execute(handler Handler) error
UnExecute() error
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is no longer needed it seems. I remember adding it to implement undeploy, but since Execute of undeployHandler handles the undeployment part, we can remove this method, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, good catch

cmd = newExecCommand(devfileObj, devfileCmd)
}

if err := cmd.CheckValidity(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err := cmd.CheckValidity(); err != nil {
if err = cmd.CheckValidity(); err != nil {

}

func getCmdline(command v1alpha2.Command) []string {
exe := command.Exec
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you can get rid off this variable?

}
return foundGroupCmd, nil
}
return groupCmds[0], nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This returns the command even if it might not be default. I assume we consider that if only one command is present, take it as default?

Copy link
Contributor Author

@feloy feloy Feb 17, 2022

Choose a reason for hiding this comment

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

Yes, that's assumed (it is explained in the comment of the function).

Comment on lines 38 to 42
return fmt.Errorf("component %q does not exists", o.command.Apply.Component)
}

if len(devfileComponents) != 1 {
return fmt.Errorf("more than one component with the same name, should not happen")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on adding error structs for these errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added these, thanks

@feloy feloy requested review from valaparthvi and dharmit February 17, 2022 11:09
@valaparthvi
Copy link
Contributor

The tests pass, so approving it, and the code looks good for now.
/lgtm
/approve

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Feb 23, 2022
@openshift-ci
Copy link

openshift-ci bot commented Feb 23, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: valaparthvi

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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Feb 23, 2022
@feloy feloy force-pushed the without-devfile-adapters branch from 86536d5 to 9f5923c Compare February 23, 2022 07:39
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Feb 23, 2022
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
1.9% 1.9% Duplication

@valaparthvi
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Feb 23, 2022
@openshift-merge-robot openshift-merge-robot merged commit 0e4e55b into redhat-developer:main Feb 23, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
* Execute devfile command

* Undeploy

* cleanup devfile/adapters

* refactor

* Move GetOnePod to component package

* Move DoesComponentExist and Log from devfile/adapter to component package

* Exec without devfile/adapters

* Move Delete from devfile/adapters to component

* Remove old Deploy code

* review

* Add tests for issue 5454

* Review
@rm3l rm3l added the area/refactoring Issues or PRs related to code refactoring label Jun 16, 2023
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. area/refactoring Issues or PRs related to code refactoring 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.

Allow executing non-default deploy commands
5 participants