amesh icon indicating copy to clipboard operation
amesh copied to clipboard

proposal: AmeshPluginConfig support

Open lingsamuel opened this issue 3 years ago • 1 comments

AmeshPluginConfig Resource

The resource AmeshPluginConfig is a custom resource that defines all the plugin configurations that will be used by the APISIX. A minimum sample configuration is as follows:

apiVersion: apisix.apache.org/v1alpha1
kind: AmeshPluginConfig
metadata:
  name: go-plugins
spec:
  type: pre-req
  plugins:
  - name: say
    config: "{\"body\":\"hello\"}"

This CRD indicates that the routes should be injected with the following plugin configuration:

{
  // ... Route configurations ...
  "plugins": {
    "ext-plugin-pre-req": {
       "conf": [
         {"name":"say", "value":"{\"body\":\"hello\"}"}
       ]
    } 
  },
}

If you only want the plugin to run on specific workloads, you can add the selector field for filtering.

apiVersion: apisix.apache.org/v1alpha1
kind: AmeshPluginConfig
metadata:
  name: go-plugins
spec:
  type: pre-req
  plugins: 
  - name: say
    config: "{\"body\":\"hello\"}"
  # selectors
  nodeSelector:
    kubernetes.io/hostname: node1
  selector:
    matchLabels:
      component: redis
    matchExpressions:
    - key: zone
      operator: In
      values:
      - foo
      - bar
    - key: environment
      operator: NotIn
      values:
      - dev

For more information about selectors, please refer to Resources that support set-based requirements. Custom Plugins Apart from the official plugins, users can also add custom plugins to the Amesh. To make the image used by the sidecar include user custom plugins, the user needs to build a new image based on Amesh's APISIX image and the user's plugins. Test Plan We need a complete and solid test suite to validate this functionality, including the following cases:

  • [x] Test the plugin configuration is injected into the routes
  • [ ] Test the plugin with a custom selector
  • [x] Test the plugin definition updates are reflected

lingsamuel avatar Sep 05 '22 09:09 lingsamuel

SGTM

tao12345666333 avatar Sep 05 '22 10:09 tao12345666333