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

Adds mapping support to odo link #5237

Merged
merged 13 commits into from
Dec 3, 2021
Merged

Adds mapping support to odo link #5237

merged 13 commits into from
Dec 3, 2021

Conversation

dharmit
Copy link
Member

@dharmit dharmit commented Nov 22, 2021

  • Sticking to SBO library v0.9.0 because the feature can be implemented
    using it just fine.
  • Docs doesn't cover --bind-as-files. I would prefer to keep it in a
    separate PR.
    --bind-as-files docs e8dfa50.
  • Added id field to the ServiceBinding resource created by odo and it
    defaults to same name as that of service's. No option to change the
    id itself.
  • Removed a hyphen from the redis.yaml file because it caused odo push for a link using the --map flag to fail due to it.

What type of PR is this?
/kind feature

What does this PR do / why we need it:
$subject. We need it for the users to be able to inject custom binding data while linking

Which issue(s) this PR fixes:

Fixes #4937

PR acceptance criteria:

How to test changes / Special notes to the reviewer:
Considering the backend component and postgres service from odo quickstart guide, try linking using:

$ odo link PostgresCluster/hippo --map pgVersion='{{ .database.spec.postgresVersion }}'
$ odo exec -- env | grep pgVersion

@netlify
Copy link

netlify bot commented Nov 22, 2021

✔️ Deploy Preview for odo-docusaurus-preview canceled.

🔨 Explore the source changes: 6b1a7dc

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

@dharmit
Copy link
Member Author

dharmit commented Nov 22, 2021

Sticking to SBO library v0.9.0 because the feature can be implemented using it just fine.

Another reason being that there are certain breaking changes which were taking longer to figure out. Refer discussion in this thread on Kubernetes Slack for more context.

@dharmit dharmit requested review from kadel, valaparthvi and feloy and removed request for mohammedzee1000 and anandrkskd November 22, 2021 12:27
sidebar_position: 4
---

`odo link` command helps link an odo component to an Operator backed service or another odo component. It does this by using [Service Binding Operator](https://github.com/redhat-developer/service-binding-operator). At the time of writing this, odo makes use of the Service Binding library and not the Operator itself to achieve the desired functionality.
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation is very detailed, and based on the quickstart project: I think it would be better to place it in the Using odo section, and have a more concise and generic doc as reference

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, while writing this, I had the thought of putting a concise form of it in the "Using odo" section. But can we do it separately?

Also, I think only this doc in "Command Reference" is based on Quickstart project. Which is not good. But I couldn't think of a better way to convey the point. Do you have any other idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see your point now. You are suggesting to add this document to the "Using odo" section. And in this section, we keep a concise document.

We will have to add the bits for linking backend and frontend component in that case. And also figure out what to keep in what doc. Doable. Let's do it.

pkg/odo/cli/component/common_link.go Outdated Show resolved Hide resolved
pkg/odo/cli/component/common_link.go Outdated Show resolved Hide resolved
pkg/odo/cli/component/common_link.go Outdated Show resolved Hide resolved
pkg/odo/util/cmdutils.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. labels Nov 26, 2021
@kadel
Copy link
Member

kadel commented Nov 26, 2021

I'm having some issues with keys referencing another types like for example

odo link PostgresCluster/hippo --map mydbname='path={.metadata.name}-pguser-{.metadata.name},objectType=Secret,sourceKey=dbname'

But I might be doing something wrong, or it might need newer SB version.
Simple values like mentioned in documentation worked for me, so we can figure out this in separate issue.

/approve

@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 Nov 26, 2021
@feloy
Copy link
Contributor

feloy commented Nov 26, 2021

@dharmit I'm not sure that removing the -app at the end of the name is what we want. I'm pretty sure that this appname was missing before, because of a bug, bug that disappeared with the refactoring

We can see the same thing in the integration tests: some tests are checking that the name of some file does not contain app inside it, but I'm pretty sure we wanted to have it. With the refacto, the appname is now here, and the tests are failing.

@dharmit
Copy link
Member Author

dharmit commented Nov 26, 2021

@feloy yeah, it's pretty annoying state that we are in right now. At the moment, the tests are failing (I'm checking locally as well against CRC) and here's the error message odo unlink prints if user tries to unlink something that isn't linked to it:

# from component directory of component A, link the component B
$ odo link compB
$ odo push

$ odo unlink compB
# try to unlink again
$ odo unlink compB
 ✗  failed to unlink the component "compB-app" since no link was found in the configuration referring this component

Expected error message is:

$ odo unlink compB
 ✗  failed to unlink the component "compB" since no link was found in the configuration referring this component

Now that we have modified o.serviceName to be the name of the Kubernetes Service belonging to the component, things are failing elsewhere. 😕

@dharmit
Copy link
Member Author

dharmit commented Nov 26, 2021

One way to handle this better could be to introduce an element in the commonLinkOptions struct. I can't think of a better way at the moment.

@dharmit
Copy link
Member Author

dharmit commented Nov 29, 2021

[ssh:Fedora-32-minikube] [odo]  ✓  Deleted link "link-dmwnmv" on the cluster; component will be restarted
[ssh:Fedora-32-minikube] [odo]  •  Restarting the component  ...
[ssh:Fedora-32-minikube] [odo]  ✗  Restarting the component [1m]
[ssh:Fedora-32-minikube] [odo]  ✗  Failed to start component with name "qjma". Error: Failed to create the component: timeout while waiting for "qjma-app-6785b7ff9f-mzzx7" pod to be deleted
[ssh:Fedora-32-minikube] Running odo with args [odo service delete Redis/flcqck -f]
[ssh:Fedora-32-minikube] Deleting project: cmd-service-test480dff 

/test psi-kubernetes-integration-e2e

@feloy
Copy link
Contributor

feloy commented Nov 29, 2021

/lgtm

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

/retest-required

Please review the full test history for this PR and help us cut down flakes.

7 similar comments
@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest-required

Please review the full test history for this PR and help us cut down flakes.

- Sticking to SBO library v0.9.0 because the feature can be implemented
  using it just fine.
- Docs doesn't cover `--bind-as-files`. I would prefer to keep it in a
  separate PR.
- Added `id` field to the ServiceBinding resource created by odo and it
  defaults to same name as that of service's. No option to change the
  `id` itself.
- Removed a hyphen from the `redis.yaml` file because it caused `odo
  push` for a link using the `--map` flag to fail due to it.
Although the error raised talks only about the requirement to have
Operator Hub for linking services, I observed this error when doing `odo
unlink`. However, since odo supports creation/deletion of links using
Service Binding library and shouldn't really need Operator Hub installed
to do that operation, I removed this check.
SplitN helps split string into specific number of parts. Using it would
help support parameters that have `=` in their value.
This hack is required because we moved a bunch of code for creation of
the service binding resource (`o.serviceBinding`) from `validate`
function to `complete` function. As a result, if the target is not an
Operator backed service, `o.serviceName` is being set to the name of the
Kubernetes Service of a component which is of the form
`<component-name>-<application-name>`.

This hack is not done to fix something pointed by the tests. I observed
that the filename of the file created under `kubernetes/` directory
changed from `odo-service-frontend-backend.yaml` to
`odo-service-frontend-backend-app.yaml`. This hack removes the `app`
part in the name.
Removes the "ugly" hack added in a previous commit and basis the error
message for 'unlink' operation on whether the user is trying to unlink
from a service or a component.
@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

OpenShift Tests finished.
View logs: TXT HTML

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

Kubernetes Tests finished.
View logs: TXT HTML

@dharmit
Copy link
Member Author

dharmit commented Dec 2, 2021

SSSSSSSSSSSSSSSSSSSSSSSSSSSS
Ran 19 of 48 Specs in 1394.911 seconds
SUCCESS! -- 19 Passed | 0 Failed | 0 Pending | 29 Skipped
PASS | FOCUSED

Ginkgo ran 1 suite in 23m19.346800807s
Test Suite Passed
Detected Programmatic Focus - setting exit status to 197

$ git diff --unified=0
diff --git a/tests/integration/cmd_link_unlink_test.go b/tests/integration/cmd_link_unlink_test.go
index a34b853e2..f01afceba 100644
--- a/tests/integration/cmd_link_unlink_test.go
+++ b/tests/integration/cmd_link_unlink_test.go
@@ -87 +87 @@ var _ = Describe("odo link and unlink command tests", func() {
-               When("a link is created between the two components", func() {
+               FWhen("a link is created between the two components", func() {
@@ -157 +157 @@ var _ = Describe("odo link and unlink command tests", func() {
-               When("a link is created between the two components with --bind-as-files", func() {
+               FWhen("a link is created between the two components with --bind-as-files", func() {

Amending to re-trigger the tests
@openshift-ci
Copy link

openshift-ci bot commented Dec 2, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kadel

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

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

Kubernetes Tests finished.
View logs: TXT HTML

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

Unit Tests finished.
View logs: TXT HTML

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

OpenShift Tests finished.
View logs: TXT HTML

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

/lgtm

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

feloy commented Dec 2, 2021

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

/test psi-kubernetes-integration-e2e

[Fail] odo service command tests for OperatorHub Operators are installed in the cluster a specific operator is installed when a nodejs component is created when a Redis instance is created with a specific name when odo push is executed when a link is created with a specific name and bind-as-files flag [BeforeEach] should create a link with bindAsFiles set to true 

@feloy
Copy link
Contributor

feloy commented Dec 2, 2021

/test psi-kubernetes-integration-e2e

{"component":"entrypoint","file":"prow/entrypoint/run.go:165","func":"k8s.io/test-infra/prow/entrypoint.Options.ExecuteProcess","level":"error","msg":"Process did not finish before 4h0m0s timeout","severity":"error","time":"2021-12-02T17:54:39Z"}

@dharmit
Copy link
Member Author

dharmit commented Dec 3, 2021

/test psi-kubernetes-integration-e2e

Tests timed out after 4h! 🤯

{"component":"entrypoint","file":"prow/entrypoint/run.go:165","func":"k8s.io/test-infra/prow/entrypoint.Options.ExecuteProcess","level":"error","msg":"Process did not finish before 4h0m0s timeout","severity":"error","time":"2021-12-02T22:19:43Z"} 

@dharmit dharmit added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Dec 3, 2021
@feloy feloy merged commit cb4a4e9 into redhat-developer:main Dec 3, 2021
@dharmit dharmit deleted the mappings branch December 3, 2021 07:25
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 link: custom mappings
4 participants