util

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON is a constant for the application type of requests.
	ContentTypeJSON = "application/json"

	// FilePermUserGroup value of permissions user and group all permissions
	FilePermUserGroup = 0o770

	// Docker scheme is the scheme we use to identify docker images
	DockerScheme = "docker"
)
View Source
const (

	// Debug indicates debug verbosity level
	Debug = 1
)

Variables

This section is empty.

Functions

func DeferIgnoreError

func DeferIgnoreError(f func() error)

DeferIgnoreError is a helper function to ignore errors returned by functions called with defer.

func FindYamlFiles

func FindYamlFiles(root string) ([]string, error)

FindYamlFiles locates all the YAML files in some root. symlinks are evaluated Files are deduped (e.g. a symlink and its source will not be included twice if they are both in root).

func IgnoreError

func IgnoreError(err error)

IgnoreError is a helper function to deal with errors.

func IsDockerURI added in v0.0.3

func IsDockerURI(uri string) bool

func LogFromContext added in v0.0.2

func LogFromContext(ctx context.Context) logr.Logger

LogFromContext returns a logr.Logger from the context or an instance of the global logger

func MyCaller

func MyCaller() string

MyCaller returns the caller of the Function in the form ${package}/${file}:${linenumber} e.g. file: somemodule/cmd/parent.go

func parent() {
  child()
}

file: somemodule/cmd/child.go

func child() {
  c := util.MyCaller()
}

The value of c will be "cmd/parent.go:2"

This is useful when you have common error handlers that want to log the location that invoked them.

The function doesn't return the full path of the code because this would be the full path on the machine where it was compiled which isn't useful.

func PrettyString

func PrettyString(v interface{}) string

PrettyString returns a prettily formatted string of the object.

func ReadYaml

func ReadYaml(path string) ([]*yaml.RNode, error)

ReadYaml reads the specified path and returns an RNode. This is useful for filtering by KRM type.

func SetKustomizeImage

func SetKustomizeImage(k *kustomize.Kustomization, name string, resolved DockerImageRef) error

SetKustomizeImage sets the specified image in the kustomization.

func SetupLogger

func SetupLogger(level string, devLogger bool) logr.Logger

SetupLogger performs common setup of a logger.

func UniqueStrings

func UniqueStrings(strings []string) []string

UniqueStrings takes a list of strings and returns a list with unique strings.

func VerbosityDescription

func VerbosityDescription() string

VerbosityDescription returns a string to be used as the description for verbosity flags.

Types

type CmdSetter

type CmdSetter func(cmd *exec.Cmd)

CmdSetter is an interface for setting commands.

type DockerImageRef

type DockerImageRef struct {
	Registry string
	Repo     string
	Tag      string
	// NB sha should be of the form "sha256:1234..." otherwise ToURL won't return a proper URL
	Sha string
}

DockerImageRef defines the various pieces of a docker image

func ParseImageURL

func ParseImageURL(url string) (*DockerImageRef, error)

ParseImageURL parses the URL refering to a docker image

TODO(jeremy): We should support shas as well TODO(jeremy): Should we support optionally having a scheme of DockerScheme?

func (*DockerImageRef) GetAwsRegistryID

func (d *DockerImageRef) GetAwsRegistryID() string

GetAwsRegistryID returns the registry ID or "" if there isn't one

func (*DockerImageRef) ToURL

func (d *DockerImageRef) ToURL() string

ToURL returns the full image URL.

type ExecHelper

type ExecHelper struct {
	Log logr.Logger
}

ExecHelper is a wrapper for executing shell commands.

func (*ExecHelper) Run

func (h *ExecHelper) Run(cmd *exec.Cmd) error

Run runs and logs stdout/stderr

func (*ExecHelper) RunCommands

func (h *ExecHelper) RunCommands(commands [][]string, setter CmdSetter) error

RunCommands runs multiple commands. CmdSetter is a function to configure the command.

func (*ExecHelper) RunQuietly

func (h *ExecHelper) RunQuietly(cmd *exec.Cmd) (string, error)

RunQuietly runs without logging stdout/stderr. Use this method when you want to let the caller decide whether to log or not. A common use case would be when commands failing to run doesn't necessarily indicate an error.

type ListOfErrors

type ListOfErrors struct {
	Causes []error
	Final  error
}

ListOfErrors is used when we want to return more then one error. This happens when we want to keep going and accumulate errors

func (*ListOfErrors) AddCause

func (l *ListOfErrors) AddCause(e error)

AddCause adds an error to the list.

func (*ListOfErrors) Error

func (l *ListOfErrors) Error() string

Error returns a single error wrapping all the errors.

Jump to

Keyboard shortcuts

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