framework

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// dirs
	CmdDir      = "cmd"
	ManagerDir  = CmdDir + filePathSep + "manager"
	BuildDir    = "build"
	BuildBinDir = BuildDir + filePathSep + "_output" + filePathSep + "bin"
)

from the old operator-sdk scaffold constants

View Source
const (
	// KubeConfigEnvVar defines the env variable KUBECONFIG which
	// contains the kubeconfig file path.
	KubeConfigEnvVar = "KUBECONFIG"

	// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
	// which is the namespace where the watch activity happens.
	// this value is empty if the operator is running with clusterScope.
	WatchNamespaceEnvVar = "WATCH_NAMESPACE"
)
View Source
const (
	ProjRootFlag           = "root"
	KubeConfigFlag         = "kubeconfig"
	NamespacedManPathFlag  = "namespacedMan"
	GlobalManPathFlag      = "globalMan"
	LocalOperatorFlag      = "localOperator"
	LocalOperatorArgs      = "localOperatorArgs"
	SkipCleanupOnErrorFlag = "skipCleanupOnError"

	TestOperatorNamespaceEnv = "TEST_OPERATOR_NAMESPACE"
	TestWatchNamespaceEnv    = "TEST_WATCH_NAMESPACE"
	TestBundleInstallEnv     = "TEST_BUNDLE_INSTALL"
)
View Source
const (
	GoPathEnv = "GOPATH"
	GoModEnv  = "GO111MODULE"
	SrcDir    = "src"
)

Variables

This section is empty.

Functions

func AddToFrameworkScheme

func AddToFrameworkScheme(addToScheme addToSchemeFunc, obj dynclient.ObjectList) error

AddToFrameworkScheme allows users to add the scheme for their custom resources to the framework's scheme for use with the dynamic client. The user provides the addToScheme function (located in the register.go file of their operator project) and the List struct for their custom resource. For example, for a memcached operator, the list stuct may look like: &MemcachedList{} The List object is needed because the CRD has not always been fully registered by the time this function is called. If the CRD takes more than 5 seconds to become ready, this function throws an error

func ExecCmd

func ExecCmd(cmd *exec.Cmd) error

func GetGoPkg

func GetGoPkg() string

TODO(hasbro17): If this function is called in the subdir of a module project it will fail to parse go.mod and return the correct import path. This needs to be fixed to return the pkg import path for any subdir in order for `generate csv` to correctly form pkg imports for API pkg paths that are not relative to the root dir. This might not be fixable since there is no good way to get the project root from inside the subdir of a module project.

GetGoPkg returns the current directory's import path by parsing it from wd if this project's repository path is rooted under $GOPATH/src, or from go.mod the project uses Go modules to manage dependencies. If the project has a go.mod then wd must be the project root.

Example: "github.com/example-inc/app-operator"

func GetKubeconfigAndNamespace

func GetKubeconfigAndNamespace(configPath string) (*rest.Config, string, error)

GetKubeconfigAndNamespace returns the *rest.Config and default namespace defined in the kubeconfig at the specified path. If no path is provided, returns the default *rest.Config and namespace

func GoBuild

func GoBuild(opts GoCmdOptions) error

GoBuild runs "go build" configured with opts.

func GoCmd

func GoCmd(cmd string, opts GoCmdOptions) error

GoCmd runs "go {cmd}".

func GoModOn

func GoModOn() (bool, error)

From https://github.com/golang/go/wiki/Modules:

	You can activate module support in one of two ways:
	- Invoke the go command in a directory with a valid go.mod file in the
     current directory or any parent of it and the environment variable
     GO111MODULE unset (or explicitly set to auto).
	- Invoke the go command with GO111MODULE=on environment variable set.

GoModOn returns true if Go modules are on in one of the above two ways.

func MainEntry

func MainEntry(m *testing.M)

func MustGetwd

func MustGetwd() string

func MustSetWdGopath

func MustSetWdGopath(currentGopath string) string

MustSetWdGopath sets GOPATH to the first element of the path list in currentGopath that prefixes the wd, then returns the set path. If GOPATH cannot be set, MustSetWdGopath exits.

Types

type CleanupOptions

type CleanupOptions struct {
	TestContext   *Context
	Timeout       time.Duration
	RetryInterval time.Duration
}

type Context

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

func NewContext

func NewContext(t *testing.T) *Context

func (*Context) AddCleanupFn

func (ctx *Context) AddCleanupFn(fn cleanupFn)

func (*Context) Cleanup

func (ctx *Context) Cleanup()

func (*Context) GetID

func (ctx *Context) GetID() string

func (*Context) GetNamespace

func (ctx *Context) GetNamespace() (string, error)

TODO: remove before 1.0.0 Deprecated: GetNamespace() exists for historical compatibility. Use GetOperatorNamespace() or GetWatchNamespace() instead

func (*Context) GetOperatorNamespace

func (ctx *Context) GetOperatorNamespace() (string, error)

GetOperatorNamespace will return an Operator Namespace, if the flag --operator-namespace not be used (TestOpeatorNamespaceEnv not set) then it will create a new namespace with randon name and return that namespace

func (*Context) GetWatchNamespace

func (ctx *Context) GetWatchNamespace() (string, error)

GetWatchNamespace will return the namespaces to operator watch for changes, if the flag --watch-namespaced not be used then it will return the Operator Namespace.

func (*Context) InitializeClusterResources

func (ctx *Context) InitializeClusterResources(cleanupOptions *CleanupOptions) error

type ErrUnknownOperatorType

type ErrUnknownOperatorType struct {
	Type string
}

func (ErrUnknownOperatorType) Error

func (e ErrUnknownOperatorType) Error() string

type Framework

type Framework struct {
	Client            *frameworkClient
	KubeConfig        *rest.Config
	KubeClient        kubernetes.Interface
	Scheme            *runtime.Scheme
	NamespacedManPath *string
	OperatorNamespace string
	WatchNamespace    string

	LocalOperator bool
	// contains filtered or unexported fields
}
var (
	// Global framework struct
	Global *Framework
)

type FrameworkClient

type FrameworkClient interface {
	Get(gCtx goctx.Context, key dynclient.ObjectKey, obj dynclient.Object) error
	List(gCtx goctx.Context, list dynclient.ObjectList, opts ...dynclient.ListOption) error
	Create(gCtx goctx.Context, obj dynclient.Object, cleanupOptions *CleanupOptions) error
	Delete(gCtx goctx.Context, obj dynclient.Object, opts ...dynclient.DeleteOption) error
	Update(gCtx goctx.Context, obj dynclient.Object) error
}

type GoCmdOptions

type GoCmdOptions struct {
	// BinName is the name of the compiled binary, passed to -o.
	BinName string
	// Args are args passed to "go {cmd}", aside from "-o {bin_name}" and
	// test binary args.
	// These apply to build, clean, get, install, list, run, and test.
	Args []string
	// PackagePath is the path to the main (go build) or test (go test) packages.
	PackagePath string
	// Env is a list of environment variables to pass to the cmd;
	// exec.Command.Env is set to this value.
	Env []string
	// Dir is the dir to run "go {cmd}" in; exec.Command.Dir is set to this value.
	Dir string
}

GoCmdOptions is the base option set for "go" subcommands.

type GoTestOptions

type GoTestOptions struct {
	GoCmdOptions
	// TestBinaryArgs are args passed to the binary compiled by "go test".
	TestBinaryArgs []string
}

GoTestOptions is the set of options for "go test".

type OperatorType

type OperatorType = string

OperatorType - the type of operator

type Scanner

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

Scanner scans a yaml manifest file for manifest tokens delimited by "---". See bufio.Scanner for semantics.

func NewYAMLScanner

func NewYAMLScanner(r io.Reader) *Scanner

func (*Scanner) Bytes

func (s *Scanner) Bytes() []byte

func (*Scanner) Err

func (s *Scanner) Err() error

func (*Scanner) Scan

func (s *Scanner) Scan() bool

func (*Scanner) Text

func (s *Scanner) Text() string

type TestCtx deprecated

type TestCtx = Context //nolint:golint

Deprecated: TestCtx exists for historical compatibility. Use Context instead.

Jump to

Keyboard shortcuts

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