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.
Describe what this PR does / why we need it
There are many scenarios in the control plane that require expansion, such as the parsing, conversion or application of some custom CRDs. The Go language itself does not have good support for the extension mechanism. After evaluating the plug-in solution's research results and project ideas, a multi-process solution based on communication was finally adopted, implemented using the go-plugin framework, and the outer layer was packaged to form a The set of infrastructure is highly reusable and can adapt to different plug-ins. Learn from other open source products that have used go-plugin, and create a plug-in mechanism that supports the extensibility of the control plane according to the needs of the control plane.
This PR implements the control plane extensibility mechanism and builds a plug-in system.
Does this pull request fix one issue?
Fixes #46
Describe how you did it
Adopting the gRPC idea, a new plug-in process is started locally to provide corresponding method calling services for the main program. The plug-in process can provide scalable functions at different points in the main link configured by the control plane.
The request plug-in flow chart is as follows:
![image](https://private-user-images.githubusercontent.com/44493045/277154401-19ef8995-618c-4126-a07d-865bc0857c97.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NzA2ODgsIm5iZiI6MTcyNDQ3MDM4OCwicGF0aCI6Ii80NDQ5MzA0NS8yNzcxNTQ0MDEtMTllZjg5OTUtNjE4Yy00MTI2LWEwN2QtODY1YmMwODU3Yzk3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI0VDAzMzMwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThlODExZGNlYmE0NTBmOWFmNzdiODQyYjI0ZTUwOTdhOTg4MWIzMzYzNzE0N2UyNGRiYmI1ZTg0NmJlODhlOTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.62uQxtYDhfy9oX63aImuYXfF75dhkVrrVuASrg2GhC8)
Describe how to verify it
To build the plug-in executable program, execute the
make
command in the plug-in directory and the corresponding file will be generated underplugin/assets
.Currently, you can directly start the control plane to start the plug-in service, or you can ``go build main.go
under
main/``` to test an already written Demo plug-in: Stream. This is a plugin that can be called in both directions. So how to write a simple plug-in?For example ```ratelimit``` plugin
pl/builtin
directory and embed them into the go-plugin framework. That’s it.server
directory, because the script executed by make scans this directory.func ServerPlugin
inplugin/pl/plugin/plugin.go
, for example:By the way, there is currently no particularly good way to assert the plugin type here.
Now that the basic plug-in building work is completed, you can expose the plug-in to the control plane according to the plug-in name and call it at the appropriate location.
Special notes for reviews