forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 45
NO-JIRA: add a generator for plugins and reduce dependencies #186
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
Open
rikatz
wants to merge
2
commits into
openshift:main
Choose a base branch
from
rikatz:reduce-coredns-dependencies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Makefile.ocp — OpenShift plugin management for CoreDNS | ||
| # | ||
| # Usage: | ||
| # make -f Makefile.ocp generate-plugins # prune plugins and regenerate | ||
| # make -f Makefile.ocp verify-plugins # CI check: fail if tree is dirty | ||
| # | ||
| # After an upstream rebase: | ||
| # 1. (Optional) Add new plugins to openshift-plugins.cfg if needed | ||
| # 2. Run: make -f Makefile.ocp generate-plugins | ||
| # 3. Commit the result | ||
|
|
||
| OPENSHIFT_PLUGINS_CFG := openshift-plugins.cfg | ||
| PLUGIN_CFG := plugin.cfg | ||
| PLUGIN_DIR := plugin | ||
|
|
||
| # Infrastructure directories under plugin/ that are never plugins. | ||
| INFRA_DIRS := pkg test deprecated import | ||
|
|
||
| # Plugin directories that are NOT registered in openshift-plugins.cfg but | ||
| # are imported as code dependencies by kept plugins. Update this list if | ||
| # a kept plugin gains a new cross-plugin import after an upstream rebase. | ||
| # | ||
| # debug — imported by forward | ||
| # dnstap — imported by forward | ||
| # etcd — etcd/msg imported by kubernetes | ||
| # metadata — imported by cache, kubernetes, forward | ||
| # transfer — imported by kubernetes | ||
| # whoami — imported by bufsize (tests) | ||
| # erratic — imported by ready (tests) | ||
| DEP_DIRS := debug dnstap etcd metadata transfer whoami erratic | ||
|
|
||
| .PHONY: generate-plugins | ||
| generate-plugins: | ||
| @echo "==> Overwriting $(PLUGIN_CFG) with $(OPENSHIFT_PLUGINS_CFG)" | ||
| cp $(OPENSHIFT_PLUGINS_CFG) $(PLUGIN_CFG) | ||
| @echo "==> Removing unused plugin directories" | ||
| @$(call remove-unused-plugins) | ||
| @echo "==> Regenerating plugin Go files" | ||
| go generate coredns.go | ||
| @echo "==> Tidying modules" | ||
| go mod tidy | ||
| @echo "==> Vendoring dependencies" | ||
| go mod vendor | ||
| @echo "==> Done. Review changes with 'git diff --stat'" | ||
|
|
||
| .PHONY: verify-plugins | ||
| verify-plugins: | ||
| @echo "==> Verifying plugin tree matches $(OPENSHIFT_PLUGINS_CFG)" | ||
| @diff -q $(OPENSHIFT_PLUGINS_CFG) $(PLUGIN_CFG) || \ | ||
| (echo "ERROR: $(PLUGIN_CFG) does not match $(OPENSHIFT_PLUGINS_CFG)"; exit 1) | ||
| @$(call check-no-unused-plugins) | ||
| @echo "==> Plugin tree is clean" | ||
|
|
||
| # All directories that must be preserved: infrastructure, active plugins | ||
| # (from openshift-plugins.cfg), and code-dependency plugins (DEP_DIRS). | ||
| define kept-plugin-dirs | ||
| $$(grep -v '^\s*#' $(OPENSHIFT_PLUGINS_CFG) | grep -v '^\s*$$' | cut -d: -f2 | grep -v '/') | ||
| endef | ||
|
|
||
| # remove-unused-plugins deletes plugin/<name>/ directories not in the | ||
| # kept set (active plugins + DEP_DIRS + INFRA_DIRS). | ||
| define remove-unused-plugins | ||
| kept=$(kept-plugin-dirs); \ | ||
| for dir in $(PLUGIN_DIR)/*/; do \ | ||
| name=$$(basename "$$dir"); \ | ||
| skip=false; \ | ||
| for s in $(INFRA_DIRS) $(DEP_DIRS); do \ | ||
| if [ "$$name" = "$$s" ]; then skip=true; break; fi; \ | ||
| done; \ | ||
| if $$skip; then continue; fi; \ | ||
| if echo "$$kept" | grep -qx "$$name"; then continue; fi; \ | ||
| echo " removing $(PLUGIN_DIR)/$$name"; \ | ||
| rm -rf "$$dir"; \ | ||
| done | ||
| endef | ||
|
|
||
| # check-no-unused-plugins fails if any plugin directories exist that | ||
| # should have been removed. | ||
| define check-no-unused-plugins | ||
| kept=$(kept-plugin-dirs); \ | ||
| stale=""; \ | ||
| for dir in $(PLUGIN_DIR)/*/; do \ | ||
| name=$$(basename "$$dir"); \ | ||
| skip=false; \ | ||
| for s in $(INFRA_DIRS) $(DEP_DIRS); do \ | ||
| if [ "$$name" = "$$s" ]; then skip=true; break; fi; \ | ||
| done; \ | ||
| if $$skip; then continue; fi; \ | ||
| if echo "$$kept" | grep -qx "$$name"; then continue; fi; \ | ||
| stale="$$stale $$name"; \ | ||
| done; \ | ||
| if [ -n "$$stale" ]; then \ | ||
| echo "ERROR: unused plugin directories found:$$stale"; \ | ||
| echo "Run 'make -f Makefile.ocp generate-plugins' to fix."; \ | ||
| exit 1; \ | ||
| fi | ||
| endef | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # OpenShift CoreDNS Fork | ||
|
|
||
| This is the OpenShift fork of [CoreDNS](https://coredns.io). It is deployed | ||
| and managed by the | ||
| [cluster-dns-operator](https://github.com/openshift/cluster-dns-operator). | ||
|
|
||
| ## Plugin management | ||
|
|
||
| The operator generates the CoreDNS Corefile and only uses a subset of upstream | ||
| plugins. Unused plugins are removed to reduce the binary size, dependency | ||
| footprint, and attack surface. | ||
|
|
||
| The file `openshift-plugins.cfg` is the source of truth for the kept plugin | ||
| set. It uses the same `name:package` format as the upstream `plugin.cfg`. | ||
|
|
||
| ### Regenerating after a rebase | ||
|
|
||
| After rebasing onto a new upstream version: | ||
|
|
||
| ``` | ||
| make -f Makefile.ocp generate-plugins | ||
| ``` | ||
|
|
||
| This will: | ||
|
|
||
| 1. Overwrite `plugin.cfg` with `openshift-plugins.cfg` | ||
| 2. Remove plugin directories under `plugin/` that are not needed | ||
| 3. Regenerate the Go files (`core/plugin/zplugin.go`, `core/dnsserver/zdirectives.go`) | ||
| 4. Run `go mod tidy` and `go mod vendor` | ||
|
|
||
| Review the result with `git diff --stat`, then commit. | ||
|
|
||
| ### Adding or removing a plugin | ||
|
|
||
| Edit `openshift-plugins.cfg`, then run `make -f Makefile.ocp generate-plugins`. | ||
|
|
||
| If a kept plugin imports another plugin as a Go package (not as a registered | ||
| Corefile directive), that dependency directory must be listed in the `DEP_DIRS` | ||
| variable in `Makefile.ocp`. The build will fail with a clear error if a | ||
| dependency is missing. | ||
|
|
||
| ### CI verification | ||
|
|
||
| The pipeline should run: | ||
|
|
||
| ``` | ||
| make -f Makefile.ocp verify-plugins | ||
| ``` | ||
|
|
||
| This checks that `plugin.cfg` matches `openshift-plugins.cfg` and that no | ||
| unused plugin directories are present. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
During the rebase process, we run
go mod vendorand commit the vendored files as a separate step — this is the "Vendor required modules" carry commit (coredns@358bd8f). So I would omitgo mod vendoringenerate-pluginsand put this "reduce dependencies" commit before the "Vendor required modules" commit. The rebase process would be like this:make generate-plugins, and commit the result.go mod vendor, and commit the results.