util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderComment    = []byte("# Generated by \"kubeapply expand\". DO NOT EDIT.\n")
	HeaderCommentStr = string(HeaderComment)
)

Functions

func AddHeaders

func AddHeaders(root string) error

AddHeaders adds a comment header to all yaml files in the argument path.

func ApplyTemplate

func ApplyTemplate(
	dir string,
	data interface{},
	deleteSources bool,
	strict bool,
) error

ApplyTemplate runs golang templating on all files in the provided path, replacing them in-place with their templated versions.

func CloneRepo

func CloneRepo(ctx context.Context, url string, ref string, path string) error

CloneRepo makes a shallow clone of the argument repo at a single ref.

See https://stackoverflow.com/questions/3489173/how-to-clone-git-repository-with-specific-revision-changeset for a discussion of the commands run.

func CompareJSONObjs

func CompareJSONObjs(t *testing.T, exp kruntime.Object, actual kruntime.Object)

CompareJSONObjs compares two objects via their JSON representations. This is much easier to debug that comparing the objects directly.

func CreateNamespace

func CreateNamespace(
	ctx context.Context,
	t *testing.T,
	namespace string,
	kubeconfig string,
)

CreateNamespace creates a namespace in a test cluster.

func DeleteNamespace

func DeleteNamespace(
	ctx context.Context,
	t *testing.T,
	namespace string,
	kubeconfig string,
)

DeleteNamespace deletes a namespace in a test cluster.

func DirExists

func DirExists(path string) (bool, error)

DirExists returns whether the given path exists and is a directory.

func FileExists

func FileExists(path string) (bool, error)

FileExists returns whether the given path exists and is a file.

func GetResources

func GetResources(
	ctx context.Context,
	t *testing.T,
	kind string,
	namespace string,
	kubeconfig string,
) []apply.TypedKubeObj

GetResources gets the objects with the given kind in the argument namespace.

func GetSSMValue

func GetSSMValue(
	ctx context.Context,
	sess *session.Session,
	ssmKeyName string,
) (string, error)

GetSSMValue gets a secret value from AWS SSM.

func KindEnabled

func KindEnabled() bool

KindEnabled returns whether testing with kind is enabled. This is generally true locally but false in CI (for now).

func ParseS3URL

func ParseS3URL(url string) (string, string, error)

ParseS3URL splits an s3 url into its bucket and key.

func RecursiveCopy

func RecursiveCopy(srcDir string, destDir string) error

RecursiveCopy does a recursive copy from the source directory to the destination one.

func RemoveDirs

func RemoveDirs(rootDir string, indicatorName string) error

RemoveDirs removes all directories that contain a file with the specified indicatorName (e.g., ".noexpand"). This is used to prune directories that are used for templating/generation but are not valid kube configs.

func RestoreData

func RestoreData(
	ctx context.Context,
	rootDir string,
	url string,
	destDir string,
) error

RestoreData generates a local version of the resource(s) at the argument URL. Currently, it supports the schemes "file://", "http://", "https://", "git://", "git-https://", and "s3://".

If there is no scheme, then "file://" is assumed.

In the http(s) and s3 cases, the url must refer to an archive. In the file case, it can refer to either an archive or a directory.

The rootDir argument is used in the file case as the base for relative file URLs. It is unused in other cases.

func RunCmdWithPrinters

func RunCmdWithPrinters(
	ctx context.Context,
	command string,
	args []string,
	extraEnv []string,
	blockedEnv map[string]struct{},
	stdoutPrinter Printer,
	stderrPrinter Printer,
) error

RunCmdWithPrinters runs a command with output streamed via custom printer functions. Adapted from example in https://github.com/golang/go/issues/19685#issuecomment-288949629.

func WriteFiles

func WriteFiles(t *testing.T, baseDir string, files map[string]string)

WriteFiles takes a map of paths to file contents and uses this to write out files to the file system.

Types

type Printer

type Printer func(input string)

Printer is a function that prints out a string, e.g. to stdout.

func LogrusDebugPrinter

func LogrusDebugPrinter(prefix string) Printer

LogrusDebugPrinter returns a printer that prints via logrus at the debug level.

func LogrusInfoPrinter

func LogrusInfoPrinter(prefix string) Printer

LogrusInfoPrinter returns a printer that prints via logrus at the info level.

func LogrusWarnPrinter

func LogrusWarnPrinter(prefix string) Printer

LogrusWarnPrinter returns a printer that prints via logrus at the warn level.

Jump to

Keyboard shortcuts

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