...

Source file src/sigs.k8s.io/kustomize/kyaml/fn/framework/function_definition.go

Documentation: sigs.k8s.io/kustomize/kyaml/fn/framework

     1  // Copyright 2022 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package framework
     5  
     6  import (
     7  	"k8s.io/kube-openapi/pkg/validation/spec"
     8  	"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
     9  	"sigs.k8s.io/kustomize/kyaml/yaml"
    10  )
    11  
    12  const FunctionDefinitionKind = "KRMFunctionDefinition"
    13  const FunctionDefinitionGroupVersion = "config.kubernetes.io/v1alpha1"
    14  
    15  // KRMFunctionDefinition is metadata that defines a KRM function the same way a CRD defines a custom resource.
    16  // https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog#function-metadata-schema
    17  type KRMFunctionDefinition struct {
    18  	// APIVersion and Kind of the object. Must be config.kubernetes.io/v1alpha1 and KRMFunctionDefinition respectively.
    19  	yaml.TypeMeta `yaml:",inline" json:",inline"`
    20  	// Standard KRM object metadata
    21  	yaml.ObjectMeta `yaml:"metadata,omitempty" json:"metadata,omitempty"`
    22  	// Spec contains the properties of the KRM function this object defines.
    23  	Spec KrmFunctionDefinitionSpec `yaml:"spec" json:"spec"`
    24  }
    25  
    26  type KrmFunctionDefinitionSpec struct {
    27  	//
    28  	// The following fields are shared with CustomResourceDefinition.
    29  	//
    30  	// Group is the API group of the defined KRM function.
    31  	Group string `yaml:"group" json:"group"`
    32  	// Names specify the resource and kind names for the KRM function.
    33  	Names KRMFunctionNames `yaml:"names" json:"names"`
    34  	// Versions is the list of all API versions of the defined KRM function.
    35  	Versions []KRMFunctionVersion `yaml:"versions" json:"versions"`
    36  
    37  	//
    38  	// The following fields are custom to KRMFunctionDefinition
    39  	//
    40  	// Description briefly describes the KRM function.
    41  	Description string `yaml:"description,omitempty" json:"description,omitempty"`
    42  	// Publisher is the entity (e.g. organization) that produced and owns this KRM function.
    43  	Publisher string `yaml:"publisher,omitempty" json:"publisher,omitempty"`
    44  	// Home is a URI pointing the home page of the KRM function.
    45  	Home string `yaml:"home,omitempty" json:"home,omitempty"`
    46  	// Maintainers lists the individual maintainers of the KRM function.
    47  	Maintainers []string `yaml:"maintainers,omitempty" json:"maintainers,omitempty"`
    48  	// Tags are keywords describing the function. e.g. mutator, validator, generator, prefix, GCP.
    49  	Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
    50  }
    51  
    52  type KRMFunctionVersion struct {
    53  	//
    54  	// The following fields are shared with CustomResourceDefinition.
    55  	//
    56  	// Name is the version name, e.g. “v1”, “v2beta1”, etc.
    57  	Name string `yaml:"name" json:"name"`
    58  	// Schema describes the schema of this version of the KRM function.
    59  	// This can be used for validation, pruning, and/or defaulting.
    60  	Schema *KRMFunctionValidation `yaml:"schema,omitempty" json:"schema,omitempty"`
    61  
    62  	//
    63  	// The following fields are custom to KRMFunctionDefinition
    64  	//
    65  	// Idempotent indicates whether the function can be re-run multiple times without changing the result.
    66  	Idempotent bool `yaml:"idempotent,omitempty" json:"idempotent,omitempty"`
    67  	// Usage is URI pointing to a README.md that describe the details of how to use the KRM function.
    68  	// It should at least cover what the function does and should give a detailed explanation about each
    69  	// field used to configure it.
    70  	Usage string `yaml:"usage,omitempty" json:"usage,omitempty"`
    71  	// A list of URIs that point to README.md files. Each README.md should cover an example.
    72  	// It should at least cover how to get input resources, how to run it and what is the expected
    73  	// output.
    74  	Examples []string `yaml:"examples,omitempty" json:"examples,omitempty"`
    75  	// License is the name of the license covering the function.
    76  	License string `yaml:"license,omitempty" json:"license,omitempty"`
    77  	// The maintainers for this version of the function, if different from the primary maintainers.
    78  	Maintainers []string `yaml:"maintainers,omitempty" json:"maintainers,omitempty"`
    79  	// The runtime information describing how to execute this function.
    80  	Runtime runtimeutil.FunctionSpec `yaml:"runtime" json:"runtime"`
    81  }
    82  
    83  type KRMFunctionValidation struct {
    84  	// OpenAPIV3Schema is the OpenAPI v3 schema for an instance of the KRM function.
    85  	OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` //nolint: tagliatelle
    86  }
    87  
    88  type KRMFunctionNames struct {
    89  	// Kind is the kind of the defined KRM Function. It is normally CamelCase and singular.
    90  	Kind string `yaml:"kind" json:"kind"`
    91  }
    92  

View as plain text