util

package
v0.0.0-...-02c6b06 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const SymbolOffset = " "

SymbolOffset is the offset that the symbol is prefixed for better readability

Variables

This section is empty.

Functions

func CheckDockerImageExists

func CheckDockerImageExists(image, tag string) error

CheckDockerImageExists checks if a docker image exists

func CompletedRun

func CompletedRun(phase argov1.WorkflowPhase) bool

CompletedRun checks if the testrun is in a completed phase

func CompletedStep

func CompletedStep(phase argov1.NodePhase) bool

CompletedStep checks if the teststep is in a completed phase

func ContainsCloudprovider

func ContainsCloudprovider(cloudproviders []common.CloudProvider, cloudprovider common.CloudProvider) bool

ContainsCloudprovider checks whether a cloudprovier is part of an array of cloudproviders

func ConvertStringArrayToVersions

func ConvertStringArrayToVersions(versions []string) []gardencorev1beta1.ExpirableVersion

ConvertStringArrayToVersions converts a string array of versions to gardener experable versions

func ConvertStringToVersion

func ConvertStringToVersion(v string) gardencorev1beta1.ExpirableVersion

ConvertStringToVersion converts a string to gardener experable versions

func CreateKubeconfigFromInternal

func CreateKubeconfigFromInternal() ([]byte, error)

CreateKubeconfigFromClient creates a new kubeocnfig file from a resclient config

func DecMinorVersion

func DecMinorVersion(v *semver.Version) (*semver.Version, error)

DecMinorVersion decreases the minor version of 1 and sets the patch version to 0.

func DocExists

func DocExists(log logr.Logger, esClient elasticsearch.Client, testrunID, testrunStartTime string) (docExists bool)

DocExists checks whether an elasticsearch doc of a testrun exists in the testmachinery-* index

func DomainMatches

func DomainMatches(s string, domains ...string) bool

DomainMatches returns true if one of the given domains or subdomains match.

func DownloadFile

func DownloadFile(client *http.Client, url string) ([]byte, error)

DownloadFile downloads a file from the given url and return the content.

func FilterArchSpecificMachineImage

func FilterArchSpecificMachineImage(versions []gardencorev1beta1.MachineImageVersion, architecture string) []gardencorev1beta1.MachineImageVersion

FilterArchSpecificMachineImage removes all version which doesn't support given architecture.

func FilterExpiredMachineImageVersions

func FilterExpiredMachineImageVersions(versions []gardencorev1beta1.MachineImageVersion) []gardencorev1beta1.MachineImageVersion

FilterExpiredMachineImageVersions removes all expired versions from the list.

func FilterExpiredVersions

func FilterExpiredVersions(versions []gardencorev1beta1.ExpirableVersion) []gardencorev1beta1.ExpirableVersion

FilterExpiredVersions removes all expired versions from the list.

func FilterPatchVersions

func FilterPatchVersions(cloudProfileVersions []gardencorev1beta1.ExpirableVersion) ([]gardencorev1beta1.ExpirableVersion, error)

FilterPatchVersions keeps only versions with newest patch versions. E.g. 1.15.1, 1.14.4, 1.14.3, will result in 1.15.1, 1.14.4

func FormatArtifactName

func FormatArtifactName(name string) string

FormatArtifactName replaces all invalid artifact name characters. It replaces everything that is not an alphan-numeric character or "-" with a "-".

func GetCloudProfile

func GetCloudProfile(k8sClient client.Client, profileName string) (gardencorev1beta1.CloudProfile, error)

GetCloudProfile returns the cloudprofile

func GetClusterDomainURL

func GetClusterDomainURL(tmClient client.Client) (string, error)

GetClusterDomainURL tries to derive the cluster domain url from a grafana ingress if possible. Returns an error if the ingress cannot be found or is in unexpected form.

func GetDockerImageFromCommit

func GetDockerImageFromCommit(image, commit string) (string, error)

GetDockerImageFromCommit searches all tags of a image and try to matches the commit (e.g. .10.0-dev-<commit>). The image tag is returned if an applicable tag can be found todo: use pagination if gcr will support is someday

func GetGitHubClient

func GetGitHubClient(apiURL, username, password, uploadURL string, skipTLS bool) (*github.Client, error)

GetGitHubClient returns a new github enterprise client with basic auth and optional tls verification

func GetHTTPClient

func GetHTTPClient(username, password string, skipTLS bool) *http.Client

GetHTTPClient returns a new http client with basic auth and optional tls verification

func GetK8sVersions

func GetK8sVersions(cloudprofile gardencorev1beta1.CloudProfile, config common.ShootKubernetesVersionFlavor, filterPatchVersions bool) ([]gardencorev1beta1.ExpirableVersion, error)

GetK8sVersions returns all K8s version that should be rendered by the chart

func GetLatestK8sVersion

func GetLatestK8sVersion(cloudprofile gardencorev1beta1.CloudProfile) (gardencorev1beta1.ExpirableVersion, error)

GetLatestK8sVersion returns the latest available kubernetes version from the cloudprofile

func GetLatestMachineImageVersion

func GetLatestMachineImageVersion(cloudprofile gardencorev1beta1.CloudProfile, imageName, arch string) (gardencorev1beta1.MachineImageVersion, error)

GetLatestK8sVersion returns the latest avilable kubernetes version from the cloudprofile

func GetLatestVersion

GetLatestVersion returns the latest image from a list of expirable versions

func GetLatestVersionFromConstraint

func GetLatestVersionFromConstraint(versions []*semver.Version, constraintString string) (*semver.Version, error)

GetLatestVersionFromConstraint returns the latest version that matches a constraint

func GetMachineImage

func GetMachineImage(cloudprofile gardencorev1beta1.CloudProfile, imageName string) (gardencorev1beta1.MachineImage, error)

func GetPreviousKubernetesVersions

GetPreviousKubernetesVersions returns the 2 latest previous minor patch versions.

func GetXMinorsBeforeLatestK8sVersion

func GetXMinorsBeforeLatestK8sVersion(cloudprofile gardencorev1beta1.CloudProfile, x uint64) (*string, error)

GetXMinorsBeforeLatestK8sVersion returns a version with the minor decreased by x from the latest major.minor version and the patch being a wildcard "*", returns an error if minor would become negative.

func Getenv

func Getenv(key, defaultValue string) string

Getenv returns the string value of the environment variable with the provided key if the env var exists. Otherwise the default value is returned

func GetenvBool

func GetenvBool(key string, defaultValue bool) bool

GetenvBool returns the boolean value of the environment variable with the provided key if the env var exists and can be parsed. Otherwise the default value is returned

func HasLabel

func HasLabel(obj metav1.ObjectMeta, label string) bool

HasLabel returns a bool if passed in label exists

func IsAnnotationSubset

func IsAnnotationSubset(src, target map[string]string) bool

IsAnnotationSubset checks if all items in target are deep equal in src with the same key

func IsLastElementOfBucket

func IsLastElementOfBucket(value, bucketSize int) bool

IsIsEndOfBucket returns if the current value is the last integer value of its bucket Examples (bucket size: 3): 0: false 1: false 2: true 3: false 5: true

func IsSystemStep

func IsSystemStep(step *tmv1beta1.StepStatus) bool

func JSONPath

func JSONPath(data interface{}, path string) (interface{}, error)

func MarshalMap

func MarshalMap(annotations map[string]string) string

MarshalMap encodes the given map into a string similar to kubectl --selectors: map '{a:b,c:d}' becomes string 'a=b,c=d'

func MarshalNoHTMLEscape

func MarshalNoHTMLEscape(v interface{}) ([]byte, error)

MarshalNoHTMLEscape is nearly same as json.Marshal but does NOT HTLM-escape <, > or & However it does add a newline char at the end (as done by json.Encoder.Encode)

func MaxTimeExceeded

func MaxTimeExceeded(startTime time.Time, maxWaitTime int64) bool

MaxTimeExceeded checks if the max time is exceeded.

func OrderStepsStatus

func OrderStepsStatus(steps []*tmv1beta1.StepStatus)

OrderStepsStatus orders a list of step status of a testrun

func ParseRepoURL

func ParseRepoURL(url *url.URL) (repoOwner, repoName string, err error)

ParseRepoURL returns the repository owner and name of a github repo url

func ParseRepoURLFromString

func ParseRepoURLFromString(repoURL string) (repoOwner, repoName string, err error)

ParseRepoURLFromString returns the repository owner and name of a github repo url

func ParseTestDef

func ParseTestDef(data []byte) (tmv1beta1.TestDefinition, error)

ParseTestDef parses a file into a TestDefinition.

func PrettyPrintStruct

func PrettyPrintStruct(obj interface{}) string

PrettyPrintStruct returns an obj as pretty printed yaml.

func RandomString

func RandomString(n int) string

RandomString generates a random string out of "abcdefghijklmnopqrstuvwxyz1234567890" with a given length.RandomString The generated string is compatible to k8s name conventions

func RawJSONPath

func RawJSONPath(content []byte, path string, dest interface{}) ([]byte, error)

func ReadLines

func ReadLines(document []byte) <-chan []byte

ReadLines reads a byte array line by line ('\n' or '\r\n'); and return the content without the line end.

func RenderTableForSlack

func RenderTableForSlack(log logr.Logger, items TableItems) (string, error)

RenderTableForSlack renders a string table of given table items

func ResumeTestrun

func ResumeTestrun(ctx context.Context, k8sClient client.Client, tr *tmv1beta1.Testrun) error

Resume testruns resumes a testrun by adding the appropriate annotation to it

func ReturnMultiError

func ReturnMultiError(err error) error

ReturnMultiError takes an err object and returns a multierror with a custom format.

func SetMetaDataLabel

func SetMetaDataLabel(obj *metav1.ObjectMeta, label string, value string)

SetMetaDataLabel sets the label and value

func SplitString

func SplitString(text string, size int) []string

SplitString splits a string into byte slices of the given length. Tt will try to split only on newlines.

func StringArrayContains

func StringArrayContains(ar []string, elem string) bool

StringArrayContains checks if a string array contains the string elem

func StringDefault

func StringDefault(value, def string) string

StringDefault checks if a string is defined. If the value is emtpy the default string is returned

func TestrunProgress

func TestrunProgress(tr *tmv1beta1.Testrun) string

TestrunProgress returns the progress of a testrun

func TestrunStatusPhase

func TestrunStatusPhase(tr *tmv1beta1.Testrun) argov1alpha1.WorkflowPhase

TestrunStatusPhase determines the real testrun phase of a testrun by ignoring exit handler failures and system component failures if all other tests passed.

func UnmarshalMap

func UnmarshalMap(cfg string) (map[string]string, error)

UnmarshalMap does the opposite of MarshalMap. It decodes the given string into a map, return an error if the string is not in the expected format 'key1=value1,key2=value2'

func Unzip

func Unzip(archive, target string) error

Unzip unpacks the given archive to the specified target path

func WorkflowPhase

func WorkflowPhase(wf *argov1.Workflow) argov1.WorkflowPhase

WorkflowPhase calculates the phase for a completed workflow. In contrast to the argo status, we need to also consider continueOn steps as failures.

func Zipit

func Zipit(source, target string) error

Zipit zips a source file or directory and writes the archive to the specified target path

Types

type AdvancedWaitGroup

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

AdvancedWaitGroup implements the same interface as sync.WaitGroup. In addition a wait can be canceled during runtime when using the WaitWithCancel function

func (*AdvancedWaitGroup) Add

func (wg *AdvancedWaitGroup) Add(delta int)

Add adds delta to the wait counter. delta may be negative but the counter cannot be less then 0.

func (*AdvancedWaitGroup) Done

func (wg *AdvancedWaitGroup) Done()

Done removes one element from the wait counter

func (*AdvancedWaitGroup) Lock

func (*AdvancedWaitGroup) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*AdvancedWaitGroup) Unlock

func (*AdvancedWaitGroup) Unlock()

func (*AdvancedWaitGroup) Wait

func (wg *AdvancedWaitGroup) Wait()

Wait waits until the counter is 0

func (*AdvancedWaitGroup) WaitWithCancelFunc

func (wg *AdvancedWaitGroup) WaitWithCancelFunc(cancel func() bool)

WaitWithCancelFunc waits until the wait group count is zero or the cancel function returns true

type ESHits

type ESHits struct {
	Hits struct {
		Total struct {
			Value int `json:"value"`
		} `json:"total"`
	} `json:"hits"`
}

type ItemMeta

type ItemMeta struct {
	CloudProvider           string
	TestrunID               string
	OperatingSystem         string
	KubernetesVersion       string
	FlavorDescription       string
	AdditionalDimensionInfo string
}

type StatusSymbol

type StatusSymbol string

StatusSymbol is a unicode symbol for displaying in a table

const (
	StatusSymbolSuccess StatusSymbol = "✅"
	StatusSymbolFailure StatusSymbol = "❌"
	StatusSymbolNA      StatusSymbol = "N/A"
	StatusSymbolError   StatusSymbol = "🔥"
	StatusSymbolUnknown StatusSymbol = "❓"
)

type TableItem

type TableItem struct {
	Meta         ItemMeta
	StatusSymbol StatusSymbol
}

type TableItems

type TableItems []*TableItem

Directories

Path Synopsis
mocks
Package mock_elasticsearch is a generated GoMock package.
Package mock_elasticsearch is a generated GoMock package.
s3
mocks
Package mock_s3 is a generated GoMock package.
Package mock_s3 is a generated GoMock package.

Jump to

Keyboard shortcuts

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