-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
make canary ingresses independent of the order they were applied #3525
Merged
k8s-ci-robot
merged 1 commit into
kubernetes:master
from
Shopify:order_independence_canary_ann
Dec 10, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,6 +389,8 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in | |
upstreams := n.createUpstreams(ingresses, du) | ||
servers := n.createServers(ingresses, upstreams, du) | ||
|
||
var canaryIngresses []*ingress.Ingress | ||
|
||
for _, ing := range ingresses { | ||
ingKey := k8s.MetaNamespaceKey(ing) | ||
anns := ing.ParsedAnnotations | ||
|
@@ -561,9 +563,15 @@ func (n *NGINXController) getBackendServers(ingresses []*ingress.Ingress) ([]*in | |
} | ||
} | ||
|
||
// set aside canary ingresses to merge later | ||
if anns.Canary.Enabled { | ||
klog.Infof("Canary ingress %v detected. Finding eligible backends to merge into.", ing.Name) | ||
mergeAlternativeBackends(ing, upstreams, servers) | ||
canaryIngresses = append(canaryIngresses, ing) | ||
} | ||
} | ||
|
||
if nonCanaryIngressExists(ingresses, canaryIngresses) { | ||
for _, canaryIng := range canaryIngresses { | ||
mergeAlternativeBackends(canaryIng, upstreams, servers) | ||
} | ||
} | ||
|
||
|
@@ -1127,8 +1135,17 @@ func (n *NGINXController) createServers(data []*ingress.Ingress, | |
return servers | ||
} | ||
|
||
// OK to merge canary ingresses iff there exists one or more ingresses to potentially merge into | ||
func nonCanaryIngressExists(ingresses []*ingress.Ingress, canaryIngresses []*ingress.Ingress) bool { | ||
return len(ingresses)-len(canaryIngresses) > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this is a bit confusing because main safety is being done in |
||
} | ||
|
||
// ensure that the following conditions are met | ||
// 1) names of backends do not match and canary doesn't merge into itself | ||
// 2) primary name is not the default upstream | ||
// 3) the primary has a server | ||
func canMergeBackend(primary *ingress.Backend, alternative *ingress.Backend) bool { | ||
return primary.Name != alternative.Name && !primary.NoServer | ||
return primary.Name != alternative.Name && primary.Name != defUpstreamName && !primary.NoServer | ||
} | ||
|
||
// Performs the merge action and checks to ensure that one two alternative backends do not merge into each other | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is done before we set https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#default-backend, canary feature won't work when the main backend has no endpoints and Nginx is proxying to custom default backend. IMO this is an expected behaviour. Not the concern of this PR but it would be nice to have an e2e test case where main ingress's backend has no endpoints (replicas: 0) and assert that all requests return 503 regardless of canary cookie/header being set to
always
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I'll add an e2e for this