-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(schema): deprecated shorthand fields precedence #13486
Conversation
8efd700
to
8275080
Compare
The actual fix is in this commit: |
8275080
to
a123edc
Compare
711b888
to
b077ce0
Compare
60ffb5e
to
d77324a
Compare
if (entity.protocols and not entity.route) | ||
or (entity.service and not entity.protocols) | ||
or (entity.route and not entity.protocols) |
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's the idea behind this logic? 🤔 Why protocols and routes are XORed etc.?
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.
same question: shouldn't we check for "protocol match" even when both e.g. protocols and route were updated?
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.
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.
you're right I misinterpreted the scope of that if block, my bad.
for k, v in pairs(new_values) do | ||
if type(v) == "table" then | ||
data[k] = tablex.merge(data[k] or {}, v, true) | ||
else | ||
data[k] = deprecation and table_merge(v, data[k]) |
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.
Maybe let's add a comment here to explain why deprecation is tied to shorthands?
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 am fine with asks like these. It is just that simple ask like this can create considerable amounts of work. Like restarting EE tests 10 times.
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.
A comment was added.
if (entity.protocols and not entity.route) | ||
or (entity.service and not entity.protocols) | ||
or (entity.route and not entity.protocols) |
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.
same question: shouldn't we check for "protocol match" even when both e.g. protocols and route were updated?
kong/api/routes/plugins.lua
Outdated
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.
are the changes in this file related to the fix? I am not sure I understand what changed here.
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.
@samugi again, they are checking, just that we can skip additional RBW (read-before-write) -> we don't need to read database as the information that is needed for the check is already there.
The changes in this file are related to fix. But it also contains optimization (aka no rbw when not needed) - the generic DAO will do RBW on updates always (too). Actually on updates on admin API the admin api does RBW to read plugin name
to get correct schema, the DAO does for protocols check and generic dao does it too. The middle one is optimized here to only happen when needed.
…ome functions Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
9b66421
to
df32e55
Compare
### Summary The shorthand fields e.g. as used in (the url is a shorthand) take precedence: ``` http PUT :8001/services/test url=http://test.org/ port=2345 ``` That means that `port=2345` will be overwritten by http default port of `80` that is implicit in shorthand field `url`. This is how it has been for a long long time. In PR #12686 we added `deprecation` field to shorthand fields definition. Some of our automatic migrations without database migrations magic use this functionality, but the precedence there does not good: ``` http -f PUT :8001/plugins/x name=x config.new=test config.old=should_be_ignored ``` In above the `config.old` is a shorthand field with a deprecation property. Thus it should not overwrite the `config.new`, but in current code base it does. This PR changes it so that it doesn't do it anymore. KAG-5134 and https://kongstrong.slack.com/archives/C07AQH7SAF8/p1722589141558609 Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
df32e55
to
c8b1604
Compare
Cherry-pick failed for Please cherry-pick the changes locally. git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-13486-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-13486-to-master-to-upstream
git checkout -b cherry-pick-13486-to-master-to-upstream
ancref=$(git merge-base 0960f882a944447df02f32390142447d95192d3e c8b1604fb71fdab969bea6f261c12b7a249d058f)
git cherry-pick -x $ancref..c8b1604fb71fdab969bea6f261c12b7a249d058f |
The EE PR is here: |
Summary
The shorthand fields e.g. as used in (the url is a shorthand) take precedence:
That means that
port=2345
will be overwritten by http default port of80
that is implicit in shorthand fieldurl
.This is how it has been for a long long time.
In PR #12686 we added
deprecation
field to shorthand fields definition.Some of our automatic migrations without database migrations magic use this functionality, but the precedence there does not good:
In above the
config.old
is a shorthand field with a deprecation property. Thus it should not overwrite theconfig.new
, but in current code base it does. This PR changes it so that it doesn't do it anymore.KAG-5134 and https://kongstrong.slack.com/archives/C07AQH7SAF8/p1722589141558609
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.md