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

Allow importing kustomize API's without relying on plugins #5525

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

tigrato
Copy link
Contributor

@tigrato tigrato commented Feb 1, 2024

Introduce kustomize_disable_go_plugin_support go build tag to decouple the kustomize API from the plugins package dependency. This is advantageous for applications embedding the kustomize API without the need for dynamic Go plugins, mitigating an increase in binary size associated with the inclusion of the plugins dependency and the population of ELF sections like .dynsym and .dynstr.

The flag provides applications with the flexibility to exclude the import, catering to scenarios where dynamic Go plugin support is unnecessary.

Fixes #5524

Introduce `kustomize_disable_go_plugin_support` go build tag to decouple the kustomize
API from the `plugins` package dependency. This is advantageous for applications
embedding the kusstomize API without the need for dynamic Go plugins, mitigating an
increase in binary size associated with the inclusion of the plugins dependency
and the population of ELF sections like `.dynsym` and `.dynstr`.

The flag provides applications with the flexibility to exclude the import, catering to
scenarios where dynamic Go plugin support is unnecessary.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 1, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @tigrato!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @tigrato. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 1, 2024
@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Hi there, @tigrato! 👋

Thank you very much for your contribution!

Left a few nits, please let me know if anything is unclear.

api/internal/plugins/loader/load_go_plugin_disabled.go Outdated Show resolved Hide resolved
api/internal/plugins/loader/load_go_plugin.go Outdated Show resolved Hide resolved
api/internal/plugins/loader/load_go_plugin.go Outdated Show resolved Hide resolved
@stormqueen1990
Copy link
Member

/ok-to-test
/cc @varshaprasad96 @koba1t
for a second-pass review

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 12, 2024
@tigrato
Copy link
Contributor Author

tigrato commented Feb 12, 2024

@stormqueen1990

I incorporated all the suggestions.
Thank you for the review.

Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

/lgtm

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

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

Thanks for the PR @tigrato!
/lgtm
/approve

// but the loaded .so files are in shared memory, so one will get
// "this plugin already loaded" errors if the registry is maintained
// as a Loader instance variable. So make it a package variable.
var registry = make(map[string]resmap.Configurable) //nolint:gochecknoglobals
Copy link
Member

@varshaprasad96 varshaprasad96 Feb 27, 2024

Choose a reason for hiding this comment

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

Probably a follow up, doesn't necessarily concern this PR as it was like this before - but it would be nice to pass the registry with the loader instead of having it as a global variable (probably like an optional builder pattern) to enable having restricted access to the map.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the reason why this is a global variable is that because go panics if you try to load the same plugin twice.
If we do it per registry, one might end up with panics because loading twice isn't allowed in go plugin module although the plugin was only loaded once per registry's
The only viable way is to use a global registry

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tigrato, varshaprasad96

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 27, 2024
@k8s-ci-robot k8s-ci-robot merged commit 33caee5 into kubernetes-sigs:master Feb 27, 2024
9 checks passed
antoooks pushed a commit to antoooks/kustomize that referenced this pull request Mar 24, 2024
…tes-sigs#5525)

* Allow importing kustomize API's without relying on `plugins`

Introduce `kustomize_disable_go_plugin_support` go build tag to decouple the kustomize
API from the `plugins` package dependency. This is advantageous for applications
embedding the kusstomize API without the need for dynamic Go plugins, mitigating an
increase in binary size associated with the inclusion of the plugins dependency
and the population of ELF sections like `.dynsym` and `.dynstr`.

The flag provides applications with the flexibility to exclude the import, catering to
scenarios where dynamic Go plugin support is unnecessary.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* fix golint by disabling some lint checks

* handle code review suggestions

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
tigrato added a commit to tigrato/kustomize that referenced this pull request Apr 8, 2024
When kubernetes-sigs#5525 merged, it
referenced `errors.New` function but that function doesn't exist.
This PR replaces the call with simple `fmt.Errorf`.
k8s-ci-robot pushed a commit that referenced this pull request Apr 30, 2024
* fix: use fmt.Errorf ubstead if non-exising `errors.New`

When #5525 merged, it
referenced `errors.New` function but that function doesn't exist.
This PR replaces the call with simple `fmt.Errorf`.

* Add lint check with kustomize_disable_go_plugin_support

* move lint-api-static to /api/Makefile

* clean golangci cache
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large Binary Size Increase due to Dependencies on Go's Dynamic Plugin Loader
4 participants