helpers

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 32 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWeights = []schema.GroupVersionKind{
	{Group: "apiextensions.k8s.io"},

	{Group: "core.kcp.io"},
	{Group: "tenancy.kcp.io", Kind: "WorkspaceAuthenticationConfiguration"},
	{Group: "tenancy.kcp.io", Kind: "WorkspaceType"},
	{Group: "tenancy.kcp.io"},
	{Group: "topology.kcp.io"},
	{Group: "apis.kcp.io", Kind: "APIResourceSchema"},
	{Group: "apis.kcp.io", Kind: "APIExport"},
	{Group: "apis.kcp.io", Kind: "APIBinding"},
	{Group: "apis.kcp.io"},

	{Kind: "Namespace"},
}

DefaultWeights is the default hierarchy for kcp related APIs to apply in order without errors or retrying.

Functions

func BindRootAPI added in v0.31.0

func BindRootAPI(ctx context.Context, kcpClient kcpclient.Interface, exportName string) error

func BindRootAPIs added in v0.6.0

func BindRootAPIs(ctx context.Context, kcpClient kcpclient.Interface, exportNames ...string) error

func Bootstrap

func Bootstrap(ctx context.Context, discoveryClient discovery.DiscoveryInterface, dynamicClient dynamic.Interface, batteriesIncluded sets.Set[string], efs embed.FS, opts ...Option) error

Bootstrap creates resources in a package's fs by continuously retrying the list. This is blocking, i.e. it only returns (with error) when the context is closed or with nil when the bootstrapping is successfully completed.

func CreateGroupedResources added in v0.31.0

func CreateGroupedResources(ctx context.Context, client dynamic.Interface, mapper meta.RESTMapper, groups [][]*unstructured.Unstructured) error

CreateGroupedResources sequentially runs CreateResources for each group of resources.

func CreateResourceFromFS

func CreateResourceFromFS(ctx context.Context, client dynamic.Interface, mapper meta.RESTMapper, batteriesIncluded sets.Set[string], filename string, efs embed.FS, transformers ...TransformFileFunc) error

CreateResourceFromFS creates given resource file.

func CreateResources added in v0.31.0

func CreateResources(ctx context.Context, client dynamic.Interface, mapper meta.RESTMapper, resources []*unstructured.Unstructured) error

CreateResources creates all resources from a group of resources.

func CreateResourcesFromFS

func CreateResourcesFromFS(ctx context.Context, client dynamic.Interface, mapper meta.RESTMapper, batteriesIncluded sets.Set[string], efs embed.FS, transformers ...TransformFileFunc) error

CreateResourcesFromFS creates all resources from a filesystem.

func GroupObjectsByDefaultHierarchy added in v0.31.0

func GroupObjectsByDefaultHierarchy(objects []*unstructured.Unstructured) [][]*unstructured.Unstructured

GroupObjectsByDefaultHierarchy returns the given objects grouped by their hierarchy using DefaultWeights.

func GroupObjectsByHierarchy added in v0.31.0

func GroupObjectsByHierarchy(objects []*unstructured.Unstructured, weights []schema.GroupVersionKind) [][]*unstructured.Unstructured

GroupObjectsByHierarchy returns the given objects grouped by their hierarchy as determined by weights.

func ObjectWeight added in v0.31.0

func ObjectWeight(obj *unstructured.Unstructured, weights []schema.GroupVersionKind) int

ObjectWeight returns the weight of the object based on the given weights.

func ParseYAML added in v0.31.0

func ParseYAML(data []byte) ([]*unstructured.Unstructured, error)

ParseYAML parses the given YAML data into unstructured.Unstructured objects.

Taken from init-agent: https://github.com/kcp-dev/init-agent/blob/1e747d414a1bd2417b77bef845f8c68487428890/internal/manifest/yaml.go#L29-L54

func ReadRawFromFS added in v0.31.0

func ReadRawFromFS(
	ctx context.Context,
	embedFS embed.FS,
	filename string,
	transformers []TransformFileFunc,
	ti *TemplateInput,
) ([]byte, error)

ReadRawFromFS reads a file from the filesystem, applies the transformers and templates it.

func ReadResourceFromFS added in v0.31.0

func ReadResourceFromFS(
	ctx context.Context,
	embedFS embed.FS,
	filename string,
	transformers []TransformFileFunc,
	batteries sets.Set[string],
) ([]*unstructured.Unstructured, error)

ReadResourceFromFS uses ReadRawFromFS to read a file and returns it based on the batteries input as a slice of unstructured.Unstructured.

func ReadResourcesFromFS added in v0.31.0

func ReadResourcesFromFS(
	ctx context.Context,
	embedFS embed.FS,
	transformers []TransformFileFunc,
	batteries sets.Set[string],
) ([]*unstructured.Unstructured, error)

ReadResourcesFromFS calls ReadResourceFromFS for each file in the filesystem and returns an aggregation of all resources.

func SortObjectsByDefaultHierarchy added in v0.31.0

func SortObjectsByDefaultHierarchy(objects []*unstructured.Unstructured)

SortObjectsByDefaultHierarchy sorts the given objects using DefaultWeights.

func SortObjectsByHierarchy added in v0.31.0

func SortObjectsByHierarchy(objects []*unstructured.Unstructured, weights []schema.GroupVersionKind)

SortObjectsByHierarchy ensures that objects are (hopefully) sorted in an order that guarantees that they apply without errors and retrying for kcp relevant APIs.

Taken from init-agent: https://github.com/kcp-dev/init-agent/blob/1e747d414a1bd2417b77bef845f8c68487428890/internal/manifest/sort.go#L27-L60

func Template added in v0.31.0

func Template(ctx context.Context, raw []byte, input *TemplateInput) ([]byte, error)

Types

type Option

type Option struct {
	// TransformFileFunc is a function that transforms a resource file before being applied to the cluster.
	TransformFile TransformFileFunc
}

Option allows to customize the bootstrap process.

func ReplaceOption

func ReplaceOption(pairs ...string) Option

ReplaceOption allows to customize the bootstrap process.

type TemplateInput added in v0.31.0

type TemplateInput struct {
	Batteries map[string]bool
}

func NewTemplateInput added in v0.31.0

func NewTemplateInput(batteries sets.Set[string]) *TemplateInput

type TransformFileFunc

type TransformFileFunc func(bs []byte) ([]byte, error)

TransformFileFunc transforms a resource file before being applied to the cluster.

Jump to

Keyboard shortcuts

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