template

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright 2020-2026 Project Capsule Authors SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

View Source
var AllowedNamespaceMetadataTemplates = sets.New[string](
	"tenant.name",
	"namespace",
)
View Source
var FastTemplateExpression = regexp.MustCompile(`{{\s*([^{}]+)\s*}}`)

Functions

func ContainsFastTemplateSyntax added in v0.13.0

func ContainsFastTemplateSyntax(value string) bool

func FastTemplate added in v0.13.0

func FastTemplate(
	template string,
	templateContext map[string]string,
) string

FastTemplate applies templating to the provided string.

func FastTemplateLabelSelector added in v0.13.0

func FastTemplateLabelSelector(
	in *metav1.LabelSelector,
	templateContext map[string]string,
) (*metav1.LabelSelector, error)

func FastTemplateMap added in v0.13.0

func FastTemplateMap(
	m map[string]string,
	templateContext map[string]string,
) map[string]string

FastTemplateMap applies templating to all values in the provided map in place.

func RenderUnstructuredItems added in v0.13.0

func RenderUnstructuredItems(
	context ReferenceContext,
	key MissingKeyOption,
	tplString string,
) (items []*unstructured.Unstructured, err error)

RenderUnstructuredItems attempts to render a given string template into a list of unstructured resources.

func RequiresFastTemplate added in v0.13.0

func RequiresFastTemplate(value string) bool

RequiresFastTemplate evaluates if given string requires templating.

func SelectorRequiresTemplating added in v0.13.0

func SelectorRequiresTemplating(sel *metav1.LabelSelector) bool

func ValidateAllowedTemplatesOnly added in v0.13.0

func ValidateAllowedTemplatesOnly(
	fieldPath string,
	value string,
) []string

func ValidateKubernetesStringOrAllowedTemplates added in v0.13.0

func ValidateKubernetesStringOrAllowedTemplates(
	fieldPath string,
	value string,
	validate func(string) []string,
) []string

Types

type MissingKeyOption added in v0.13.0

type MissingKeyOption string

+kubebuilder:validation:Enum=invalid;zero;error

const (
	MissingKeyInvalid MissingKeyOption = "invalid"
	MissingKeyZero    MissingKeyOption = "zero"
	MissingKeyError   MissingKeyOption = "error"
)

func (MissingKeyOption) String added in v0.13.0

func (p MissingKeyOption) String() string

type NamespaceValidator added in v0.13.0

type NamespaceValidator func(namespace string) error

func NewNamespaceValidator added in v0.13.0

func NewNamespaceValidator(allowCrossNamespaceSelection bool, allowed sets.Set[string]) NamespaceValidator

type ReferenceContext added in v0.13.0

type ReferenceContext map[string]any

+kubebuilder:object:generate=false

func (*ReferenceContext) String added in v0.13.0

func (t *ReferenceContext) String() (string, error)

type ResourceReference added in v0.13.0

type ResourceReference struct {
	gvk.VersionKind `json:",inline"`

	// Name of the values referent. This is useful
	// when you traying to get a specific resource
	// +kubebuilder:validation:MinLength=1
	// +kubebuilder:validation:MaxLength=253
	// +optional
	Name string `json:"name,omitempty"`
	// Namespace of the values referent.
	// +optional
	Namespace string `json:"namespace,omitempty"`
	// Selector which allows to get any amount of these resources based on labels
	// +optional
	Selector *metav1.LabelSelector `json:"selector,omitempty"`
	// Only relevant if name is set. If an item is not optional, there will be an error thrown when it does not exist
	// +kubebuilder:default:=true
	Optional bool `json:"optional,omitempty"`
}

Reference +kubebuilder:object:generate=true

func (*ResourceReference) DeepCopy added in v0.13.0

func (in *ResourceReference) DeepCopy() *ResourceReference

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceReference.

func (*ResourceReference) DeepCopyInto added in v0.13.0

func (in *ResourceReference) DeepCopyInto(out *ResourceReference)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (ResourceReference) IsNamespacedGVK added in v0.13.0

func (t ResourceReference) IsNamespacedGVK(
	restMapper k8smeta.RESTMapper,
) (bool, error)

func (ResourceReference) LoadResources added in v0.13.0

func (t ResourceReference) LoadResources(
	ctx context.Context,
	kubeClient client.Client,
	restMapper k8smeta.RESTMapper,
	namespace string,
	additionSelectors []labels.Selector,
	templateContext map[string]string,
	allowClusterScoped bool,
	validateNamespace NamespaceValidator,
) ([]*unstructured.Unstructured, error)

func (ResourceReference) LoadTemplated added in v0.13.0

func (t ResourceReference) LoadTemplated(templateContext map[string]string) (ResourceReference, error)

func (ResourceReference) RequiresTemplating added in v0.13.0

func (t ResourceReference) RequiresTemplating() bool

type TemplateContext added in v0.13.0

type TemplateContext struct {
	Resources []*TemplateResourceReference `json:"resources,omitempty"`
}

Additional Context to enhance templating +kubebuilder:object:generate=true

func (*TemplateContext) DeepCopy added in v0.13.0

func (in *TemplateContext) DeepCopy() *TemplateContext

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateContext.

func (*TemplateContext) DeepCopyInto added in v0.13.0

func (in *TemplateContext) DeepCopyInto(out *TemplateContext)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*TemplateContext) GatherContext added in v0.13.0

func (t *TemplateContext) GatherContext(
	ctx context.Context,
	kubeClient client.Client,
	restMapper k8smeta.RESTMapper,
	templateContext map[string]string,
	namespace string,
	additionSelectors []labels.Selector,
	validateNamespace NamespaceValidator,
) (ReferenceContext, error)

type TemplateResourceReference added in v0.13.0

type TemplateResourceReference struct {
	ResourceReference `json:",inline"`

	// Index to mount the resource in the template context
	Index string `json:"index,omitempty"`
}

+kubebuilder:object:generate=true

func (*TemplateResourceReference) DeepCopy added in v0.13.0

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateResourceReference.

func (*TemplateResourceReference) DeepCopyInto added in v0.13.0

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL