utils

package
v0.0.0-...-4c20933 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClusterChecks = []Checker{
	kernelVersionCheck,
	clusterTypeIsSupported,
	k8sVersionCheck,
	hasKubectlCheck,
	userCanCreateNamespace,
}

DefaultClusterChecks is a list of cluster that are performed by default.

View Source
var ExtraClusterChecks = []Checker{
	allowListClusterCheck,
}

ExtraClusterChecks is a list of checks for the cluster that are not required for deployment, but are highly recommended.

Functions

func EnsureDefaultAuthFilePath

func EnsureDefaultAuthFilePath() (string, error)

EnsureDefaultAuthFilePath returns the file path for the auth file.

func EnsureDefaultConfigFilePath

func EnsureDefaultConfigFilePath() (string, error)

EnsureDefaultConfigFilePath returns the file path for the config file.

func Error

func Error(str string)

Error prints the input string to stderr.

func Errorf

func Errorf(format string, args ...interface{})

Errorf prints the input string to stderr formatted with the input args.

func ExecCommand

func ExecCommand(name string, args ...string) error

ExecCommand runs a command and returns stderr as the error.

func Fatal

func Fatal(str string)

Fatal prints the input string to stderr.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf prints the input string to stderr formatted with the input args.

func GetCloudClientConnection

func GetCloudClientConnection(cloudAddr string) (*grpc.ClientConn, error)

GetCloudClientConnection gets the GRPC connection based on the cloud addr.

func Info

func Info(str string)

Info prints the input string to stdout.

func Infof

func Infof(format string, args ...interface{})

Infof prints the input string to stdout formatted with the input args.

func RunClusterChecks

func RunClusterChecks(checks []Checker) error

RunClusterChecks will run a list of checks and print out their results. The first error is returned, but we continue to run all checks.

func RunDefaultClusterChecks

func RunDefaultClusterChecks() error

RunDefaultClusterChecks runs the default configured checks.

func RunExtraClusterChecks

func RunExtraClusterChecks() error

RunExtraClusterChecks runs the extra configured checks.

func VersionCompatible

func VersionCompatible(version string, minVersion string) (bool, error)

VersionCompatible checks to make sure version >= minVersion as per semver.

func WithSignalCancellable

func WithSignalCancellable(ctx context.Context) (context.Context, func())

WithSignalCancellable returns a context that will automatically be cancelled when Ctrl+C is pressed.

Types

type CLIOutputEntry

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

CLIOutputEntry represents an output log entry.

func WithColor

func WithColor(c *color.Color) *CLIOutputEntry

WithColor returns a struct that can be used to log text to the CLI in a specific color.

func WithError

func WithError(err error) *CLIOutputEntry

WithError returns a struct that can be used to log text to the CLI with a specific error.

func (*CLIOutputEntry) Error

func (c *CLIOutputEntry) Error(str string)

Error prints the input string to stderr.

func (*CLIOutputEntry) Errorf

func (c *CLIOutputEntry) Errorf(format string, args ...interface{})

Errorf prints the input string to stderr formatted with the input args.

func (*CLIOutputEntry) Fatal

func (c *CLIOutputEntry) Fatal(str string)

Fatal prints the input string to stderr.

func (*CLIOutputEntry) Fatalf

func (c *CLIOutputEntry) Fatalf(format string, args ...interface{})

Fatalf prints the input string to stderr formatted with the input args.

func (*CLIOutputEntry) Info

func (c *CLIOutputEntry) Info(str string)

Info prints the input string to stdout.

func (*CLIOutputEntry) Infof

func (c *CLIOutputEntry) Infof(format string, args ...interface{})

Infof prints the input string to stdout formatted with the input args.

func (*CLIOutputEntry) WithColor

func (c *CLIOutputEntry) WithColor(textColor *color.Color) *CLIOutputEntry

WithColor returns a struct that can be used to log text to the CLI in a specific color.

func (*CLIOutputEntry) WithError

func (c *CLIOutputEntry) WithError(err error) *CLIOutputEntry

WithError returns a struct that can be used to log text to the CLI with a specific error.

type Checker

type Checker interface {
	// Returns the name of the Checker.
	Name() string
	// Checker returns nil for pass, or error.
	Check() error
}

Checker is a named check.

func NamedCheck

func NamedCheck(name string, check func() error) Checker

NamedCheck is used to easily create a Checker with a name.

type ClusterType

type ClusterType int

ClusterType represents all possible types of a K8s cluster.

const (
	// ClusterTypeUnknown is an unknown cluster type.
	ClusterTypeUnknown ClusterType = iota
	// ClusterTypeGKE is a GKE cluster.
	ClusterTypeGKE
	// ClusterTypeEKS is an EKS cluster.
	ClusterTypeEKS
	// ClusterTypeAKS is an AKS cluster.
	ClusterTypeAKS
	// ClusterTypeKind is a kind cluster.
	ClusterTypeKind
	// ClusterTypeDockerDesktop is a Docker for Desktop cluster.
	ClusterTypeDockerDesktop
	// ClusterTypeMinikubeKVM2 is a minikube cluster running with the kvm2 driver.
	ClusterTypeMinikubeKVM2
	// ClusterTypeMinikubeHyperkit is a minikube cluster running with the hyperkit driver.
	ClusterTypeMinikubeHyperkit
	// ClusterTypeMinikubeOther is a minikube cluster running with a driver not specified in
	// the other enums.
	ClusterTypeMinikubeOther
	// ClusterTypeK0s is a k0s cluster.
	ClusterTypeK0s
	// ClusterTypeK3s is a k3s cluster.
	ClusterTypeK3s
)

type ParallelTaskRunner

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

ParallelTaskRunner runs tasks in parallel and displays them in a table.

func NewParallelTaskRunner

func NewParallelTaskRunner(tasks []Task) *ParallelTaskRunner

NewParallelTaskRunner creates a new ParallelTaskRunner

func (*ParallelTaskRunner) RunAndMonitor

func (s *ParallelTaskRunner) RunAndMonitor() error

RunAndMonitor runs tasks and shows output in a table.

type SerialTaskRunner

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

SerialTaskRunner runs tasks in serial and displays them in a table.

func NewSerialTaskRunner

func NewSerialTaskRunner(tasks []Task) *SerialTaskRunner

NewSerialTaskRunner creates a new SerialTaskRunner

func (*SerialTaskRunner) RunAndMonitor

func (s *SerialTaskRunner) RunAndMonitor() error

RunAndMonitor runs tasks and shows output in a table.

type Task

type Task interface {
	Name() string
	Run() error
}

Task is an entity that can be run.

Jump to

Keyboard shortcuts

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