-
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
Clean JSON before post request to update configuration #2365
Conversation
internal/ingress/controller/nginx.go
Outdated
copyOfPcfg := &ingress.Configuration{} | ||
|
||
mergo.Merge(copyOfRunningConfig, n.runningConfig) | ||
mergo.Merge(copyOfPcfg, pcfg) |
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.
is this safer? I'm curious why you switched to using mergo
.
dc43d30
to
8e3eab6
Compare
Codecov Report
@@ Coverage Diff @@
## master #2365 +/- ##
==========================================
+ Coverage 40.91% 41.19% +0.28%
==========================================
Files 74 74
Lines 5248 5263 +15
==========================================
+ Hits 2147 2168 +21
+ Misses 2809 2798 -11
- Partials 292 297 +5
Continue to review full report at Codecov.
|
// that is handled by Lua | ||
func (n *NGINXController) ConfigureDynamically(pcfg *ingress.Configuration) error { |
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.
why are you changing this?
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.
to be able to test it without creating a new NGINXController
instance.
Also removes an export we should not expose.
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.
to be able to test it without creating a new NGINXController instance.
Is this a big deal though? I'm already doing it at https://github.com/kubernetes/ingress-nginx/pull/2365/files#diff-b43320e0cdcbbb75b01313d88f637165L55 to test the other function.
Also removes an export we should not expose.
👍 for not exporting this function
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.
Is this a big deal though? I'
I just want to make sure we don't have targets in the endpoints. This is the biggest object in the json request
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.
I understand that, I was commenting on "to be able to test it without creating a new NGINXController instance." - it is a few lines of code to create a new NGINXController
instance in test.
internal/ingress/controller/nginx.go
Outdated
@@ -779,9 +787,8 @@ func (n *NGINXController) ConfigureDynamically(pcfg *ingress.Configuration) erro | |||
return err | |||
} | |||
|
|||
glog.V(2).Infof("posting backends configuration: %s", buf) | |||
glog.Infof("posting backends configuration: %s", buf) |
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.
This is gonna spam the logs with not so valuable information. It is important to see what's being posted only during debugging.
What do you think we should alway log without escalated logging level?
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.
change reverted
internal/ingress/controller/nginx.go
Outdated
copyOfPcfg := &ingress.Configuration{} | ||
|
||
mergo.MergeWithOverwrite(copyOfRunningConfig, n.runningConfig) | ||
mergo.MergeWithOverwrite(copyOfPcfg, pcfg) |
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.
is this safer? what was the issue with existing implementation?
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.
what was the issue with existing implementation?
No issue. We already use mergo for this kind of tasks
err := configureDynamically(commonConfig, ts.URL) | ||
if err != nil { | ||
t.Errorf("unexpected error posting dynamic configuration: %v", err) | ||
} |
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.
can you also assert that Target field has not changed for the endpoints defined at https://github.com/kubernetes/ingress-nginx/pull/2365/files#diff-b43320e0cdcbbb75b01313d88f637165R101?
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.
done
t.Fatal(err) | ||
} | ||
body := string(b) | ||
if strings.Index(body, "target") != -1 { |
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.
can we also assert that "service" does not exist?
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.
done
t.Errorf("unexpected target reference in JSON content: %v", body) | ||
} | ||
|
||
if strings.Index(body, "service") != -1 { |
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.
Could you include a dummy service object for the backend at https://github.com/kubernetes/ingress-nginx/pull/2365/files#diff-b43320e0cdcbbb75b01313d88f637165R99 as well? so that this assertion becomes more meaningful
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.
done
t.Errorf("unexpected error posting dynamic configuration: %v", err) | ||
} | ||
t.Logf("%v", commonConfig.Backends[0].Endpoints[0]) | ||
if commonConfig.Backends[0].Endpoints[0].Target == nil { |
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.
What about comparing this with its expected value &apiv1.ObjectReference{}
(from https://github.com/kubernetes/ingress-nginx/pull/2365/files#diff-b43320e0cdcbbb75b01313d88f637165R105) instead? IMHO that would be a complete check since it covers the case where target is being changed to something other than nil
err := n.ConfigureDynamically(&pcfg) | ||
|
||
url := fmt.Sprintf("http://localhost:%d/configuration/backends", n.cfg.ListenPorts.Status) | ||
err := configureDynamically(&pcfg, url) |
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.
I realize it makes testing easier but to me this feels counterintuitive for configureDynamically
to not know about the endpoint URL itself and get it from a caller.
I think there's still some flakiness at https://github.com/kubernetes/ingress-nginx/blob/master/test/e2e/lua/dynamic_configuration.go#L61, maybe bump it up to 5s in this PR? |
41cb034
to
5945b58
Compare
} | ||
if asslc1 == nil || assl2 == nil { | ||
return false | ||
} |
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.
Is this a no-op change or addressing an actual issue?
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.
addressing an actual issue?
Comparing a valid instance against null.
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.
Thanks! Loving to see more and more test coverage 😍
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aledbf, 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 |
I just ran into a situation where it would be very useful to have access to What was the reason for removing it? Any opinions on adding it back? Maybe in some kind of opt-in way. |
IIRC the only reason was to avoid unnecessarily polluting NGINX Lua shared memory space used to store the backend configuration. I see no issue with extracting pod name from target and including it as a metadata in the endpoints objects. That being said, neither Manuel nor me are maintainers anymore and the current team has decided to deprecate Lua and therefore does not seem to be accepting changes touching to Lua side: #11381 (comment) (I guess you can still make the PR as it likely does not dirtectly touch to Lua code anyway). |
What this PR does / why we need it:
Remove Target object reference from endpoints (this is not used for the dynamic configuration)