Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Map "binding.ContainerPort" instead of "binding.Port" to "manifest containerPort" #740

Merged

Conversation

tebeco
Copy link
Contributor

@tebeco tebeco commented Oct 31, 2020

fixes #725

It seems that the manifest code was mapping binding.Port" to the field "containerPort" inthe KubernetesManifestGenerator`
As I have, for now, a limited understanding on that, There might be other underlying reason that I'm missing here

Adding back context from the Issue here for review:

From @jongio
#725 (comment)

Here's what I recommend:

If tye.yaml has containerPort, then use it for both containerPort in the deployment and targetPort in the service
If tye.yaml doesn't have containerPort, then use 80 for http and 443 for https for both containerPort and targetPort.

I personally do not see a scenario where containerPort or targetPort should be equal to port

@jkotalik to confirm the logic above, but @tebeco if you want to take a stab at updating to that, you are more than welcome to mod your PR.

This PR only covers HTTP scheme and not HTTPS due to the current absence of support yet for HTTPS :

                        if (binding.Protocol == "https")
                        {
                            // We skip https for now in deployment, because the E2E requires certificates
                            // and we haven't done those features yet.
                            continue;
                        }

What troubles me ?
tye.yaml seem to have the notion of port binding that seems to be used for local run when doing tye run
What happens when there's a port: 1111 specified but no containerPort ? Should it default to 80 ? or should it use the existing/defined port ?
eg:

name: foobar
services:
- name: thewebapione
  project: src/TheWebapiOne/TheWebapiOne.csproj
  bindings:
    - port: 1111
      protocol: http

This would feel like a dup to have to do:

name: foobar
services:
- name: thewebapione
  project: src/TheWebapiOne/TheWebapiOne.csproj
  bindings:
    - port: 1111
      protocol: http
      containerPort: 1111

@tebeco tebeco marked this pull request as draft October 31, 2020 16:27
@tebeco tebeco force-pushed the fix-containerport-mapping-in-manifest branch from 73cd50d to 814e9e6 Compare November 2, 2020 01:37
@tebeco tebeco marked this pull request as ready for review November 2, 2020 01:38
@tebeco tebeco force-pushed the fix-containerport-mapping-in-manifest branch from 814e9e6 to cf89725 Compare November 2, 2020 01:39
@jkotalik
Copy link
Contributor

jkotalik commented Nov 2, 2020

I think we prefer what you currently have, not defaulting to port 80. Could you clean that up and we'll verify.

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

done

}

Choose a reason for hiding this comment

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

nit: new line not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤨

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx, that will teach me to double check when editing directly from the portal :D
(Not on the head please)

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

What's the proper way to dig in this error ?
Download artifacts and open the html report ?

image

Copy link
Contributor

@jkotalik jkotalik left a comment

Choose a reason for hiding this comment

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

Modify CombineStep.cs line 41 to be:

                    var port = binding.ContainerPort ?? binding.Port ?? 80;

Currently, this will not work because the app will be listening on port 1111 instead of port 2222 in your example.

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

will do that right after dinner ;)
sorry about that

@jkotalik
Copy link
Contributor

jkotalik commented Nov 2, 2020

There should be a test view just above to view failures. https://dev.azure.com/dnceng/public/_build/results?buildId=873333&view=ms.vss-test-web.build-test-results-tab&runId=27940212&resultId=100012&paneView=debug. Looks like a flaky test though.

@jkotalik
Copy link
Contributor

jkotalik commented Nov 2, 2020

Will approve once that done!

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

can you enlight me about this ENV_VAR ?

project.EnvironmentVariables.Add(new EnvironmentVariableBuilder("PORT") { Value = port.ToString(CultureInfo.InvariantCulture), });

I saw it when i did tye generate but I'm not sure about the underlying reason of it as the ASPNETCORE_URLS already cover the http(s) port

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

I decided to lookup binding.Port accross the repo, and now I'm curious :D

Should I also change the annotation for DAPR ?
This code seems to be use "when it's NOT LOCAL" meaning probably after tye generate or tye deploy
https://github.com/dotnet/tye/blob/master/src/Microsoft.Tye.Extensions/Dapr/DaprExtension.cs#L193
image

@tebeco
Copy link
Contributor Author

tebeco commented Nov 2, 2020

To be honest I attempted to review all usage of BindingBuilder.Port` accross the repo, and I'm not 100% sure for each usage (yet) :(

@jkotalik
Copy link
Contributor

jkotalik commented Nov 2, 2020

I believe PORT is used in some applications as well (maybe by kestrel). I'd have to double check though.

@jkotalik jkotalik merged commit 5331046 into dotnet:master Nov 3, 2020
@tebeco tebeco deleted the fix-containerport-mapping-in-manifest branch November 3, 2020 00:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

containerPort contains port value
3 participants