Chever-John commented on code in PR #994: URL: https://github.com/apache/apisix-ingress-controller/pull/994#discussion_r866578904
########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,400 @@ +# How to use go-plugin-runner in APISIX Ingress + +## Background Description + +While wandering around the community, I found a user confused about "how to use multilingual plugins in APISIX Ingress environment". I happen to be a user of go-plugin-runner and have a little knowledge of the APISIX Ingress project, so this document was born. + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through building the cluster, building the image, customizing the helm chart package, and finally, deploying the resources. It is guaranteed that the final result can be derived in full based on this documentation. + +```bash +go-plugin-runner: 0.3 +APISIX Ingress: 1.4.0 + +kind: kind v0.12.0 go1.17.8 linux/amd64 +kubectl version: Client Version: v1.23.5/Server Version: v1.23.4 +golang: go1.18 linux/amd64 +``` + +## Begin + +### Build a cluster environment + +Select `kind` to build a local cluster environment. The command is as follows: + +```bash +cat <<EOF | kind create cluster --config=- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP +EOF +``` + +### Build the go-plugin-runner executable + +If you have finished writing the plugin, you can start compiling the executable to run with APISIX. + +This article recommends two packaging build options. + +1. put the packaging process into the Dockerfile and finish the compilation process when you build the docker image later. +2. You can also follow the scheme used in this document, building the executable first and then copying the packaged executable to the image. + +How you choose the option should depend on your local hardware considerations. The reason for selecting the second option here is that I want to rely on my powerful local hardware to increase the building speed and speed up the process. + +### Go to the go-plugin-runner directory + +Choose a folder address `/home/chever/api7/cloud_native/tasks/plugin-runner` and place our `apisix-go-plugin-runner` project in this folder. + +After successful placement, the file tree is shown below: + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner$ tree -L 1 +. +└── apisix-go-plugin-runner + +1 directory, 0 files +``` + +Then you need to go to the `apisix-go-plugin-runner/cmd/go-runner/plugins` directory and write the plugins you need in that directory. This article will use the default plugin `say` for demonstration purposes. + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner/apisix-go-plugin-runner$ tree cmd +cmd +└── go-runner + ├── main.go + ├── main_test.go + ├── plugins + │ ├── fault_injection.go + │ ├── fault_injection_test.go + │ ├── limit_req.go + │ ├── limit_req_test.go + │ ├── say.go + │ └── say_test.go + └── version.go + +2 directories, 10 files +``` + +After writing the plugins, start compiling the executable formally, and note here that you should build static executables, not dynamic ones. + +The package compile command is as follows. + +```bash +CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' . +``` + +This successfully packages a statically compiled `go-runner` executable. + +In the `apisix-go-plugin-runner/cmd/go-runner/` directory, you can see that the current file tree looks like this: Review Comment: @tao12345666333 @navendu-pottekkat I'm convinced by you guys, thanks~ ########## docs/en/latest/practices/how-to-use-go-plugin-runner-in-apisix-ingress.md: ########## @@ -0,0 +1,400 @@ +# How to use go-plugin-runner in APISIX Ingress + +## Background Description + +While wandering around the community, I found a user confused about "how to use multilingual plugins in APISIX Ingress environment". I happen to be a user of go-plugin-runner and have a little knowledge of the APISIX Ingress project, so this document was born. + +## Proposal Description + +Based on version 0.3 of the go-plugin-runner plugin and version 1.4.0 of APISIX Ingress, this article goes through building the cluster, building the image, customizing the helm chart package, and finally, deploying the resources. It is guaranteed that the final result can be derived in full based on this documentation. + +```bash +go-plugin-runner: 0.3 +APISIX Ingress: 1.4.0 + +kind: kind v0.12.0 go1.17.8 linux/amd64 +kubectl version: Client Version: v1.23.5/Server Version: v1.23.4 +golang: go1.18 linux/amd64 +``` + +## Begin + +### Build a cluster environment + +Select `kind` to build a local cluster environment. The command is as follows: + +```bash +cat <<EOF | kind create cluster --config=- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + extraPortMappings: + - containerPort: 80 + hostPort: 80 + protocol: TCP + - containerPort: 443 + hostPort: 443 + protocol: TCP +EOF +``` + +### Build the go-plugin-runner executable + +If you have finished writing the plugin, you can start compiling the executable to run with APISIX. + +This article recommends two packaging build options. + +1. put the packaging process into the Dockerfile and finish the compilation process when you build the docker image later. +2. You can also follow the scheme used in this document, building the executable first and then copying the packaged executable to the image. + +How you choose the option should depend on your local hardware considerations. The reason for selecting the second option here is that I want to rely on my powerful local hardware to increase the building speed and speed up the process. + +### Go to the go-plugin-runner directory + +Choose a folder address `/home/chever/api7/cloud_native/tasks/plugin-runner` and place our `apisix-go-plugin-runner` project in this folder. + +After successful placement, the file tree is shown below: + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner$ tree -L 1 +. +└── apisix-go-plugin-runner + +1 directory, 0 files +``` + +Then you need to go to the `apisix-go-plugin-runner/cmd/go-runner/plugins` directory and write the plugins you need in that directory. This article will use the default plugin `say` for demonstration purposes. + +```bash +chever@cloud-native-01:~/api7/cloud_native/tasks/plugin-runner/apisix-go-plugin-runner$ tree cmd +cmd +└── go-runner + ├── main.go + ├── main_test.go + ├── plugins + │ ├── fault_injection.go + │ ├── fault_injection_test.go + │ ├── limit_req.go + │ ├── limit_req_test.go + │ ├── say.go + │ └── say_test.go + └── version.go + +2 directories, 10 files +``` + +After writing the plugins, start compiling the executable formally, and note here that you should build static executables, not dynamic ones. + +The package compile command is as follows. + +```bash +CGO_ENABLED=0 go build -a -ldflags '-extldflags "-static"' . +``` + +This successfully packages a statically compiled `go-runner` executable. + +In the `apisix-go-plugin-runner/cmd/go-runner/` directory, you can see that the current file tree looks like this: Review Comment: Solved~ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
