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

Clean JSON before post request to update configuration #2365

Merged
merged 1 commit into from
Apr 26, 2018

Conversation

aledbf
Copy link
Member

@aledbf aledbf commented Apr 17, 2018

What this PR does / why we need it:

Remove Target object reference from endpoints (this is not used for the dynamic configuration)

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 17, 2018
copyOfPcfg := &ingress.Configuration{}

mergo.Merge(copyOfRunningConfig, n.runningConfig)
mergo.Merge(copyOfPcfg, pcfg)
Copy link
Member

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.

@aledbf aledbf force-pushed the clean-json branch 2 times, most recently from dc43d30 to 8e3eab6 Compare April 24, 2018 19:16
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 24, 2018
@codecov-io
Copy link

codecov-io commented Apr 24, 2018

Codecov Report

Merging #2365 into master will increase coverage by 0.28%.
The diff coverage is 55.55%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
internal/ingress/controller/controller.go 2.23% <0%> (-0.02%) ⬇️
internal/ingress/controller/nginx.go 9.76% <100%> (+4.65%) ⬆️
internal/file/filesystem.go 40.98% <0%> (-0.4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bad526b...c6728aa. Read the comment docs.

// that is handled by Lua
func (n *NGINXController) ConfigureDynamically(pcfg *ingress.Configuration) error {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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.

@@ -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)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

change reverted

copyOfPcfg := &ingress.Configuration{}

mergo.MergeWithOverwrite(copyOfRunningConfig, n.runningConfig)
mergo.MergeWithOverwrite(copyOfPcfg, pcfg)
Copy link
Member

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?

Copy link
Member Author

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)
}
Copy link
Member

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?

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 25, 2018
t.Errorf("unexpected target reference in JSON content: %v", body)
}

if strings.Index(body, "service") != -1 {
Copy link
Member

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

Copy link
Member Author

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 {
Copy link
Member

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)
Copy link
Member

@ElvinEfendi ElvinEfendi Apr 25, 2018

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.

@ElvinEfendi
Copy link
Member

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?

@aledbf aledbf force-pushed the clean-json branch 8 times, most recently from 41cb034 to 5945b58 Compare April 26, 2018 18:14
}
if asslc1 == nil || assl2 == nil {
return false
}
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@ElvinEfendi ElvinEfendi left a 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 😍

@ElvinEfendi
Copy link
Member

/lgtm

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

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 0a58b1f into kubernetes:master Apr 26, 2018
@aledbf aledbf deleted the clean-json branch April 26, 2018 23:57
@fw42
Copy link

fw42 commented Jul 20, 2024

I just ran into a situation where it would be very useful to have access to endpoint.target in Lua (the pod name in particular). Was about to create a PR to add it when I saw this PR which explicitly removed it.

What was the reason for removing it?

Any opinions on adding it back? Maybe in some kind of opt-in way.

@ElvinEfendi @aledbf

@ElvinEfendi
Copy link
Member

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).

@fw42 fw42 mentioned this pull request Jul 29, 2024
10 tasks
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.

5 participants