Skip to content

fix: no extra port mapping in main container when nlb target is a sidecar#3819

Merged
mergify[bot] merged 3 commits intoaws:mainlinefrom
Lou1415926:fix/nlb/sidecars/3768
Jul 27, 2022
Merged

fix: no extra port mapping in main container when nlb target is a sidecar#3819
mergify[bot] merged 3 commits intoaws:mainlinefrom
Lou1415926:fix/nlb/sidecars/3768

Conversation

@Lou1415926
Copy link
Copy Markdown
Contributor

Fix #3768

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@Lou1415926 Lou1415926 requested a review from a team as a code owner July 26, 2022 21:49
@Lou1415926 Lou1415926 requested review from efekarakus and removed request for a team July 26, 2022 21:49
Protocol: tcp
{{- end }}
{{- if .NLB}} {{ $nlbListener := .NLB.Listener }}
{{- if and (eq $nlbListener.TargetContainer .WorkloadName) (ne $nlbListener.TargetPort .NLB.MainContainerPort)}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:ack: this looks good, what about this feedback from the issue:

It appears that the cf partial below is not sidecar aware, and assumes that the nlb target is always the main workload container.

To me it sounded like the NLB target group is pointing to the wrong port?

Copy link
Copy Markdown
Contributor Author

@Lou1415926 Lou1415926 Jul 26, 2022

Choose a reason for hiding this comment

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

With a manifest like this:

nlb:
  port: 80/tcp
  target_container: envoy

image:
  location: blah
  port: 10000

sidecars:
  envoy:
    # envoy admin port
    port: 9901
    image: public.ecr.aws/hashicorp/envoy-alpine:latest

The NLB target group's target port will be 9901, not 10000, with the current implementation and as expected!

My understanding for the quoted comment was specifically for the code:

{{if ne .NLB.Listener.TargetPort .NLB.MainContainerPort}} {{/*No need to add additional port if the target port is the same as image port*/}}

The (bugged) code assume the target container is main container, and add the target port to main container's port mapping if it's not the same as the container port. It fails to take into consideration the possibility that the target container could be a sidecar, in which case, it does not need to add the extra port mapping to the main container.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, totally makes sense!

@mergify mergify Bot merged commit 3fbc49d into aws:mainline Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load Balanced Web Service: incompatibility when nlb and sidecars are used together

4 participants