Skip to content

Allow endpoints with the same targetPort if they are on the same container component #822

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

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

amisevsk
Copy link
Contributor

What does this PR do?:

Implements the suggested solution in #821 (comment), in particular:

  • Endpoints using the same targetPort are allowed again, provided all endpoints using that targetPort are on the same container component
  • Endpoints using the same targetPort on different containers return a validation error.

Documentation on endpoints and in validation-rule.md is updated to reflect this fact.

Note: this PR requires additional handling by tools that use endpoint names for containerPort names, as it's possible to generate invalid pod specs by not de-duplicating containerPorts -- cc: @kadel

Which issue(s) this PR fixes:

Closes #821

PR acceptance criteria:

Testing and documentation do not need to be complete in order for this PR to be approved. We just need to ensure tracking issues are opened.

  • Open new test/doc issues under the devfile/api repo
  • Check each criteria if:
  • There is a separate tracking issue. Add the issue link under the criteria
    or
  • test/doc updates are made as part of this PR
  • If unchecked, explain why it's not needed

How to test changes / Special notes to the reviewer:

@amisevsk amisevsk requested a review from kadel April 11, 2022 21:20
@amisevsk amisevsk changed the title Duplicated endpoints Allow endpoints with the same targetPort if they are on the same container component Apr 12, 2022
@@ -14,7 +14,8 @@ The validation will be done as part of schema validation, the rule will be intro

### Endpoints:
- all the endpoint names are unique across components
- all the endpoint ports are unique across components. Only exception: container component with `dedicatedpod=true`
- endpoint ports must be unique across components -- to components cannot have the same target port, but one component may have two endpoints with the same target port. This restriction does not apply to container components with `dedicatedPod` set to `true`.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: "to components..." should be "two 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.

Embarrassing! Fixed, thank you 😄

Allow multiple endpoints to have the same target point if and only if
they are attached to the same container. Otherwise, target ports must be
unique unless dedicatedPod is set to true.

Allowing multiple endpoints to use the same port is required for some
applications which require two routes to the same endpoint, in order to
create isolation between components within the browser.

Signed-off-by: Angel Misevski <[email protected]>
@elsony
Copy link
Contributor

elsony commented Apr 12, 2022

/lgtm
Note: We should wait for @kadel to confirm if that is ok for odo before merging

@openshift-ci openshift-ci bot added the lgtm label Apr 12, 2022
@@ -14,7 +14,8 @@ The validation will be done as part of schema validation, the rule will be intro

### Endpoints:
- all the endpoint names are unique across components
- all the endpoint ports are unique across components. Only exception: container component with `dedicatedpod=true`
- endpoint ports must be unique across components -- two components cannot have the same target port, but one component may have two endpoints with the same target port. This restriction does not apply to container components with `dedicatedPod` set to `true`.
Copy link
Member

Choose a reason for hiding this comment

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

If we allow the use of the same port on one container, why not allow the same ports on two different containers? Isn't basically the same situation as in most cases the containers will be in on Pod?

We don't need to block this PR on this.
We can revisit it in a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kubernetes won't allow multiple containerPorts within the same pod, so allowing the same port on different containers will result in the pod being rejected as invalid. For endpoints on the same container, only one containerPort is created (and only one service within the pod can listen on that port).

The endpoint defines more information than just the port. In particular, we use endpoints to define URL paths, protocols, and whether a route should be created. This results in multiple ingresses/routes that map to 1 or more services, that end up all pointing at one port in the container. An example would be something like

https://url1.com/path1 ───────────┐
                                  ▼
                           service port 8080 ──► container port 8080
                                  ▲
https://url2.com/path2 ───────────┘

Perhaps the ultimately better solution (requiring a new APIVersion) would be to extend endpoints to allow configuring something like this in one endpoint entry.

Copy link
Member

Choose a reason for hiding this comment

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

Kubernetes won't allow multiple containerPorts within the same pod, so allowing the same port on different containers will result in the pod being rejected as invalid. For endpoints on the same container, only one containerPort is created (and only one service within the pod can listen on that port).

oh, right.
In this case, we have quite a broken implementation of endpoints in devfile/library :-/
Currently, it maps every endpoint into the container port.
By re-introducing this change devfile/library will have to start doing smarter things with endpoints than just blindly mapping 1:1 to container ports.
/cc @elsony @yangcao77

I think that this is another proof of how badly we need a common layer that controls the basic principles of how Devfile is translated to k8s resources.
If we can't have it on code level in for of some shared library then at least we need to have documentation describing the ground rules of how devfile is translated to k8s resources. Otherwise, problems like this will keep coming.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I have aware that library need to make change accordingly. But library can still use the endpoint name, if multiple endpoints uses same port, library can use the first endpoint uses that port. Or Odo want to change back to the old behavior? all use port-<portNumber> instead?

@kadel
Copy link
Member

kadel commented Apr 13, 2022

/approve

@elsony
Copy link
Contributor

elsony commented Apr 14, 2022

/approve

@ibuziuk ibuziuk self-requested a review April 14, 2022 12:19
@openshift-ci
Copy link

openshift-ci bot commented Apr 14, 2022

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: amisevsk, elsony, ibuziuk, kadel

The full list of commands accepted by this bot can be found 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

@ibuziuk ibuziuk merged commit 32cae1f into devfile:main Apr 14, 2022
@amisevsk amisevsk deleted the duplicated-endpoints branch April 14, 2022 14:08
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Apr 14, 2022
Update devfile/api dependency to include changes from PR

devfile/api#822

Signed-off-by: Angel Misevski <[email protected]>
amisevsk added a commit to devfile/devworkspace-operator that referenced this pull request Apr 14, 2022
Update devfile/api dependency to include changes from PR

devfile/api#822

Signed-off-by: Angel Misevski <[email protected]>
amisevsk added a commit to amisevsk/devworkspace-operator that referenced this pull request Apr 14, 2022
Update devfile/api dependency to include changes from PR

devfile/api#822

Signed-off-by: Angel Misevski <[email protected]>
ibuziuk pushed a commit to devfile/devworkspace-operator that referenced this pull request Apr 14, 2022
* Update devfile/api dependency to fix validation of devworkspaces

Update devfile/api dependency to include changes from PR

devfile/api#822

Signed-off-by: Angel Misevski <[email protected]>

* Regenerate files for new devfile/api version

Signed-off-by: Angel Misevski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endpoint validation is stricter than it needs to be; breaks some use cases.
5 participants