jpl

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 40 Imported by: 1

Documentation

Index

Constants

View Source
const CustomResourceDefinitionName = "CustomResourceDefinition"
View Source
const (
	StdinToken = "-"
)

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error, msg string)

CheckError default error handling function

func Cleanup

func Cleanup(clients *K8sClients, namespace string, resources []Resource) error

Cleanup removes the resources no longer deployed and updates the secret in the cluster with the updated set of resources

func CreateFile

func CreateFile(path string) (afero.File, error)

CreateFile create a new file in path

func CreateResource

func CreateResource(gvr schema.GroupVersionResource, clients *K8sClients, res Resource) error

CreateResource handles the creation of a k8s resource when not already present on the cluster

func Deploy

func Deploy(clients *K8sClients, namespace string, resources []Resource, deployConfig DeployConfig, supportedResourcesGetter SupportedResourcesGetter, apply ApplyFunction) error

Deploy ensures namespace existence and applies the resources to the cluster

func ExtractYAMLFiles

func ExtractYAMLFiles(paths []string) ([]string, error)

ExtractYAMLFiles return array of YAML filenames from array of files and directories

func GetChecksum

func GetChecksum(content []byte) string

GetChecksum is used to calculate a checksum using an array of bytes

func GetMiaAnnotation

func GetMiaAnnotation(name string) string

GetMiaAnnotation is used to get an annotation name following a pattern used in mia-platform

func GetResource

func GetResource(gvr schema.GroupVersionResource, clients *K8sClients, res Resource) (*unstructured.Unstructured, error)

GetResource returns the identified resource if present on the cluster if the resource does not exist, returns a NotFound error

func IsNotUsingSemver

func IsNotUsingSemver(target *Resource) (bool, error)

IsNotUsingSemver is used to check if a resoure is following semver or not

func ListResources

ListResources returns the list of resources with the given GVR across all namespaces. If no resource exists, returns a NotFound error

func MakeResources

func MakeResources(filePaths []string, namespace string, clients *K8sClients) ([]Resource, []Resource, error)

MakeResources takes a filepath/buffer. It returns two arrays of resources, respectively for CRDs and other kinds, to allow the implementation of the 2-step apply.

func MkdirAll

func MkdirAll(name string) error

MkdirAll create a folder

func NewResourcesFromBuffer

func NewResourcesFromBuffer(stream []byte) ([]Resource, []Resource, error)

NewResourcesFromBuffer exposes the createResourcesFromBuffer function setting the filepath to "buffer"

func NewResourcesFromFile

func NewResourcesFromFile(filepath string) ([]Resource, []Resource, error)

NewResourcesFromFile creates new Resources from a file at `filepath`. It returns two arrays of resources, respectively for CRDs and other kinds, to allow the implementation of the 2-step apply. Supports multiple documents inside a single file

func PatchResource

func PatchResource(gvr schema.GroupVersionResource, clients *K8sClients, res Resource, onClusterObj *unstructured.Unstructured) error

PatchResource patches a resource that already exists on the cluster and needs to be updated

func ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile read a file from the file system

func RemoveAll

func RemoveAll(path string) error

RemoveAll removes a directory path and any children it contains.

func WriteFile

func WriteFile(filename string, data []byte) error

WriteFile write data to file

func WriteYamlsToDisk

func WriteYamlsToDisk(objs map[string]runtime.Object, outputDirectory string)

WriteYamlsToDisk marshals and writes kubernetes runtime objects to YAML file

Types

type ApplyFunction

type ApplyFunction func(clients *K8sClients, res Resource, deployConfig DeployConfig) error

func DecorateApplyFunction

func DecorateApplyFunction(apply ApplyFunction, decorators ...func(ApplyFunction) ApplyFunction) ApplyFunction

DecorateApplyFunction allows to generate an apply function with a generic number of decorators before calling the actual apply

func DecorateDefaultApplyFunction

func DecorateDefaultApplyFunction(decorators ...func(ApplyFunction) ApplyFunction) ApplyFunction

DecorateDefaultApplyFunction allows to decorate the default apply function

type DeployConfig

type DeployConfig struct {
	DeployType              string
	ForceDeployWhenNoSemver bool
	EnsureNamespace         bool
}

DeployConfig are all the specific configurations used in deploy phase

type K8sClients

type K8sClients struct {
	// contains filtered or unexported fields
}

func FakeK8sClients

func FakeK8sClients() *K8sClients

FakeK8sClients returns a struct of fake k8s clients for testing purposes

func InitRealK8sClients

func InitRealK8sClients(opts *Options) *K8sClients

InitRealK8sClients initializes a K8sClients struct from given CLI options, to be used for the deployment process

type Options

type Options struct {
	Config *genericclioptions.ConfigFlags

	CertificateAuthority  string
	ClientCertificate     string
	ClientKey             string
	Cluster               string
	Context               string
	Kubeconfig            string
	InsecureSkipTLSVerify bool
	Namespace             string
	Server                string
	Token                 string
	User                  string
}

Options global option struct

func NewOptions

func NewOptions() *Options

NewOptions create a new options struct

type RealSupportedResourcesGetter

type RealSupportedResourcesGetter struct{}

RealSupportedResourcesGetter is a type to identify the real getter function for the supported resources dictionary

func (RealSupportedResourcesGetter) GetSupportedResourcesDictionary

func (supportedResourcesGetter RealSupportedResourcesGetter) GetSupportedResourcesDictionary(discovery discovery.DiscoveryInterface) (map[schema.GroupVersionKind]metav1.APIResource, error)

GetSupportedResourcesDictionary exposes the getSupportedResourcesDictionary function for the real getter

type Resource

type Resource struct {
	Filepath         string
	GroupVersionKind *schema.GroupVersionKind
	Object           unstructured.Unstructured
	Namespaced       ResourceNamespace
}

func SortResourcesByKind

func SortResourcesByKind(resources []Resource, ordering resourceOrder) []Resource

SortResourcesByKind Results are sorted by 'ordering', keeping order of items with equal kind/priority

type ResourceList

type ResourceList struct {
	Kind      *schema.GroupVersionKind `json:"kind"`
	Resources []string                 `json:"resources"`
}

type ResourceNamespace added in v0.1.1

type ResourceNamespace int8
const (
	None ResourceNamespace = iota
	True
	False
)

type SupportedResourcesGetter

type SupportedResourcesGetter interface {
	GetSupportedResourcesDictionary(discovery discovery.DiscoveryInterface) (map[schema.GroupVersionKind]metav1.APIResource, error)
}

SupportedResourcesGetter is a type for handling real and mock dictionaries of supported resources

Jump to

Keyboard shortcuts

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