render

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package render implements composition rendering using composition functions.

Index

Constants

View Source
const (
	AnnotationKeyCompositionResourceName = "crossplane.io/composition-resource-name"
	AnnotationKeyCompositeName           = "crossplane.io/composite"
	AnnotationKeyClaimNamespace          = "crossplane.io/claim-namespace"
	AnnotationKeyClaimName               = "crossplane.io/claim-name"
)

Annotations added to composed resources.

View Source
const (
	// AnnotationKeyRuntimeDockerCleanup configures how a Function's Docker
	// container should be cleaned up once rendering is done.
	AnnotationKeyRuntimeDockerCleanup = "render.crossplane.io/runtime-docker-cleanup"

	// AnnotationKeyRuntimeDockerImage overrides the Docker image that will be
	// used to run the Function. By default render assumes the Function package
	// (i.e. spec.package) can be used to run the Function.
	AnnotationKeyRuntimeDockerImage = "render.crossplane.io/runtime-docker-image"
)

Annotations that can be used to configure the Docker runtime.

View Source
const AnnotationKeyRuntime = "render.crossplane.io/runtime"

AnnotationKeyRuntime can be added to a Function to control what runtime is used to run it locally.

View Source
const (
	// AnnotationKeyRuntimeDevelopmentTarget can be used to configure the gRPC
	// target where the Function is listening. The default is localhost:9443.
	AnnotationKeyRuntimeDevelopmentTarget = "render.crossplane.io/runtime-development-target"
)

Annotations that can be used to configure the Development runtime.

View Source
const AnnotationKeyRuntimeDockerPullPolicy = "render.crossplane.io/runtime-docker-pull-policy"

AnnotationKeyRuntimeDockerPullPolicy can be added to a Function to control how its runtime image is pulled.

Variables

This section is empty.

Functions

func LoadCompositeResource

func LoadCompositeResource(fs afero.Fs, file string) (*composite.Unstructured, error)

LoadCompositeResource from a YAML manifest.

func LoadComposition

func LoadComposition(fs afero.Fs, file string) (*apiextensionsv1.Composition, error)

LoadComposition form a YAML manifest.

func LoadExtraResources added in v1.15.0

func LoadExtraResources(fs afero.Fs, file string) ([]unstructured.Unstructured, error)

LoadExtraResources from a stream of YAML manifests.

func LoadFunctions

func LoadFunctions(filesys afero.Fs, file string) ([]pkgv1beta1.Function, error)

LoadFunctions from a stream of YAML manifests.

func LoadObservedResources

func LoadObservedResources(fs afero.Fs, file string) ([]composed.Unstructured, error)

LoadObservedResources from a stream of YAML manifests.

func LoadYAMLStream

func LoadYAMLStream(filesys afero.Fs, fileOrDir string) ([][]byte, error)

LoadYAMLStream from the supplied file or directory. Returns an array of byte arrays, where each byte array is expected to be a YAML manifest.

func LoadYAMLStreamFromFile

func LoadYAMLStreamFromFile(fs afero.Fs, file string) ([][]byte, error)

LoadYAMLStreamFromFile from the supplied file. Returns an array of byte arrays, where each byte array is expected to be a YAML manifest.

func PullImage

func PullImage(ctx context.Context, p pullClient, image string) error

PullImage pulls the supplied image using the supplied client. It blocks until the image has either finished pulling or hit an error.

func SetComposedResourceMetadata

func SetComposedResourceMetadata(cd resource.Object, xr resource.Composite, name string) error

SetComposedResourceMetadata sets standard, required composed resource metadata. It's a simplified version of the same function used by Crossplane. Notably it doesn't handle 'nested' XRs - it assumes the supplied XR should be treated as the top-level XR for setting the crossplane.io/composite, crossplane.io/claim-namespace, and crossplane.io/claim-name annotations.

https://github.com/crossplane/crossplane/blob/0965f0/internal/controller/apiextensions/composite/composition_render.go#L117

Types

type Cmd

type Cmd struct {
	// Arguments.
	CompositeResource string `arg:"" type:"existingfile" help:"A YAML file specifying the composite resource (XR) to render."`
	Composition       string `arg:"" type:"existingfile" help:"A YAML file specifying the Composition to use to render the XR. Must be mode: Pipeline."`
	Functions         string `` /* 126-byte string literal not displayed */

	// Flags. Keep them in alphabetical order.
	ContextFiles           map[string]string `` /* 129-byte string literal not displayed */
	ContextValues          map[string]string `` /* 155-byte string literal not displayed */
	IncludeFunctionResults bool              `` /* 127-byte string literal not displayed */
	IncludeFullXR          bool              `short:"x" help:"Include a direct copy of the input XR's spec and metadata fields in the rendered output."`
	ObservedResources      string            `` /* 139-byte string literal not displayed */
	ExtraResources         string            `` /* 147-byte string literal not displayed */
	IncludeContext         bool              `short:"c" help:"Include the context in the rendered output as a resource of kind: Context."`

	Timeout time.Duration `help:"How long to run before timing out." default:"1m"`
	// contains filtered or unexported fields
}

Cmd arguments and flags for render subcommand.

func (*Cmd) AfterApply

func (c *Cmd) AfterApply() error

AfterApply implements kong.AfterApply.

func (*Cmd) Help

func (c *Cmd) Help() string

Help prints out the help for the render command.

func (*Cmd) Run

func (c *Cmd) Run(k *kong.Context, logger logging.Logger) error

Run render.

type DockerCleanup

type DockerCleanup string

DockerCleanup specifies what Docker should do with a Function container after it has been run.

const (
	// AnnotationValueRuntimeDockerCleanupStop is the default. It stops the
	// container once rendering is done.
	AnnotationValueRuntimeDockerCleanupStop DockerCleanup = "Stop"

	// AnnotationValueRuntimeDockerCleanupOrphan leaves the container running
	// once rendering is done.
	AnnotationValueRuntimeDockerCleanupOrphan DockerCleanup = "Orphan"

	AnnotationValueRuntimeDockerCleanupDefault = AnnotationValueRuntimeDockerCleanupStop
)

Supported AnnotationKeyRuntimeDockerCleanup values.

func GetDockerCleanup

func GetDockerCleanup(fn pkgv1beta1.Function) (DockerCleanup, error)

GetDockerCleanup extracts Cleanup configuration from the supplied Function.

type DockerPullPolicy

type DockerPullPolicy string

DockerPullPolicy can be added to a Function to control how its runtime image is pulled by Docker.

const (
	// Always pull the image.
	AnnotationValueRuntimeDockerPullPolicyAlways DockerPullPolicy = "Always"

	// Never pull the image.
	AnnotationValueRuntimeDockerPullPolicyNever DockerPullPolicy = "Never"

	// Pull the image if it's not present.
	AnnotationValueRuntimeDockerPullPolicyIfNotPresent DockerPullPolicy = "IfNotPresent"

	AnnotationValueRuntimeDockerPullPolicyDefault DockerPullPolicy = AnnotationValueRuntimeDockerPullPolicyIfNotPresent
)

Supported pull policies.

func GetDockerPullPolicy

func GetDockerPullPolicy(fn pkgv1beta1.Function) (DockerPullPolicy, error)

GetDockerPullPolicy extracts PullPolicy configuration from the supplied Function.

type Inputs

type Inputs struct {
	CompositeResource *ucomposite.Unstructured
	Composition       *apiextensionsv1.Composition
	Functions         []pkgv1beta1.Function
	ObservedResources []composed.Unstructured
	ExtraResources    []unstructured.Unstructured
	Context           map[string][]byte
}

Inputs contains all inputs to the render process.

type Outputs

type Outputs struct {
	CompositeResource *ucomposite.Unstructured
	ComposedResources []composed.Unstructured
	Results           []unstructured.Unstructured
	Context           *unstructured.Unstructured
}

Outputs contains all outputs from the render process.

func Render

func Render(ctx context.Context, logger logging.Logger, in Inputs) (Outputs, error)

Render the desired XR and composed resources, sorted by resource name, given the supplied inputs.

type Runtime

type Runtime interface {
	// Start the Function.
	Start(ctx context.Context, logger logging.Logger) (RuntimeContext, error)
}

A Runtime runs a Function.

func GetRuntime

func GetRuntime(fn pkgv1beta1.Function) (Runtime, error)

GetRuntime for the supplied Function, per its annotations.

type RuntimeContext

type RuntimeContext struct {
	// Target for RunFunctionRequest gRPCs.
	Target string

	// Stop the running Function.
	Stop func(context.Context) error
}

RuntimeContext contains context on how a Function is being run.

type RuntimeDevelopment

type RuntimeDevelopment struct {
	// Target is the gRPC target for the running function, for example
	// localhost:9443.
	Target string
	// Function is the name of the function to be run.
	Function string
}

RuntimeDevelopment is largely a no-op. It expects you to run the Function manually. This is useful for developing Functions.

func GetRuntimeDevelopment

func GetRuntimeDevelopment(fn pkgv1beta1.Function) *RuntimeDevelopment

GetRuntimeDevelopment extracts RuntimeDevelopment configuration from the supplied Function.

func (*RuntimeDevelopment) Start

Start does nothing. It returns a Stop function that also does nothing.

type RuntimeDocker

type RuntimeDocker struct {
	// Image to run
	Image string

	// Stop container once rendering is done
	Stop bool

	// PullPolicy controls how the runtime image is pulled.
	PullPolicy DockerPullPolicy
}

RuntimeDocker uses a Docker daemon to run a Function.

func GetRuntimeDocker

func GetRuntimeDocker(fn pkgv1beta1.Function) (*RuntimeDocker, error)

GetRuntimeDocker extracts RuntimeDocker configuration from the supplied Function.

func (*RuntimeDocker) Start

func (r *RuntimeDocker) Start(ctx context.Context, logger logging.Logger) (RuntimeContext, error)

Start a Function as a Docker container.

type RuntimeType

type RuntimeType string

RuntimeType is a type of Function runtime.

const (
	// The Docker runtime uses a Docker daemon to run a Function. It uses the
	// standard DOCKER_ environment variables to determine how to connect to the
	// daemon.
	AnnotationValueRuntimeDocker RuntimeType = "Docker"

	// The Development runtime expects you to deploy a Function locally. This is
	// mostly useful when developing a Function. The Function must be running
	// with the --insecure flag, i.e. without transport security.
	AnnotationValueRuntimeDevelopment RuntimeType = "Development"

	AnnotationValueRuntimeDefault = AnnotationValueRuntimeDocker
)

Supported runtimes.

Jump to

Keyboard shortcuts

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