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
TT-4354 Go plugins to support multiple Tyk versions #3873
TT-4354 Go plugins to support multiple Tyk versions #3873
Conversation
API tests result: success ✅ |
API tests result: success ✅ |
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.
@sredxny requested some small validation but it looks solid 👌.
Have you tested this with bundles?
API tests result: success ✅ |
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.
Looks good so far
API tests result: success ✅ |
Do I have to always put them in the same order? Can I skip some of it? Also it would be great if we modify our plugin compiler to always generate plugins with the given prefixes. And OS/arch can be read from GOOS and GOARCH arguments, if they passed to the image, and read from the current linux env if not specified. |
…of github.com:TykTechnologies/tyk into TT-4354-feature/plugins-support-multiple-tyk-versions
API tests result: success ✅ |
images/plugin-compiler/data/build.sh
Outdated
@@ -1,6 +1,7 @@ | |||
#!/bin/bash | |||
set -xe | |||
|
|||
CURRENTVERS=$(perl -n -e'/v(\d+).(\d+).(\d+)/'' && print "v$1\.$2\.$3"' ./../../../gateway/version.go) |
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.
The entry point for plugin compiler is this build.sh
at path /build.sh
. So ./../../../gateway/version.go
might not resolve correctly. gw code is copied to TYK_GW_PATH
here. ./../../../gateway/version.go
can be changed to $TYK_GW_PATH/gateway/version.go
API tests result: success ✅ |
💥 CI tests failed 🙈CI test logall ok gofmtall ok goimportsall ok If the above are ok, please look at the run or in the Checks tab. |
API tests result: success ✅ |
API tests result: success ✅ |
API tests result: success ✅ |
API tests result: success ✅ |
I think that cross compilation is complex in this case (it's easier for Go builds that don't rely on cgo). |
@matiasinsaurralde @buger @tbuchaillot I created this ticket https://tyktech.atlassian.net/browse/TT-4637 to support cross compilation in the plugin compiler and limit the scope of the current ticket to support different versions of Tyk. Can you please review again? Now the plugin compiler generate files following the naming convention stablished in this PR |
API tests result: skipped 🚫 |
API tests result: skipped 🚫 |
API tests result: skipped 🚫 |
API tests result: skipped 🚫 |
API tests result: skipped 🚫 |
SonarCloud Quality Gate failed. |
/release to release-4 |
Working on it! Note that it can take a few minutes. |
@tbuchaillot Seems like there is conflict and it require manual merge. |
API tests result: skipped 🚫
Co-authored-by: Tomas Buchaillot tombuchaillot89@gmail.com |
…ce-tests' of github.com:TykTechnologies/tyk into fix/TT-4655/federation-crashes-gateway-during-performance-tests * 'fix/TT-4655/federation-crashes-gateway-during-performance-tests' of github.com:TykTechnologies/tyk: TT-4354 Go plugins to support multiple Tyk versions (#3873) update sprig to v3 (#3897)
cherry picked into release-4 |
Revert the changes inherited from PR #3873.
Revert the changes inherited from PR #3873.
/release to release-4.1 |
@sredxny Release branch not found |
@@ -53,5 +73,5 @@ rm -rf $TYK_GW_PATH/vendor | |||
|
|||
rm /go/src/modules.txt | |||
|
|||
GO111MODULE=off go build -buildmode=plugin -o $plugin_name \ | |||
GO111MODULE=off CGO_ENABLE=$CGO_ENABLE GOOS=$GOOS GOARCH=$GOARCH go build -buildmode=plugin -o $plugin_name \ |
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.
We have $CGOENABLED as a variable, the env to use is CGO_ENABLED
but we define CGO_ENABLE
🤔
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.
Good point... Created #4160
however unsure if we should support this var any longer
Description
In order to support plugins with multiple tyk versions then was added a logic on how to load them using information such as: tyk version, operative system and architecture in which its running. The load Go Plugin logic will find first if there's an exact match with the provided path, if that file doesn't exist then it will build a path+pluginName like this:
1- Gather information like: os, tyk version and architecture
2- Obtain the clean name of the plugin
3- Obtain the directory where the plugins are stored
4- Build a new plugin name in the format:
{plugin-dir}/{plugin-name}_{GW-version}_{OS}_{arch}.so
5- Load the plugin using the new name
Related Issue
https://tyktech.atlassian.net/browse/TT-4354
Motivation and Context
Allow users to upload multiple version of a go plugin, and load it based on where its running
How This Has Been Tested
mygoplugin_v4.1.0_darwin_amd64.so
curl -i http://tyk-gateway:8081/goplugin/get
Testing the Plugin compiler
Now the plugin compiler have the ability to generate the plugins with the name format set as explained above, in order to test it we need to create the plugin and check that the name is set as expected. The plugin compiler have the ability to receive by params the OS and Arch as 3rd and 4th param. To test, lets do:
go mod init tyk_plugin
go mod edit -replace github.com/jensneuse/graphql-go-tools=github.com/TykTechnologies/graphql-go-tools@f818861b88dc
go get github.com/TykTechnologies/tyk@af8883a
tykio/tyk-plugin-compiler:v4.1.0-rc3
and at this point we need to test it in 2 ways: sending the arch and os, and not sending thos params:1- Sending OS/Arch (Skip this section as cross compilation is not working):
docker run --rm -v
pwd:/plugin-source tykio/tyk-plugin-compiler:v4.1.0-rc5 plugin.so pluginid testOS testArch
and as output it will generate a file named:plugin_v4.1.0_testOS_testArch.so
The bad side of this approach is that is always required to send a pluginID.
If we attempt to send an invalid OS or arch, we will receive a message like this:
2- Without sending the OS/Arch:
docker run --rm -v
pwd:/plugin-source tykio/tyk-plugin-compiler:v4.1.0-rc5 plugin.so
as the docker container is running linux it will detect that OS and architecture and will create a file with a name like:plugin_v4.1.0_linux_amd64.so
Screenshots (if appropriate)
Types of changes
Checklist
fork, don't request your
master
!master
branch (left side). Also, you should startyour branch off our latest
master
.go mod tidy && go mod vendor
go fmt -s
go vet