resource

package
v0.0.0-...-921a65a Latest Latest
Warning

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

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

Documentation

Overview

Package resource contains logic related to Kubernetes resource objects.

Index

Constants

View Source
const AggregatedFilename = "aggregated-resources.yaml"

AggregatedFilename is the filename for the file created by SaveAsConfigs.

Variables

This section is empty.

Functions

func AddAnnotation

func AddAnnotation(obj *Object, key, value string) error

AddAnnotation updates an object to add an annotation with the key and value provided.

func AddLabel

func AddLabel(ctx context.Context, obj *Object, key, value string, override bool) error

AddLabel updates an object to add a label with the key and value provided.

func AddNamespaceIfMissing

func AddNamespaceIfMissing(objs Objects, namespace string) error

AddNamespaceIfMissing updates all objects to add a namespace only if the object does not have one already.

func DeploySummary

func DeploySummary(ctx context.Context, objs Objects) (string, error)

DeploySummary returns a string representation of a summary of a list of objects' deploy statuses.

func EncodeToYAMLString

func EncodeToYAMLString(obj *Object) (string, error)

EncodeToYAMLString encodes an object from *Object to a string.

func HasObject

func HasObject(ctx context.Context, objs Objects, kind, name string) (bool, error)

HasObject returns true if there exists an object in objs that matches the provided kind and name.

func IsReady

func IsReady(ctx context.Context, obj *Object) (bool, error)

IsReady returns true if a deployed object is ready. Please check the comments of each kind's implementation for a description of what is considered to be ready for that kind of object.

func ObjectKind

func ObjectKind(obj *Object) string

ObjectKind returns the kind of an object.

func ObjectName

func ObjectName(obj *Object) (string, error)

ObjectName returns the name of an object.

func ObjectNamespace

func ObjectNamespace(obj *Object) (string, error)

ObjectNamespace returns the namespace of an object.

func SaveAsConfigs

func SaveAsConfigs(ctx context.Context, objs Objects, outputDir string, lineComments map[string]string, oss services.OSService) (string, error)

SaveAsConfigs saves resource objects as config files to a target output directory. If any lines in a resource object's string representation contain a key in lineComments, the corresponding value will be added as a comment at the end of the line. The string being returned is the path of the saved file.

func SetApplicationLinks(obj *Object, links []applicationsv1beta1.Link) error

SetApplicationLinks sets a list of links to an Application object's spec.descriptor.links field.

func UpdateMatchingContainerImage

func UpdateMatchingContainerImage(ctx context.Context, objs Objects, imageName, replace string) error

UpdateMatchingContainerImage updates all objects that have container images matching the provided image name with the provided replacement string.

func UpdateNamespace

func UpdateNamespace(ctx context.Context, objs Objects, replace string) error

UpdateNamespace updates all objects to change its namespace to the provided namespace. Objects that do not have a namespace field will also be updated to have a namespace field.

Types

type Object

type Object struct {
	*unstructured.Unstructured
}

Object extends unstructured.Unstructured, which implements runtime.Object

func CreateApplicationObject

func CreateApplicationObject(name, selectorKey, selectorValue, descriptorType, descriptorVersion string, componentObjs Objects) (*Object, error)

CreateApplicationObject creates an Application CR object with the given name and fields. appVersion may be empty, in which case the resulting Application CR will not have a value for spec.descriptor.version. To add links, to the Application, use the SetApplicationLinks function on the output object,

func CreateDeploymentObject

func CreateDeploymentObject(ctx context.Context, name string, selectorValue, image string) (*Object, error)

CreateDeploymentObject creates a Deployment object with the given name and image. The created Deployment will have 3 replicas.

func CreateHorizontalPodAutoscalerObject

func CreateHorizontalPodAutoscalerObject(ctx context.Context, name, deploymentName string) (*Object, error)

CreateHorizontalPodAutoscalerObject creates a Namespace object with the given name. The created HorizontalPodAutoscaler will have minReplicas set to 1, maxReplicas set to 5, and a cpu targetAverageUtilization of 80.

func CreateNamespaceObject

func CreateNamespaceObject(ctx context.Context, name string) (*Object, error)

CreateNamespaceObject creates a Namespace object with the given name.

func CreateServiceObject

func CreateServiceObject(ctx context.Context, name, selectorKey, selectorValue string, port int) (*Object, error)

CreateServiceObject creates a Service object with the given name with service type LoadBalancer.

func DecodeFromYAML

func DecodeFromYAML(ctx context.Context, yaml []byte) (*Object, error)

DecodeFromYAML decodes an object from a YAML string as bytes.

func (*Object) String

func (obj *Object) String() string

String returns a string representation of an object.

type Objects

type Objects []*Object

Objects maps resource file base names to corresponding resource objects (mutable).

func ParseConfigs

func ParseConfigs(ctx context.Context, configs string, oss services.OSService, recursive bool) (Objects, error)

ParseConfigs parses resource objects from a file or directory of files into a map that maps unique file base names to the parsed objects.

func (Objects) String

func (objs Objects) String() string

String returns a string representation of objects.

Jump to

Keyboard shortcuts

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