[backport -> release/3.6.x] chore(wasm): reuse kong.dns object for DNS bridge #12652
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.
Automated backport to
release/3.6.x
, triggered by a label in #12465.Original description
The overall goal of this PR is to make the Wasm subsystem a better citizen of Kong.
Summary
The original code used the
kong.tools.dns
module to attempt* to instantiate its own DNS client:kong/kong/runloop/wasm.lua
Lines 838 to 839 in b7d50b0
This has not caused any problems that we are aware of, but it's not the correct behavior and could potentially lead to problems further down the line with the DNS client rewrite looming.
Reusing the global
kong.dns
object necessitates moving this initialization code to theinit_worker
phase to work around some order-of-operations challenges (wasm.init()
needs to run before core entity schemas are loaded, which is also beforekong.dns
is initialized).Additionally, I have added some checks around our special
ngx.IS_CLI
flag to avoid setup steps in CLI mode. This means that test code that useskong.runloop.wasm
will not be expected to mock global objects that are effectively unused in this context.*the DNS client code uses a singleton pattern with state kept at the module level, so it does not in fact create a "new" DNS client--it merely re-configures the existing one in-place.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdThere is a user-facing docs PR against https://github.com/Kong/docs.konghq.comIssue reference
KAG-3644