Skip to content

Fix changing host target port#2376

Merged
anshulpundir merged 1 commit into
moby:masterfrom
dperny:fix-changing-host-port
Dec 6, 2017
Merged

Fix changing host target port#2376
anshulpundir merged 1 commit into
moby:masterfrom
dperny:fix-changing-host-port

Conversation

@dperny
Copy link
Copy Markdown
Collaborator

@dperny dperny commented Sep 15, 2017

Fixes a bug where if a service has the same number of host-mode published ports with PublishedPort 0, changes to the spec would not reflect in the service object.

Also altered the unit tests to be more informative, and added a new unit test case for this bug.

@dperny
Copy link
Copy Markdown
Collaborator Author

dperny commented Sep 15, 2017

hey cool 2376 that's the default docker TLS port.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 15, 2017

Codecov Report

Merging #2376 into master will decrease coverage by 0.3%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           master    #2376      +/-   ##
==========================================
- Coverage   62.08%   61.78%   -0.31%     
==========================================
  Files          49      128      +79     
  Lines        6842    21114   +14272     
==========================================
+ Hits         4248    13045    +8797     
- Misses       2163     6663    +4500     
- Partials      431     1406     +975

Copy link
Copy Markdown

@fcrisciani fcrisciani left a comment

Choose a reason for hiding this comment

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

LGTM, agree that the logic looks a bit fuzzy, still not have super clear what was happening before like the isPortsAllocated was returning true so was not clearing the previous state?

portStates := allocatedPorts{}
hostTargetPorts := map[uint32]struct{}{}
for _, portState := range s.Endpoint.Ports {
if portState.PublishMode == api.PublishModeIngress {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

will it be nicer with a switch as below?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes it would

@@ -344,18 +353,28 @@ func (pa *portAllocator) isPortsAllocatedOnInit(s *api.Service, onInit bool) boo
// Iterate portConfigs with PublishedPort == 0 (low priority)
for _, portConfig := range s.Spec.Endpoint.Ports {
// Ignore ports which are not PublishModeIngress
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this needs to be removed I guess

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

i don't think so.

@dperny
Copy link
Copy Markdown
Collaborator Author

dperny commented Sep 17, 2017

Yeah my understanding is that every case where a port was added or removed caused an allocation. But if a port was added and a port was removed, there was no logic to handle that, because host ports changes are usually handled in a different function. But because this seemed more like the add/remove case than the host port changed case, I went with changing this function. Sorry if that's a little unspecific, I'm on mobile.

// a host port that's not in the service, then we need to do
// allocation. if we get the same target port but something else
// has changed, then HostPublishPortsNeedUpdate will cover that
// case. don't ask me why this is handled in two different code
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.

nit: @dperny can you add this as a TODO(dperny) or something so it's easy to search for later?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it's not really a TODO, it's just a comment. it's handled correctly in the other case i'm just explaining what it is. i'm adding "don't ask me" because i don't want someone to to a git blame in a year and ask my why this is the case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment should instead reference #2143.

@dperny dperny force-pushed the fix-changing-host-port branch from 071e07d to d5bb8bf Compare September 18, 2017 20:04
}
case api.PublishModeHost:
// check if the target port is already in the port config. if it
// is, then it's our problem.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this read "not our problem"?

@aaronlehmann
Copy link
Copy Markdown
Collaborator

Looks correct to me, but we should really fix #2143 once and for all.

@dperny dperny force-pushed the fix-changing-host-port branch from d5bb8bf to 1602055 Compare December 6, 2017 19:19
@dperny
Copy link
Copy Markdown
Collaborator Author

dperny commented Dec 6, 2017

apparently i'm the biggest idiot and forgot about the PR. thought it was already merged. i don't know what happened.

Fixes a bug where if a service has the same number of host-mode
published ports with PublishedPort 0, changes to the spec would not
reflect in the service object.

Signed-off-by: Drew Erny <drew.erny@docker.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants