-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fn framework: Enable validation using openAPI schema for functionConfig #4467
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
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:master
from
KnVerey:fn-cfg-openapi-validation
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright 2022 The Kubernetes Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package framework | ||
|
|
||
| import ( | ||
| "k8s.io/kube-openapi/pkg/validation/spec" | ||
| "sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil" | ||
| "sigs.k8s.io/kustomize/kyaml/yaml" | ||
| ) | ||
|
|
||
| const FunctionDefinitionKind = "KRMFunctionDefinition" | ||
| const FunctionDefinitionGroupVersion = "config.kubernetes.io/v1alpha1" | ||
|
|
||
| // KRMFunctionDefinition is metadata that defines a KRM function the same way a CRD defines a custom resource. | ||
| // https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog#function-metadata-schema | ||
| type KRMFunctionDefinition struct { | ||
| // APIVersion and Kind of the object. Must be config.kubernetes.io/v1alpha1 and KRMFunctionDefinition respectively. | ||
| yaml.TypeMeta `yaml:",inline" json:",inline"` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we usually have this field on the top. |
||
| // Standard KRM object metadata | ||
| yaml.ObjectMeta `yaml:"metadata,omitempty" json:"metadata,omitempty"` | ||
| // Spec contains the properties of the KRM function this object defines. | ||
| Spec KrmFunctionDefinitionSpec `yaml:"spec" json:"spec"` | ||
| } | ||
|
|
||
| type KrmFunctionDefinitionSpec struct { | ||
| // | ||
| // The following fields are shared with CustomResourceDefinition. | ||
| // | ||
| // Group is the API group of the defined KRM function. | ||
| Group string `yaml:"group" json:"group"` | ||
| // Names specify the resource and kind names for the KRM function. | ||
| Names KRMFunctionNames `yaml:"names" json:"names"` | ||
| // Versions is the list of all API versions of the defined KRM function. | ||
| Versions []KRMFunctionVersion `yaml:"versions" json:"versions"` | ||
|
|
||
| // | ||
| // The following fields are custom to KRMFunctionDefinition | ||
| // | ||
| // Description briefly describes the KRM function. | ||
| Description string `yaml:"description,omitempty" json:"description,omitempty"` | ||
| // Publisher is the entity (e.g. organization) that produced and owns this KRM function. | ||
| Publisher string `yaml:"publisher,omitempty" json:"publisher,omitempty"` | ||
| // Home is a URI pointing the home page of the KRM function. | ||
| Home string `yaml:"home,omitempty" json:"home,omitempty"` | ||
| // Maintainers lists the individual maintainers of the KRM function. | ||
| Maintainers []string `yaml:"maintainers,omitempty" json:"maintainers,omitempty"` | ||
| // Tags are keywords describing the function. e.g. mutator, validator, generator, prefix, GCP. | ||
| Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"` | ||
| } | ||
|
|
||
| type KRMFunctionVersion struct { | ||
| // | ||
| // The following fields are shared with CustomResourceDefinition. | ||
| // | ||
| // Name is the version name, e.g. “v1”, “v2beta1”, etc. | ||
| Name string `yaml:"name" json:"name"` | ||
| // Schema describes the schema of this version of the KRM function. | ||
| // This can be used for validation, pruning, and/or defaulting. | ||
| Schema *KRMFunctionValidation `yaml:"schema,omitempty" json:"schema,omitempty"` | ||
|
|
||
| // | ||
| // The following fields are custom to KRMFunctionDefinition | ||
| // | ||
| // Idempotent indicates whether the function can be re-run multiple times without changing the result. | ||
| Idempotent bool `yaml:"idempotent,omitempty" json:"idempotent,omitempty"` | ||
| // Usage is URI pointing to a README.md that describe the details of how to use the KRM function. | ||
| // It should at least cover what the function does and should give a detailed explanation about each | ||
| // field used to configure it. | ||
| Usage string `yaml:"usage,omitempty" json:"usage,omitempty"` | ||
| // A list of URIs that point to README.md files. Each README.md should cover an example. | ||
| // It should at least cover how to get input resources, how to run it and what is the expected | ||
| // output. | ||
| Examples []string `yaml:"examples,omitempty" json:"examples,omitempty"` | ||
| // License is the name of the license covering the function. | ||
| License string `yaml:"license,omitempty" json:"license,omitempty"` | ||
| // The maintainers for this version of the function, if different from the primary maintainers. | ||
| Maintainers []string `yaml:"maintainers,omitempty" json:"maintainers,omitempty"` | ||
| // The runtime information describing how to execute this function. | ||
| Runtime runtimeutil.FunctionSpec `yaml:"runtime" json:"runtime"` | ||
| } | ||
|
|
||
| type KRMFunctionValidation struct { | ||
| // OpenAPIV3Schema is the OpenAPI v3 schema for an instance of the KRM function. | ||
| OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` | ||
| } | ||
|
|
||
| type KRMFunctionNames struct { | ||
| // Kind is the kind of the defined KRM Function. It is normally CamelCase and singular. | ||
| Kind string `yaml:"kind" json:"kind"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we want to support reading from a Catalog kind?
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.
Sure, we can have another helper for that once Catalog is in here / somewhere. I'd like to keep that out of scope of this PR though.