utils

package
v3.0.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KubebuilderBinName define the name of the kubebuilder binary to be used in the tests
	KubebuilderBinName = "kubebuilder"
)

Variables

This section is empty.

Functions

func EnsureExistAndReplace

func EnsureExistAndReplace(input, match, replace string) (string, error)

EnsureExistAndReplace check if the content exists and then do the replace

func GetNonEmptyLines

func GetNonEmptyLines(output string) []string

GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it.

func ImplementWebhooks

func ImplementWebhooks(filename string) error

ImplementWebhooks will mock an webhook data

func InsertCode

func InsertCode(filename, target, code string) error

InsertCode searches target content in the file and insert `toInsert` after the target.

func RandomSuffix

func RandomSuffix() (string, error)

RandomSuffix returns a 4-letter string.

func UncommentCode

func UncommentCode(filename, target, prefix string) error

UncommentCode searches for target in the file and remove the comment prefix of the target content. The target content may span multiple lines.

Types

type CmdContext

type CmdContext struct {
	// environment variables in k=v format.
	Env   []string
	Dir   string
	Stdin io.Reader
}

CmdContext provides context for command execution

func (*CmdContext) Run

func (cc *CmdContext) Run(cmd *exec.Cmd) ([]byte, error)

Run executes the provided command within this context

type Kubectl

type Kubectl struct {
	*CmdContext
	Namespace string
}

Kubectl contains context to run kubectl commands

func (*Kubectl) Apply

func (k *Kubectl) Apply(inNamespace bool, cmdOptions ...string) (string, error)

Apply is a general func to run kubectl apply commands

func (*Kubectl) Command

func (k *Kubectl) Command(cmdOptions ...string) (string, error)

Command is a general func to run kubectl commands

func (*Kubectl) CommandInNamespace

func (k *Kubectl) CommandInNamespace(cmdOptions ...string) (string, error)

CommandInNamespace is a general func to run kubectl commands in the namespace

func (*Kubectl) Delete

func (k *Kubectl) Delete(inNamespace bool, cmdOptions ...string) (string, error)

Delete is a func to run kubectl delete commands

func (*Kubectl) Get

func (k *Kubectl) Get(inNamespace bool, cmdOptions ...string) (string, error)

Get is a func to run kubectl get commands

func (*Kubectl) Logs

func (k *Kubectl) Logs(cmdOptions ...string) (string, error)

Logs is a func to run kubectl logs commands

func (*Kubectl) Version

func (k *Kubectl) Version() (ver KubernetesVersion, err error)

Version is a func to run kubectl version command

func (*Kubectl) Wait

func (k *Kubectl) Wait(inNamespace bool, cmdOptions ...string) (string, error)

Wait is a func to run kubectl wait commands

func (*Kubectl) WithInput

func (k *Kubectl) WithInput(stdinInput string) *Kubectl

WithInput is a general func to run kubectl commands with input

type KubernetesVersion

type KubernetesVersion struct {
	ClientVersion VersionInfo `json:"clientVersion,omitempty"`
	ServerVersion VersionInfo `json:"serverVersion,omitempty"`
}

KubernetesVersion holds a subset of both client and server versions.

type TestContext

type TestContext struct {
	*CmdContext
	TestSuffix string
	Domain     string
	Group      string
	Version    string
	Kind       string
	Resources  string
	ImageName  string
	BinaryName string
	Kubectl    *Kubectl
	K8sVersion *KubernetesVersion
}

TestContext specified to run e2e tests

func NewTestContext

func NewTestContext(binaryName string, env ...string) (*TestContext, error)

NewTestContext init with a random suffix for test TestContext stuff, to avoid conflict when running tests synchronously.

func (*TestContext) CleanupManifests

func (t *TestContext) CleanupManifests(dir string)

CleanupManifests is a helper func to run kustomize build and pipe the output to kubectl delete -f -

func (*TestContext) CreateAPI

func (t *TestContext) CreateAPI(resourceOptions ...string) error

CreateAPI is for running `kubebuilder create api`

func (*TestContext) CreateWebhook

func (t *TestContext) CreateWebhook(resourceOptions ...string) error

CreateWebhook is for running `kubebuilder create webhook`

func (*TestContext) Destroy

func (t *TestContext) Destroy()

Destroy is for cleaning up the docker images for testing

func (*TestContext) Init

func (t *TestContext) Init(initOptions ...string) error

Init is for running `kubebuilder init`

func (*TestContext) InstallCertManager

func (t *TestContext) InstallCertManager(hasv1beta1CRs bool) error

InstallCertManager installs the cert manager bundle. If hasv1beta1CRs is true, the legacy version (which uses v1alpha2 CRs) is installed.

func (*TestContext) InstallPrometheusOperManager

func (t *TestContext) InstallPrometheusOperManager() error

InstallPrometheusOperManager installs the prometheus manager bundle.

func (*TestContext) LoadImageToKindCluster

func (t *TestContext) LoadImageToKindCluster() error

LoadImageToKindCluster loads a local docker image to the kind cluster

func (*TestContext) Make

func (t *TestContext) Make(makeOptions ...string) error

Make is for running `make` with various targets

func (*TestContext) Prepare

func (t *TestContext) Prepare() error

Prepare prepares the test environment.

func (*TestContext) UninstallCertManager

func (t *TestContext) UninstallCertManager(hasv1beta1CRs bool)

UninstallCertManager uninstalls the cert manager bundle. If hasv1beta1CRs is true, the legacy version (which uses v1alpha2 CRs) is installed.

func (*TestContext) UninstallPrometheusOperManager

func (t *TestContext) UninstallPrometheusOperManager()

UninstallPrometheusOperManager uninstalls the prometheus manager bundle.

type VersionInfo

type VersionInfo struct {
	Major      string `json:"major"`
	Minor      string `json:"minor"`
	GitVersion string `json:"gitVersion"`
	// contains filtered or unexported fields
}

VersionInfo holds a subset of client/server version information.

func (VersionInfo) GetMajorInt

func (vi VersionInfo) GetMajorInt() uint64

GetMajorInt returns the uint64 representation of vi.Major.

func (VersionInfo) GetMinorInt

func (vi VersionInfo) GetMinorInt() uint64

GetMinorInt returns the uint64 representation of vi.Minor.

Jump to

Keyboard shortcuts

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