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

sample-app: Fix port of node-server-svc (80 to 8080) #6204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

guzalv
Copy link

@guzalv guzalv commented Jan 24, 2025

Without this, following the instructions that don't require port forwarding (e.g. using "minikube tunnel") fails: the service is exposed on port 80, which is not what the frontend expects.

After this commit the setup mimics that of the frontend service, which works both with and without port forwarding.

Without this, following the instructions that don't require port
forwarding (e.g. using "minikube tunnel") fails: the service is exposed
on port 80, which is not what the frontend expects.

After this commit the setup mimics that of the frontend service, which
works both with and without port forwarding.

Signed-off-by: Guzman <[email protected]>
@knative-prow knative-prow bot requested review from csantanapr and nainaz January 24, 2025 17:05
@knative-prow knative-prow bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 24, 2025
Copy link

netlify bot commented Jan 24, 2025

Deploy Preview for knative ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit bbbd4e2
🔍 Latest deploy log https://app.netlify.com/sites/knative/deploys/67952479da8b410008b58917
😎 Deploy Preview https://deploy-preview-6204--knative.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

This is needed because the node-server service listens on port 8080, and
the K8s ref resolver doesn't support custom ports [1], and referring to
the node-server-svc service yields:

  http://node-server-svc.default.svc.cluster.local/insert

Instead of the correct URL:

  http://node-server-svc.default.svc.cluster.local:8080/insert

Which results in hanging connections and eventually timeouts when adding
new comments that pass the trigger's filter.

[1] https://github.com/knative/pkg/blob/dcf159339de2fec9dde678a04cb7a354e912d2bf/resolver/addressable_resolver.go#L227

Signed-off-by: Guzman <[email protected]>
@knative-prow knative-prow bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 25, 2025
@guzalv
Copy link
Author

guzalv commented Jan 25, 2025

Hi,

When I reached step 6 of the sample app tutorial I noticed that the event never reached the subscriber (node-server service).

If I understand correctly, this is because when the subscriber's destination is a reference to a service, the resolver assumes it listens on port 80, i.e. it doesn't consider the "port" part of the hostname.

I lack experience to fully understand how this is supposed to work. Should I open an issue in pkg/ to handle this kind of situation? or, am I going in the wrong direction?

Thanks!

@dprotaso
Copy link
Member

/assign @Leo6Leo @Cali0707 who authored the sample-app tutorial

@Cali0707
Copy link
Member

cc @Leo6Leo

Could you recreate the problem reported here, does this fix it?

Copy link
Member

@Leo6Leo Leo6Leo left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Please see the comments and let me know if you have any questions.

kind: Service
name: node-server-svc
uri: /insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
uri: http://node-server-svc.default.svc.cluster.local:8080/insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
Copy link
Member

Choose a reason for hiding this comment

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

Here we would still prefer using the ref instead of hardcoding the uri, as the uri might get changed based on the environment. The original yaml file without this change should work as expected.

Copy link
Author

Choose a reason for hiding this comment

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

I agree the ref looks much nicer. However this is the only way I could make it work, see this explanation: #6204 (comment)

I just tried it out again just in case and observed the same behavior:
Screenshot 2025-02-04 at 11 43 53

I think the ref is cleaner and the proper way to do this, but it seems to me that this method lacks support to discover the service port. And since it now is 8080 rather than the default 80, the event never reaches the node server.

kind: Service
name: node-server-svc
uri: /insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
uri: http://node-server-svc.default.svc.cluster.local:8080/insert # This is the path where the event will be sent to the subscriber, see /insert in node-server code: index.js
Copy link
Member

Choose a reason for hiding this comment

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

Here we would still prefer using the ref instead of hardcoding the uri, as the uri might get changed based on the environment. The original yaml file without this change should work as expected.

@@ -29,6 +29,6 @@ spec:
app: node-server
ports:
- protocol: TCP
port: 80
port: 8080
Copy link
Member

Choose a reason for hiding this comment

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

Could you also update the /solution/node-server/config/100-deployment.yaml file? @guzalv

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, done

Copy link

knative-prow bot commented Feb 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: guzalv
Once this PR has been reviewed and has the lgtm label, please assign leo6leo for approval. For more information see the Code Review Process.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants