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 odo work if optional metadata.name field is missing in Devfile #6015

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Aug 9, 2022

What type of PR is this:
/kind feature

What does this PR do / why we need it:

Which issue(s) this PR fixes:
Fixes #5821

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Aug 9, 2022
@openshift-ci
Copy link

openshift-ci bot commented Aug 9, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci bot added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Aug 9, 2022
@netlify
Copy link

netlify bot commented Aug 9, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit 3aa7bc0
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/630d217cf8f7260008a163db

@rm3l
Copy link
Member Author

rm3l commented Aug 9, 2022

/hold

Builds upon #5989 (first commit), so waiting for it to be merged in first.
Note: remove the first commit from this branch after #5989 is merged (and upon rebasing onto main)

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. label Aug 9, 2022
@odo-robot
Copy link

odo-robot bot commented Aug 9, 2022

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

@odo-robot
Copy link

odo-robot bot commented Aug 9, 2022

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

@odo-robot
Copy link

odo-robot bot commented Aug 9, 2022

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

@odo-robot
Copy link

odo-robot bot commented Aug 9, 2022

Kubernetes Tests on commit fcac29b finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented Aug 9, 2022

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

@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from 3d40ab8 to 71cad0c Compare August 10, 2022 08:10
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 11, 2022
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from 71cad0c to 1d64567 Compare August 11, 2022 14:37
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 11, 2022
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from 1d64567 to 3b99e67 Compare August 16, 2022 08:09
@rm3l rm3l mentioned this pull request Aug 16, 2022
3 tasks
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch 4 times, most recently from 2dc0119 to b2478e6 Compare August 16, 2022 15:35
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 18, 2022
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from b2478e6 to 16a2835 Compare August 26, 2022 10:01
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Aug 26, 2022
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch 3 times, most recently from bf58a7c to b8f9079 Compare August 26, 2022 14:58
@rm3l rm3l changed the title [WIP] Make odo work if optional metadata.name field is missing in Devfile Make odo work if optional metadata.name field is missing in Devfile Aug 26, 2022
@rm3l
Copy link
Member Author

rm3l commented Aug 26, 2022

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. Required by Prow. label Aug 26, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Aug 26, 2022
@openshift-ci openshift-ci bot requested review from dharmit and feloy August 26, 2022 15:31
@rm3l
Copy link
Member Author

rm3l commented Aug 26, 2022

/test unit-and-validate-test
/test v4.10-integration-e2e

@rm3l
Copy link
Member Author

rm3l commented Aug 28, 2022

The devfile "a-devfile-name" from the registry "a-registry" will be downloaded.
Based on the files in the current directory odo detected
Language: 
Project type: 
The devfile "" from the registry "" will be downloaded.
--- FAIL: TestInteractiveBackend_PersonalizeName (0.22s)
    --- FAIL: TestInteractiveBackend_PersonalizeName/no_flag (0.22s)
        controller.go:137: missing call(s) to *asker.MockAsker.AskName(is anything) /go/src/github.com/redhat-developer/odo/pkg/init/backend/interactive_test.go:223
        controller.go:137: aborting test due to missing call(s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x258d712]

/test unit-and-validate-test

pkg/binding/add.go Outdated Show resolved Hide resolved
rm3l added a commit to rm3l/odo that referenced this pull request Aug 29, 2022
…file metadata name

Compute and store the component name in the CLI context, and pass it as needed

As commented out in [1], the context should ideally be built
and passed down to the business clients structs.

[1] redhat-developer#6015 (comment)
@rm3l rm3l requested a review from feloy August 29, 2022 09:48
rm3l added a commit to rm3l/odo that referenced this pull request Aug 29, 2022
…as needed

As commented out in [1], the context should ideally be built
and passed down to the business clients structs.

[1] redhat-developer#6015 (comment)
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from 3f7ef4d to cf27963 Compare August 29, 2022 15:47
@feloy
Copy link
Contributor

feloy commented Aug 29, 2022

/approve

@openshift-ci
Copy link

openshift-ci bot commented Aug 29, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feloy

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 Aug 29, 2022
Functions in this file are only called from the 'registry' package,
so it makes sense for this file to belong to this package.

Furthermore, this paves the way to calling 'alizer.DetectName' from 'component.go',
thus avoiding a cyclic dependency between packages.
…nent/component.go'

This rewrites the 'component#GatherName' function that was already there,
but not used, to meet the expectations, i.e.:

- use 'metadata.name' field (after sanitizing it) if it is defined in the Devfile
- otherwise, use Alizer to detect the name. Under the hood, this leverages the 'alizer#DetectName' introduced in 83ad3ee, which means that:
-- use Alizer to detect the name automatically
-- otherwise, use the name of the Devfile base directory after sanitizing it
…as needed

As commented out in [1], the context should ideally be built
and passed down to the business clients structs.

[1] redhat-developer#6015 (comment)
For the sake of both performance and readability,
only the tests that break in the absence of a 'metadata.name'
field in their Devfiles have been updated (to test this specific case).
…d with no 'metadata.name' in the Devfile

The rationale behind this is to purposely make
the Alizer library unable to detect the project.
Per the requirements, this would force us to use the project
directory name as component name.

This highlights an interesting behavior if the project
directory name is all-numeric (as is the case in our tests);
our sanitization logic automatically prepends an "x" prefix
to the directory name, so it can be used as a valid name
for the component.
@rm3l rm3l force-pushed the 5821-odo-should-not-require-metadata.name-in-devfile branch from cf27963 to 3aa7bc0 Compare August 29, 2022 20:28
@sonarcloud
Copy link

sonarcloud bot commented Aug 29, 2022

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 6 Code Smells

No Coverage information No Coverage information
1.5% 1.5% Duplication

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

feloy commented Aug 30, 2022

/override ci/prow/unit-and-validate-test
/override ci/prow/v4.10-integration-e2e
Tests pass on IBM Cloud

@openshift-ci
Copy link

openshift-ci bot commented Aug 30, 2022

@feloy: Overrode contexts on behalf of feloy: ci/prow/unit-and-validate-test, ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/unit-and-validate-test
/override ci/prow/v4.10-integration-e2e
Tests pass on IBM Cloud

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot merged commit 843717c into redhat-developer:main Aug 30, 2022
@rm3l rm3l deleted the 5821-odo-should-not-require-metadata.name-in-devfile branch August 30, 2022 06:54
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
…redhat-developer#6015)

* Move 'starter_project.go' from 'pkg/component' to 'pkg/registry'

Functions in this file are only called from the 'registry' package,
so it makes sense for this file to belong to this package.

Furthermore, this paves the way to calling 'alizer.DetectName' from 'component.go',
thus avoiding a cyclic dependency between packages.

* Introduce central logic for determining component names in 'pkg/component/component.go'

This rewrites the 'component#GatherName' function that was already there,
but not used, to meet the expectations, i.e.:

- use 'metadata.name' field (after sanitizing it) if it is defined in the Devfile
- otherwise, use Alizer to detect the name. Under the hood, this leverages the 'alizer#DetectName' introduced in 83ad3ee, which means that:
-- use Alizer to detect the name automatically
-- otherwise, use the name of the Devfile base directory after sanitizing it

* Compute and store the component name in the CLI context, and pass it as needed

As commented out in [1], the context should ideally be built
and passed down to the business clients structs.

[1] redhat-developer#6015 (comment)

* Enrich relevant integration test cases

For the sake of both performance and readability,
only the tests that break in the absence of a 'metadata.name'
field in their Devfiles have been updated (to test this specific case).

* Add test case for 'odo dev' when a project with no source code is used with no 'metadata.name' in the Devfile

The rationale behind this is to purposely make
the Alizer library unable to detect the project.
Per the requirements, this would force us to use the project
directory name as component name.

This highlights an interesting behavior if the project
directory name is all-numeric (as is the case in our tests);
our sanitization logic automatically prepends an "x" prefix
to the directory name, so it can be used as a valid name
for the component.
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. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation 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.

odo should not require metadata.name in devfile
3 participants