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

make canary ingresses independent of the order they were applied #3525

Merged

Conversation

clandry94
Copy link

What this PR does / why we need it:
This PR fixes a problem with the canary ingress feature where canary ingresses depend on the order of which they were applied. It also adds a check that a canary ingress cannot be merged into the default upstream when no other ingresses have been applied.

To make canary ingresses order independent, the getBackendServers function first sets aside canary ingresses as it iterates across them. Then, after servers are created for every real ingress, the a check is done to make sure merging is safe and canary ingresses are iterated over and merged. The current condition for knowing if it is safe to merge canary ingresses is whether the length of ingresses - length of canary ingresses > 0 If true, we know that a real ingress must exist and there is a potential match which can be merged into. This is currently more of a sanity check than a condition for "safeness", but this function can be used to add more conditions for safeness if necessary.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 5, 2018
@@ -1115,8 +1123,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 safeToMergeCanaryIngresses(ingresses []*ingress.Ingress, canaryIngresses []*ingress.Ingress) bool {
return len(ingresses)-len(canaryIngresses) > 0
Copy link
Member

Choose a reason for hiding this comment

The 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 mergeAlternativeBackends function. I'd suggest to call this something like nonCanaryIngressExists


if safeToMergeCanaryIngresses(ingresses, canaryIngresses) {
for _, canaryIng := range canaryIngresses {
mergeAlternativeBackends(canaryIng, upstreams, servers)
Copy link
Member

@ElvinEfendi ElvinEfendi Dec 6, 2018

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.

Copy link
Author

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

@clandry94 clandry94 force-pushed the order_independence_canary_ann branch 2 times, most recently from 429bd99 to a63d81f Compare December 6, 2018 17:15
@clandry94
Copy link
Author

/assign @ElvinEfendi

@clandry94 clandry94 force-pushed the order_independence_canary_ann branch 10 times, most recently from ebff4f4 to 66bf543 Compare December 10, 2018 17:35
@clandry94 clandry94 force-pushed the order_independence_canary_ann branch from 66bf543 to d5840a4 Compare December 10, 2018 18:17
@ElvinEfendi
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 10, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: clandry94, ElvinEfendi

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2018
@k8s-ci-robot k8s-ci-robot merged commit 8ae01a2 into kubernetes:master Dec 10, 2018
@ElvinEfendi ElvinEfendi deleted the order_independence_canary_ann branch December 10, 2018 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants