util

package
v0.0.0-...-5984036 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// AnalyticsMinionAddressKey is the annotation key used by Kelda commands to denote
	// what address should be used for updating analytics.
	AnalyticsMinionAddressKey = "analyticsMinionAddress"

	// AnalyticsNamespaceKey is the annotation key used to hardcode a analytics
	// namespace.
	AnalyticsNamespaceKey = "analyticsNamespace"

	// AnalyticsNamespaceEnvKey is the annotation key used to set the analytics
	// namespace to an environment variable that's read at runtime.
	AnalyticsNamespaceEnvKey = "analyticsNamespaceEnv"

	// UseInClusterKubeClientKey is the annotation used to make analytics look
	// up information via the in cluster client, rather than the user's Kelda
	// config.
	UseInClusterKubeClientKey = "useInClusterKubeClient"

	// ServiceNotExistsTemplate is an error message template shown when the
	// requested service doesn't exist.
	ServiceNotExistsTemplate = "Service %q does not exist. " +
		"Check the `kelda dev` UI for a list of possible service names."

	// ContextNotExistsTemplate is an error message template shown when the context
	// in the user configuration file doesn't exist.
	ContextNotExistsTemplate = "Context %q does not exist. Check the " +
		"output of `kubectl config get-contexts` for a list of possible contexts " +
		"and use `kelda config` to configure an available context."
)
View Source
const ClearProgress = "\033[2K\r"

ClearProgress clears the progress printer output so any errors are easier to read when they're printed to stdout. The `\033` character denotes the start of the control sequence, the `[2K` clears the text on the current line, and the `\r` moves the cursor back to the beginning of the line.

Variables

View Source
var (

	// ErrMultiplePodsRunning represents a failure to resolve a service to a
	// single pod because it has multiple pods running. This can happen when
	// Kubernetes is transitioning between Deployment versions, and hasn't
	// terminated the previous pod before starting the new one.
	ErrMultiplePodsRunning = errors.NewFriendlyError("Multiple pods are running.\n" +
		"This is likely because Kubernetes is transitioning between states, " +
		"and should resolve itself eventually.")

	// ErrMultiplePodsSpecified represents a failure to resolve a service to a
	// single pod because the service definition defines multiple pods. This
	// can happen when a service has multiple Deployments, or if the Deployment
	// has a Replicas count higher than one.
	ErrMultiplePodsSpecified = errors.NewFriendlyError("Service defines multiple pods, " +
		"which isn't supported by Kelda. To resolve, either:\n" +
		"- Contact your administrator to split the service up\n" +
		"- Or use `kubectl` directly.")

	// ErrMissingServiceName is used by commands that expect users to provide a
	// service name.
	ErrMissingServiceName = errors.NewFriendlyError("A service name is required. " +
		"Check the `kelda dev` UI for a list of possible " +
		"service names.")

	// ErrTooManyServices is used by commands that expect users to provide
	// exactly one service name.
	ErrTooManyServices = errors.NewFriendlyError("Only one service name at a time is supported.")
)

Functions

func GetKubeClient

func GetKubeClient(context string) (kubernetes.Interface, *rest.Config, error)

GetKubeClient creates a Kubernetes config and client for a given kubeconfig context.

func GetKubeConfig

func GetKubeConfig(context string) clientcmd.ClientConfig

GetKubeConfig parses the ClientConfig stored in the local system for `context`.

func HandleFatalError

func HandleFatalError(err error)

HandleFatalError handles errors that are severe enough to terminate the program.

func HandlePanic

func HandlePanic()

HandlePanic catches panics and logs them to analytics. It's meant to be invoked in a `defer` statement for goroutines that might panic.

func PromptYesOrNo

func PromptYesOrNo(prompt string) (bool, error)

PromptYesOrNo prompts the specified string and let the user choose whether they want or don't want to proceed.

func ResolvePodName

func ResolvePodName(kc keldaClientset.Interface,
	namespace, id string) (string, string, error)

ResolvePodName resolves a service name to a pod name.

Types

type ProgressPrinter

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

ProgressPrinter prints to the output every 2 seconds so that the user knows the application isn't stalled.

func NewProgressPrinter

func NewProgressPrinter(out io.Writer, msg string) ProgressPrinter

NewProgressPrinter creates a new ProgressPrinter.

func (ProgressPrinter) Run

func (pp ProgressPrinter) Run()

Run starts printing to the output.

func (ProgressPrinter) Stop

func (pp ProgressPrinter) Stop()

Stop stops printing to the output. After it returns, ProgressPrinter won't print anything more.

func (ProgressPrinter) StopWithPrint

func (pp ProgressPrinter) StopWithPrint(toPrint string)

StopWithPrint stops the progress printer and prints the supplied message to the output.

Jump to

Keyboard shortcuts

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