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

Fix issue with variables not substituted in uri-referenced manifests (#5451) #5711

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented May 2, 2022

What type of PR is this:
/kind bug

What does this PR do / why we need it:

This fixes the issue reported in #5451, where running odo deploy (actually any commands calling libdevfile.GetK8sComponentAsUnstructured) using a Devfile containing uri-referenced manifests containing variables would not succeed, either with a YAML validation error message similar to the line below or with an error (e.g., unresolvable image name) in the manifest once deployed in the cluster:

error converting YAML to JSON: yaml: invalid map key: map[interface {}]interface {}{"appname":interface {}(nil)}

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

PR acceptance criteria:

  • Unit test

  • Integration test

  • Documentation

How to test changes / Special notes to the reviewer:
Refer to the reproduction steps depicted in the original issue for testing this: #5451

From the code perspective, as discussed during one of the Sprint Plannings, this PR is enriching the libdevfile package with a new GetK8sManifestWithVariablesSubstituted function that is responsible for returning the resource manifest from the Kubernetes/OpenShift Devfile component with all variables substituted, rather than having libdevfile.GetK8sComponentAsUnstructured (and few other places in the codebase) fetch the raw manifest from the URI and handle it as is.
Also, the implementation aims at leaving room for supporting OpenShift components in a near future (scope of #5704).

Since this seems a much more realistic scenario of how outer-loop manifests are referenced in Devfiles, this PR also switches to uri references in all test Devfiles. This is the purpose of df1f19e
Note that tests for odo deploy still test both inlined (as before) and uri manifests (scope of this issue).
[Will be covered in a separate PR]

@rm3l rm3l requested review from dharmit, feloy and valaparthvi May 2, 2022 15:42
@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label May 2, 2022
@netlify
Copy link

netlify bot commented May 2, 2022

Deploy Preview for odo-docusaurus-preview canceled.

Name Link
🔨 Latest commit 614bc60
🔍 Latest deploy log https://app.netlify.com/sites/odo-docusaurus-preview/deploys/62738081a1a9880008a3189a

@odo-robot
Copy link

odo-robot bot commented May 2, 2022

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

@odo-robot
Copy link

odo-robot bot commented May 2, 2022

Windows Tests (OCP) on commit 98d19f6 finished successfully.
View logs: TXT HTML

@odo-robot
Copy link

odo-robot bot commented May 2, 2022

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

@odo-robot
Copy link

odo-robot bot commented May 2, 2022

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

@odo-robot
Copy link

odo-robot bot commented May 2, 2022

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

pkg/libdevfile/libdevfile.go Outdated Show resolved Hide resolved
tests/integration/devfile/cmd_devfile_build_images_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@feloy feloy left a comment

Choose a reason for hiding this comment

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

You have moved devfile from using Inlined to using URI as discussed during issue preparation. Are there some remaining devfile using Inlined? I would not like we make regressions on this now :(

pkg/libdevfile/errors.go Outdated Show resolved Hide resolved
@rm3l
Copy link
Member Author

rm3l commented May 3, 2022

You have moved devfile from using Inlined to using URI as discussed during issue preparation. Are there some remaining devfile using Inlined? I would not like we make regressions on this now :(

I identified the following places:

I was also hesitant on changing this in this PR. That's why the commit is isolated if we want to revert or do this change in a separate issue/PR.

Ideally, I think we should come up with a way to easily reuse the same tests against both Inlined and URI-referenced manifests. This is what I tried to accomplish with this loop in cmd_devfile_deploy_test.go.

@rm3l rm3l requested a review from feloy May 4, 2022 06:57
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label May 4, 2022
@rm3l rm3l changed the title Fix issue with variable substitution not occurring in uri-referenced manifests (#5451) Fix issue with variables not substituted in uri-referenced manifests (#5451) May 4, 2022
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label May 4, 2022
@rm3l
Copy link
Member Author

rm3l commented May 4, 2022

You have moved devfile from using Inlined to using URI as discussed during issue preparation. Are there some remaining devfile using Inlined? I would not like we make regressions on this now :(

I identified the following places:

I was also hesitant on changing this in this PR. That's why the commit is isolated if we want to revert or do this change in a separate issue/PR.

Ideally, I think we should come up with a way to easily reuse the same tests against both Inlined and URI-referenced manifests. This is what I tried to accomplish with this loop in cmd_devfile_deploy_test.go.

To be safe, I just reverted that commit from this PR, but saved it to a separate branch, and will try to include it in a dedicated PR later on.

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

feloy commented May 5, 2022

/approve

@openshift-ci
Copy link

openshift-ci bot commented May 5, 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 May 5, 2022
rm3l added 5 commits May 5, 2022 09:44
The devfile used is the same as devfile-deploy.yaml,
except that the the Kubernetes component is referenced via the URI.
This is why the same integration test logic is being reused here.
…resource manifest and substitute variables

This works with both Inlined or Uri resources.

Notes:
- Ideally, it would make more sense to rely on the same logic used in Devfile to
  substitute variables (defined in the 'variables' package),
  but this function is not exported;
  and the exported ones substitute variables only in the URI name,
  not in the content itself (it is not fetched),
  which is actually the issue we are trying to solve here.
This seems to be a much more realistic case when referencing external
Kubernetes manifests.

Notes:
Some tests, like for `odo deploy`, still test 'Inlined' manifests.
…riablesResolved'

As suggested in review, this makes more sense
now that we are passing the entire devfile object
…h 'GetK8sManifestWithVariablesSubstituted'

Previous name was a bit long ^^
rm3l added 2 commits May 5, 2022 09:44
This reverts commit df1f19e.

This will be done in a separate PR, with ideally
changes that should allow to use the same set of
tests for testing both Inlined and
URI-referenced manifests.
@rm3l rm3l force-pushed the 5451-odo-deploy-devfile-variable-substitution-does-not-occur-in-uri-referenced-deployment-manifest-yaml-file branch from 9d78b5c to 614bc60 Compare May 5, 2022 07:45
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label May 5, 2022
@rm3l
Copy link
Member Author

rm3l commented May 5, 2022

Just rebased onto main to benefit from #5712, which fixed the tests.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 5, 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 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rm3l rm3l requested a review from feloy May 5, 2022 08:49
@feloy
Copy link
Contributor

feloy commented May 5, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label May 5, 2022
@rm3l
Copy link
Member Author

rm3l commented May 5, 2022

/override ci/prow/v4.10-integration-e2e

Looks like a problem not related to this PR, but related to the deprovisioning job that tears down the cluster on Prow:

  • could not run steps: step integration-e2e failed: "integration-e2e" post steps failed: "integration-e2e" pod "integration-e2e-ipi-deprovision-deprovision" failed: the pod ci-op-kzni8cn5/integration-e2e-ipi-deprovision-deprovision was deleted without completing after 4m50s (failed containers: )

All tests passed on IBM Cloud by the way.

@openshift-ci
Copy link

openshift-ci bot commented May 5, 2022

@rm3l: Overrode contexts on behalf of rm3l: ci/prow/v4.10-integration-e2e

In response to this:

/override ci/prow/v4.10-integration-e2e

Looks like a problem not related to this PR, but related to the deprovisioning job that tears down the cluster on Prow:

  • could not run steps: step integration-e2e failed: "integration-e2e" post steps failed: "integration-e2e" pod "integration-e2e-ipi-deprovision-deprovision" failed: the pod ci-op-kzni8cn5/integration-e2e-ipi-deprovision-deprovision was deleted without completing after 4m50s (failed containers: )

All tests passed on IBM Cloud by the way.

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 7c7e607 into redhat-developer:main May 5, 2022
cdrage pushed a commit to cdrage/odo that referenced this pull request Aug 31, 2022
redhat-developer#5451) (redhat-developer#5711)

* Add integration test highlighting the issue

The devfile used is the same as devfile-deploy.yaml,
except that the the Kubernetes component is referenced via the URI.
This is why the same integration test logic is being reused here.

* Add higher-level function in 'libdevfile' allowing to load component resource manifest and substitute variables

This works with both Inlined or Uri resources.

Notes:
- Ideally, it would make more sense to rely on the same logic used in Devfile to
  substitute variables (defined in the 'variables' package),
  but this function is not exported;
  and the exported ones substitute variables only in the URI name,
  not in the content itself (it is not fetched),
  which is actually the issue we are trying to solve here.

* Switch to using 'uri' Kubernetes components in test Devfiles

This seems to be a much more realistic case when referencing external
Kubernetes manifests.

Notes:
Some tests, like for `odo deploy`, still test 'Inlined' manifests.

* Pass the component name to 'GetComponentResourceManifestContentWithVariablesResolved'

As suggested in review, this makes more sense
now that we are passing the entire devfile object

* Rename 'GetComponentResourceManifestContentWithVariablesResolved' with 'GetK8sManifestWithVariablesSubstituted'

Previous name was a bit long ^^

* Remove extra parentheses in error string returned by 'ComponentsWithSameNameError#Error', as suggested in review

* Revert "Switch to using 'uri' Kubernetes components in test Devfiles"

This reverts commit df1f19e.

This will be done in a separate PR, with ideally
changes that should allow to use the same set of
tests for testing both Inlined and
URI-referenced manifests.
@rm3l rm3l deleted the 5451-odo-deploy-devfile-variable-substitution-does-not-occur-in-uri-referenced-deployment-manifest-yaml-file branch December 1, 2022 16:35
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/bug Categorizes issue or PR as related to a bug. 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 deploy - devfile variable substitution does not occur in uri referenced deployment manifest yaml file
3 participants