util

package
v0.0.0-...-2caf503 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const LabelFilterKeySubstring = "giantswarm.io"

LabelFilterKeySubstring is the substring used to hide giantswarm labels

Variables

View Source
var CouldNotSetKubectlClusterError = &microerror.Error{
	Kind: "CouldNotSetKubectlClusterError",
	Desc: "could not set cluster using 'kubectl config set-cluster'",
}

CouldNotSetKubectlClusterError is used if kubectl config set-cluster could not be executed.

View Source
var CouldNotSetKubectlContextError = &microerror.Error{
	Kind: "CouldNotSetKubectlContextError",
	Desc: "could not set context using 'kubectl config set-context'",
}

CouldNotSetKubectlContextError is used when kubectl config set-context could not be executed.

View Source
var CouldNotSetKubectlCredentialsError = &microerror.Error{
	Kind: "CouldNotSetKubectlCredentialsError",
	Desc: "could not set credentials using 'kubectl config set-credentials'",
}

CouldNotSetKubectlCredentialsError is used when kubectl config set-credentials could not be executed.

View Source
var CouldNotUseKubectlContextError = &microerror.Error{
	Kind: "CouldNotUseKubectlContextError",
	Desc: "could not apply context using 'kubectl config set-context'",
}

CouldNotUseKubectlContextError is used when kubectl config use-context could not be executed.

View Source
var DurationExceededError = &microerror.Error{
	Kind: "DurationExceededError",
}

DurationExceededError is thrown when a duration value is larger than can be represented internally

View Source
var InvalidDurationStringError = &microerror.Error{
	Kind: "InvalidDurationStringError",
}

InvalidDurationStringError is used when a duration string given by the user could not be parsed.

Functions

func CheckKubectl

func CheckKubectl() bool

CheckKubectl checks if kubectl exists, is silent if yes, prints error and exits if not

func CompareVersions

func CompareVersions(v1 string, v2 string) (int, error)

CompareVersions compres to semver version strings v1 and v2. Returned result: - if v1 is greater than v2: 1 - if v1 is equal to v2: 0 if v1 is smaller than v2: -1

func DurationPhrase

func DurationPhrase(hours int) string

DurationPhrase creates a human-friendly phrase from a number of hours expressing a duration, like "3 days, 2 hours". Precision of output is limited in favour of readability.

func GetBashCompletionFn

func GetBashCompletionFn(fName, fBody string) string

GenBashCompletionFn generates a bash function that can be used for auto-completion of command-line commands or flags

func GetCustomCommandCompletionFnBody

func GetCustomCommandCompletionFnBody() string

GetCustomCommandCompletionFnBody returns the global custom command-line completion function body

func GetDeprecatedNotice

func GetDeprecatedNotice(provider, gsctlCmd, kubectlgsCmd, docsURL string) string

func IsCouldNotSetKubectlClusterError

func IsCouldNotSetKubectlClusterError(err error) bool

IsCouldNotSetKubectlClusterError asserts CouldNotSetKubectlClusterError.

func IsCouldNotSetKubectlContextError

func IsCouldNotSetKubectlContextError(err error) bool

IsCouldNotSetKubectlContextError asserts CouldNotSetKubectlContextError.

func IsCouldNotSetKubectlCredentialsError

func IsCouldNotSetKubectlCredentialsError(err error) bool

IsCouldNotSetKubectlCredentialsError asserts CouldNotSetKubectlClusterError.

func IsCouldNotUseKubectlContextError

func IsCouldNotUseKubectlContextError(err error) bool

IsCouldNotUseKubectlContextError asserts CouldNotUseKubectlContextError.

func IsDurationExceededError

func IsDurationExceededError(err error) bool

IsDurationExceededError asserts DurationExceededError

func IsInvalidDurationStringError

func IsInvalidDurationStringError(err error) bool

IsInvalidDurationStringError asserts InvalidDurationStringError.

func KubectlSetCluster

func KubectlSetCluster(clusterID, apiEndpoint, caCertificatePath string) error

KubectlSetCluster is a wrapper for the `kubectl config set-cluster` command

func KubectlSetContext

func KubectlSetContext(contextName, clusterID string) error

KubectlSetContext is a wrapper for the `kubectl config set-context` command

func KubectlSetCredentials

func KubectlSetCredentials(clusterID, keyPath, certificatePath string) error

KubectlSetCredentials is a wrapper for the `kubectl config set-credentials` command

func KubectlUseContext

func KubectlUseContext(contextName string) error

KubectlUseContext applies the context for the given cluster ID

func ParseDate

func ParseDate(dateString string) time.Time

ParseDate parses our common date/time strings and returns a time.Time object

func ParseDuration

func ParseDuration(durationString string) (time.Duration, error)

ParseDuration converts strings like "1d" into a duration. Only one combination of <number> and <unit> is allowed, and the unit must be one of: - "h" - one hour - "d" - day (24 hours) - "w" - 7 days - "m" - 30 days - "y" - 365 days

This is necessary because time.ParseDuration does not support units larger than hour.

func RegisterBashCompletionFn

func RegisterBashCompletionFn(command *cobra.Command, fName, fBody string)

RegisterBashCompletionFn adds a custom completion function to the root command config

func SetCommandBashCompletion

func SetCommandBashCompletion(completionFn *BashCompletionFunc)

SetCommandBashCompletion adds functionality to the global custom command-line completion function

Due to `cobra` limitations, this is currently the only way of adding auto-completion for commands

func SetFlagBashCompletionFn

func SetFlagBashCompletionFn(completionFn *BashCompletionFunc)

SetFlagBashCompletionFn sets a custom completion function for a given command-line flag

func ShortDate

func ShortDate(date time.Time) string

ShortDate reformats a time.Time to a short date

func StoreCaCertificate

func StoreCaCertificate(fs afero.Fs, certsDirPath, clusterID, data string) string

StoreCaCertificate writes a CA certificate to a file

The file will have the name format `<clusterID>-ca.crt`

func StoreClientCertificate

func StoreClientCertificate(fs afero.Fs, certsDirPath, clusterID, keyPairID, data string) string

StoreClientCertificate writes a client certificate to a file

The file will have the name format `<clusterID>-<keypair-id>-client.crt`

func StoreClientKey

func StoreClientKey(fs afero.Fs, certsDirPath, clusterID, keyPairID, data string) string

StoreClientKey writes a client key to a file

The file will have the name format `<clusterID>-<keypair-id>-client.key`

func Truncate

func Truncate(str string, length int, doTruncate bool) string

Truncate takes a string and truncates it (if doTruncate is true)

func VersionSortComp

func VersionSortComp(v1, v2 string) bool

VersionSortComp is a comparison function usable with the sort.Slice API

Types

type BashCompletionFunc

type BashCompletionFunc struct {
	Command  *cobra.Command
	Flags    *pflag.FlagSet
	FlagName string
	FnName   string
	FnBody   string
}

Jump to

Keyboard shortcuts

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