Skip to content
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

Tool for Generating Trigger Schema #6345

Open
SpiritZhou opened this issue Nov 19, 2024 · 3 comments
Open

Tool for Generating Trigger Schema #6345

SpiritZhou opened this issue Nov 19, 2024 · 3 comments
Labels
feature-request All issues for new features that have not been committed to needs-discussion

Comments

@SpiritZhou
Copy link
Contributor

Proposal

Generating trigger metadata schema according to new declarative scaler configuration, which can be used for validation or other related improvement.

Input:
make generate-trigger-metadata-schema [--triggername][--output][--outputfile]

Output:
trigger-metadata-schemas.yaml

Trigger metadata example:

- type: kubernetes-workload
  metadatafields:
    activationValue:
        type: string
        default: "0"
    podSelector:
        type: string
    value:
        type: string
        default: "0"
- type: activemq
  metadatafields:
    activationTargetQueueSize:
      type: string
      optional: "true"
      default: "0"
    brokerName:
      type: string
      optional: "true"
    corsHeader:
      type: string
      optional: "true"
    destinationName:
      type: string
      optional: "true"
    managementEndpoint:
      type: string
      optional: "true"
    password:
      type: string
    passwordFromEnv:
      type: string
    restAPITemplate:
      type: string
      optional: "true"
    targetQueueSize:
      type: string
      optional: "true"
      default: "10"
    username:
      type: string
    usernameFromEnv:
      type: string

Use-Case

No response

Is this a feature you are interested in implementing yourself?

Yes

Anything else?

No response

@SpiritZhou SpiritZhou added needs-discussion feature-request All issues for new features that have not been committed to labels Nov 19, 2024
@wozniakjan
Copy link
Member

the tricky part is that technically all metadata fields are string in the CRD definition despite the underlying type. The OpenAPI schema allows setting multiple types for a field, maybe we can leverage that in some way?
https://stackoverflow.com/questions/46472543/specifying-multiple-types-for-additionalproperties-through-swagger-openapi

We would likely need to change the map[string]string to map[string]any but this theoretically shouldn't be a breaking change.

@SpiritZhou
Copy link
Contributor Author

Now the metadata parameters can be retrieved from the config, but there are two options in the following steps:

  1. Attempt to merge the schemas to the ScaledObject schema. I've made several attempts in this direction, but there is no proper way to add them into the ScaledObjects CRD YAML. The major problem is that I can't find a way to validate the parameter combination of the trigger. I have tried using 'oneOf', but it is not working. If there is any other good approach, please let me know so that I can give it a try.
  2. Save them as Trigger Metadata schema files and validate trigger metadata value on the webhook by loading these trigger metadata schemas at runtime.
    WDYT @JorTurFer @zroubalik @wozniakjan

@wozniakjan
Copy link
Member

great findings @SpiritZhou! I think option 2 - a standalone schemas file should be sufficient. I personally would even descope the webhook and validation by kube-apiserver for now and only generate + publish the trigger schema file as part of the KEDA repository. That would already be a terrific improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request All issues for new features that have not been committed to needs-discussion
Projects
Status: To Triage
Development

No branches or pull requests

2 participants