Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

[TT-5883] Python plugin example #464

Closed
wants to merge 1 commit into from

Conversation

andrei-tyk
Copy link
Collaborator

Description

Added required documentation and examples regarding the custom plugin - python version functionality.

Related Issue

Motivation and Context

A colleague @JRWu tested this functionality himself for a blog post and provided us with the associated documentation and examples.

Test Coverage For This Change

No logic modified, just a documentation update.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side). If PRing from your fork, don't come from your master!
  • Make sure you are making a pull request against our master branch (left side). Also, it would be best if you started your change off our latest master.
  • Make sure you are updating CHANGELOG.md based on your changes.
  • My change requires a change to the documentation.
    • If you've changed APIs, describe what needs to be updated in the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • Check your code additions will not fail linting checks:
    • gofmt -s -w .
    • go vet ./...
    • golangci-lint run

… required files in order to run the tutorial
@andrei-tyk andrei-tyk requested a review from a team as a code owner May 23, 2022 09:36
@andrei-tyk andrei-tyk requested review from buraksekili and removed request for a team May 23, 2022 09:36
@sonarcloud
Copy link

sonarcloud bot commented May 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell B 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

| [Custom Plugins - gRPC](./../bdd/features/api_http_grpc_plugin.feature) | ✅ | - |
| [Custom Plugins - Javascript](./api_definitions/custom_plugin.md) | ✅ | - |
| Custom Plugins - Lua | ⚠️ | Untested |
| Custom Plugins - Python | ✅️ | - |
Copy link
Member

Choose a reason for hiding this comment

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

Worth linking to docs/api_definitions/custom_plugin_python/custom_plugin_python.md from here

"custom_plugin_python.yaml" via the command (assuming the tyk stack has been deployed inside the tyk namespace):

```
kubectl apply -f custom_plugin_python.yaml -n tyk
Copy link
Member

Choose a reason for hiding this comment

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

I believe that we shouldn't set path and namespace explicitly in the doc. We might use

  • heredoc:
cat <<EOF | kubectl apply -n <namespace> -f -
apiVersion: tyk.tyk.io/v1alpha1
kind: ApiDefinition
metadata:
  name: httpbin
spec:
  name: httpbin
  use_keyless: true
  protocol: http
  active: true
  proxy:
    target_url: http://httpbin.org
    listen_path: /httpbin
    strip_listen_path: true
  custom_middleware_bundle: "bundle.zip"
EOF
  • or if users have access to repository,
kubectl apply -f ./docs/api_definitions/custom_plugin_python.yaml -n <namespace>

Firstly to create the said bundle we need to run the following command:

```
IMAGETAG=v3.2.1
Copy link
Member

Choose a reason for hiding this comment

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

This command won't run if your directory has no manifest.json attached to this PR. So, users should be in docs/api_definitions/custom_plugin_python directory.

```

Your bundle should now be accessible locally through the URL http://localhost:8000/bundle.zip,
or through the url http://host.minikube.internal:8000/bundle.zip from within minikube.
Copy link
Member

@buraksekili buraksekili May 24, 2022

Choose a reason for hiding this comment

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

It may sound silly but why are we mentioning minikube here? The above part indicates that I should see bundle.zip in my current directory. And after serving it, shouldn't it be accessible only locally? It seems like it shouldn't be accessible via my cluster. Maybe i am missing a feature of minikube 😄

Copy link

Choose a reason for hiding this comment

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

I mentioned it since the gateway needs to be able to access the bundle.zip being served by the python fileserver on the HOST; in minikube, host access is permitted through host.minikube.internal, which is also why the env variable TYK_GW_BUNDLEBASEURL refers to http://host.minikube.internal:8000/.

If the python fileserver was deployed in the minkube cluster, we would simply use the k8s namespacing to refer to the bundle's hosted location

Copy link
Member

Choose a reason for hiding this comment

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

oh, i see. thanks @JRWu for explanation 👍 should we update doc based on your explanation? it may be helpful for users.

Copy link

Choose a reason for hiding this comment

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

Yes absolutely, I can add some more information to the markdown file

Copy link
Member

Choose a reason for hiding this comment

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

Thank you 🙏

Copy link
Member

@asoorm asoorm May 24, 2022

Choose a reason for hiding this comment

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

I'm also a bit confused about this. Targeting bundle server http://host.minikube.internal:8000/bundle.zip might work fine locally / in Minikube, but how would it work in production? I need a bundle server right? So that bundle server needs to be deployable to K8s (dockerized) also with a Deployment and Service that the Gateway can target?

## Custom Plugin example using python

We assume that you already have a developed python plugin with the associated python file and its manifest in JSON.
If not, you can start from the provided examples ("manifest.json" and "middleware.py").
Copy link
Member

Choose a reason for hiding this comment

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

Provide links to the manifest.json and middleware.py example files.

@caroltyk caroltyk changed the title Python plugin example [TT-5883] Python plugin example Jun 28, 2022
@buger buger force-pushed the feat/python-custom-plugin branch from 3046ae9 to ee2b362 Compare May 22, 2024 14:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants