framework

package
v1.4.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RetryInterval = time.Second * 5
	Timeout       = time.Minute * 30
	TestPoolName  = "e2e"

	RhcosContentFile              = "ssg-rhcos4-ds.xml"
	OcpContentFile                = "ssg-ocp4-ds.xml"
	UnexistentResourceContentFile = "ocp4-unexistent-resource.xml"
)
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 (
	TestTypeAll      = "all"
	TestTypeParallel = "parallel"
	TestTypeSerial   = "serial"
)
View Source
const (
	ProjRootFlag          = "root"
	KubeConfigFlag        = "kubeconfig"
	NamespacedManPathFlag = "namespacedMan"
	GlobalManPathFlag     = "globalMan"
	LocalOperatorFlag     = "localOperator"
	LocalOperatorArgs     = "localOperatorArgs"
	CleanupOnErrorFlag    = "cleanupOnError"
	TestTypeFlag          = "testType"

	TestOperatorNamespaceEnv = "TEST_OPERATOR_NAMESPACE"
	TestWatchNamespaceEnv    = "TEST_WATCH_NAMESPACE"
)
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 AssertEachMetric added in v1.1.0

func AssertEachMetric(namespace string, expectedMetrics map[string]int) error

func CheckPodLimit added in v1.1.0

func CheckPodLimit(c kubernetes.Interface, podName, namespace, cpuLimit, memLimit string) wait.ConditionFunc

func CheckPodPriorityClass added in v1.1.0

func CheckPodPriorityClass(c kubernetes.Interface, podName, namespace, priorityClass string) wait.ConditionFunc

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 GetObjNameFromTest added in v1.1.0

func GetObjNameFromTest(t *testing.T) string

func GetPoolNodeRoleSelector added in v1.1.0

func GetPoolNodeRoleSelector() map[string]string

func GetRotationCheckerWorkload added in v1.1.0

func GetRotationCheckerWorkload(namespace, rawResultName string) *core.Pod

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 IsRuleInProfile added in v1.1.0

func IsRuleInProfile(ruleName string, profile *compv1alpha1.Profile) bool

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.

func ProcessErrorOrTimeout added in v1.1.0

func ProcessErrorOrTimeout(err, timeoutErr error, message string) error

func WaitForPod added in v1.1.0

func WaitForPod(podCallback wait.ConditionFunc) error

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) 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) GetTestType

func (ctx *Context) GetTestType() string

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.

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
)

func NewFramework added in v1.1.0

func NewFramework() *Framework

func (*Framework) ApplyRemediationAndCheck added in v1.1.0

func (f *Framework) ApplyRemediationAndCheck(namespace, name, pool string) error

func (*Framework) AssertCheckRemediation added in v1.1.0

func (f *Framework) AssertCheckRemediation(name, namespace string, shouldHaveRem bool) error

func (*Framework) AssertComplianceSuiteDoesNotExist added in v1.4.0

func (f *Framework) AssertComplianceSuiteDoesNotExist(name, namespace string) error

func (*Framework) AssertCronJobIsNotSuspended added in v1.4.0

func (f *Framework) AssertCronJobIsNotSuspended(name string) error

func (*Framework) AssertCronJobIsSuspended added in v1.4.0

func (f *Framework) AssertCronJobIsSuspended(name string) error

func (*Framework) AssertHasCheck added in v1.1.0

func (f *Framework) AssertHasCheck(suiteName, scanName string, check compv1alpha1.ComplianceCheckResult) error

func (*Framework) AssertHasRemediations added in v1.1.0

func (f *Framework) AssertHasRemediations(suiteName, scanName, roleLabel string, remNameList []string) error

func (*Framework) AssertMetricsEndpointUsesHTTPVersion added in v1.4.0

func (f *Framework) AssertMetricsEndpointUsesHTTPVersion(endpoint, version string) error

func (*Framework) AssertMustHaveParsedProfiles added in v1.1.0

func (f *Framework) AssertMustHaveParsedProfiles(pbName, productType, productName string) error

func (*Framework) AssertProfileBundleMustHaveParsedRules added in v1.1.0

func (f *Framework) AssertProfileBundleMustHaveParsedRules(pbName string) error

func (*Framework) AssertProfileInRuleAnnotation added in v1.4.0

func (f *Framework) AssertProfileInRuleAnnotation(r *compv1alpha1.Rule, expectedProfileId string) bool

func (*Framework) AssertRemediationDoesNotExists added in v1.4.0

func (f *Framework) AssertRemediationDoesNotExists(name, namespace string) error

func (*Framework) AssertRemediationExists added in v1.4.0

func (f *Framework) AssertRemediationExists(name, namespace string) error

func (*Framework) AssertRemediationIsCurrent added in v1.1.0

func (f *Framework) AssertRemediationIsCurrent(namespace, name string) error

func (*Framework) AssertRemediationIsObsolete added in v1.1.0

func (f *Framework) AssertRemediationIsObsolete(namespace, name string) error

func (*Framework) AssertResultStorageHasExpectedItemsAfterRotation added in v1.1.0

func (f *Framework) AssertResultStorageHasExpectedItemsAfterRotation(expected int, namespace, checkerPodName string) error

func (*Framework) AssertRuleCheckTypeChangedAnnotationKey added in v1.4.0

func (f *Framework) AssertRuleCheckTypeChangedAnnotationKey(namespace, ruleName, lastCheckType string) error

AssertRuleCheckTypeChangedAnnotationKey asserts that the rule check type changed annotation key exists

func (*Framework) AssertRuleIsNodeType added in v1.4.0

func (f *Framework) AssertRuleIsNodeType(ruleName, namespace string) error

func (*Framework) AssertRuleIsPlatformType added in v1.4.0

func (f *Framework) AssertRuleIsPlatformType(ruleName, namespace string) error

func (*Framework) AssertScanDoesNotContainCheck added in v1.4.0

func (f *Framework) AssertScanDoesNotContainCheck(scanName, checkName, namespace string) error

func (*Framework) AssertScanDoesNotExist added in v1.4.0

func (f *Framework) AssertScanDoesNotExist(name, namespace string) error

func (*Framework) AssertScanExists added in v1.4.1

func (f *Framework) AssertScanExists(name, namespace string) error

func (*Framework) AssertScanHasValidPVCReference added in v1.1.0

func (f *Framework) AssertScanHasValidPVCReference(scanName, namespace string) error

func (*Framework) AssertScanHasValidPVCReferenceWithSize added in v1.1.0

func (f *Framework) AssertScanHasValidPVCReferenceWithSize(scanName, size, namespace string) error

func (*Framework) AssertScanIsCompliant added in v1.1.0

func (f *Framework) AssertScanIsCompliant(name, namespace string) error

func (*Framework) AssertScanIsInError added in v1.1.0

func (f *Framework) AssertScanIsInError(name, namespace string) error

func (*Framework) AssertScanIsNonCompliant added in v1.1.0

func (f *Framework) AssertScanIsNonCompliant(name, namespace string) error

func (*Framework) AssertScanIsNotApplicable added in v1.1.0

func (f *Framework) AssertScanIsNotApplicable(name, namespace string) error

func (*Framework) AssertScanSettingBindingConditionIsReady added in v1.4.0

func (f *Framework) AssertScanSettingBindingConditionIsReady(name string, namespace string) error

func (*Framework) AssertScanSettingBindingConditionIsSuspended added in v1.4.0

func (f *Framework) AssertScanSettingBindingConditionIsSuspended(name string, namespace string) error

func (*Framework) CleanUpOnError added in v1.1.0

func (f *Framework) CleanUpOnError() bool

func (*Framework) CreateAndRemoveEtcSecurettyOnNode added in v1.1.0

func (f *Framework) CreateAndRemoveEtcSecurettyOnNode(namespace, name, nodeName string) (*core.Pod, error)

createAndRemoveEtcSecurettyOnNode creates a pod that creates the file /etc/securetty on node, returns the pod object for the caller to delete at which point the pod, before exiting, removes the file

func (*Framework) CreateImageStream added in v1.1.0

func (f *Framework) CreateImageStream(iSName, namespace, imgPath string) (*imagev1.ImageStream, error)

func (*Framework) DoesObjectExist added in v1.1.0

func (f *Framework) DoesObjectExist(kind, namespace, name string) (error, bool)

func (*Framework) DoesRuleExist added in v1.1.0

func (f *Framework) DoesRuleExist(namespace, ruleName string) (error, bool)

func (*Framework) EnableRuleExistInTailoredProfile added in v1.4.0

func (f *Framework) EnableRuleExistInTailoredProfile(namespace, name, ruleName string) (bool, error)

func (*Framework) GetConfigMapsFromScan added in v1.1.0

func (f *Framework) GetConfigMapsFromScan(scaninstance *compv1alpha1.ComplianceScan) ([]core.ConfigMap, error)

GetConfigMapsFromScan lists the configmaps from the specified openscap scan instance

func (*Framework) GetImageStreamUpdatedDigest added in v1.1.0

func (f *Framework) GetImageStreamUpdatedDigest(iSName, namespace string) (string, error)

func (*Framework) GetNodesWithSelector added in v1.1.0

func (f *Framework) GetNodesWithSelector(labelselector map[string]string) ([]core.Node, error)

GetNodesWithSelector lists nodes according to a specific selector

func (*Framework) GetPodsForScan added in v1.1.0

func (f *Framework) GetPodsForScan(scanName string) ([]core.Pod, error)

func (*Framework) GetRawResultClaimNameFromScan added in v1.1.0

func (f *Framework) GetRawResultClaimNameFromScan(namespace, scanName string) (string, error)

func (*Framework) GetReadyProfileBundle added in v1.1.0

func (f *Framework) GetReadyProfileBundle(name, namespace string) (*compv1alpha1.ProfileBundle, error)

func (*Framework) PauseMachinePool added in v1.1.0

func (f *Framework) PauseMachinePool(poolName string) error

func (*Framework) ReRunScan added in v1.1.0

func (f *Framework) ReRunScan(scanName, namespace string) error

func (*Framework) RemoveObsoleteRemediationAndCheck added in v1.1.0

func (f *Framework) RemoveObsoleteRemediationAndCheck(namespace, name, renderedMcName, pool string) error

func (*Framework) ResumeMachinePool added in v1.1.0

func (f *Framework) ResumeMachinePool(poolName string) error

func (*Framework) ScanHasWarnings added in v1.1.0

func (f *Framework) ScanHasWarnings(scanName, namespace string) error

func (*Framework) SetUp added in v1.1.0

func (f *Framework) SetUp() error

func (*Framework) SuiteErrorMessageMatchesRegex added in v1.1.0

func (f *Framework) SuiteErrorMessageMatchesRegex(namespace, name, regexToMatch string) error

func (*Framework) TaintNode added in v1.1.0

func (f *Framework) TaintNode(node *core.Node, taint core.Taint) error

func (*Framework) TearDown added in v1.1.0

func (f *Framework) TearDown() error

tearDown performs any tasks necessary to cleanup resources leftover from testing and assumes a specific order. All namespaced resources must be cleaned up before deleting the cluster-wide resources, like roles, service accounts, or the deployment. If we don't properly cleanup resources before deleting CRDs, it leaves resources in a terminating state, making them harder to cleanup.

func (*Framework) UnApplyRemediationAndCheck added in v1.1.0

func (f *Framework) UnApplyRemediationAndCheck(namespace, name, pool string) error

func (*Framework) UntaintNode added in v1.1.0

func (f *Framework) UntaintNode(nodeName, taintKey string) error

func (*Framework) UpdateImageStreamTag added in v1.1.0

func (f *Framework) UpdateImageStreamTag(iSName, imagePath, namespace string) error

func (*Framework) UpdateSuiteContentImage added in v1.1.0

func (f *Framework) UpdateSuiteContentImage(newImg, suiteName, suiteNs string) error

func (*Framework) WaitForCronJobWithSchedule added in v1.1.0

func (f *Framework) WaitForCronJobWithSchedule(namespace, suiteName, schedule string) error

func (*Framework) WaitForDeployment added in v1.1.0

func (f *Framework) WaitForDeployment(name string, replicas int, retryInterval, timeout time.Duration) error

func (*Framework) WaitForDeploymentContentUpdate added in v1.1.0

func (f *Framework) WaitForDeploymentContentUpdate(pbName, imgDigest string) error

func (*Framework) WaitForGenericRemediationToBeAutoApplied added in v1.1.0

func (f *Framework) WaitForGenericRemediationToBeAutoApplied(remName, remNamespace string) error

func (*Framework) WaitForMachinePoolUpdate added in v1.1.0

func (f *Framework) WaitForMachinePoolUpdate(name string, action machineConfigActionFunc, predicate poolPredicate, poolPre *mcfgv1.MachineConfigPool) error

waitForMachinePoolUpdate retrieves the original version of a MCP, then performs an action passed in as a parameter and then waits until a MCP passes a predicate If a pool is already given (poolPre), that will be used to check the previous state of the pool.

func (*Framework) WaitForNodesToBeReady added in v1.1.0

func (f *Framework) WaitForNodesToBeReady() error

waitForNodesToBeReady waits until all the nodes in the cluster have reached the expected machineConfig.

func (*Framework) WaitForObjectToExist added in v1.1.0

func (f *Framework) WaitForObjectToExist(name, namespace string, obj dynclient.Object) error

func (*Framework) WaitForObjectToUpdate added in v1.1.0

func (f *Framework) WaitForObjectToUpdate(name, namespace string, obj ObjectResouceVersioner) error

func (*Framework) WaitForProfileBundleStatus added in v1.1.0

func (f *Framework) WaitForProfileBundleStatus(name string, status compv1alpha1.DataStreamStatusType) error

waitForProfileBundleStatus will poll until the compliancescan that we're lookingfor reaches a certain status, or until a timeout is reached.

func (*Framework) WaitForReScanStatus added in v1.1.0

func (f *Framework) WaitForReScanStatus(namespace, name string, targetStatus compv1alpha1.ComplianceScanStatusPhase) error

WaitForReScanStatus will poll until the compliancescan that we're lookingfor reaches a certain status for a re-scan, or until a timeout is reached.

func (*Framework) WaitForRemediationState added in v1.1.0

func (f *Framework) WaitForRemediationState(name, namespace string, state compv1alpha1.RemediationApplicationState) error

WaitForRemediationState will poll until the complianceRemediation that we're lookingfor gets applied, or until a timeout is reached.

func (*Framework) WaitForRemediationToBeAutoApplied added in v1.1.0

func (f *Framework) WaitForRemediationToBeAutoApplied(remName, remNamespace string, pool *mcfgv1.MachineConfigPool) error

func (*Framework) WaitForScanSettingBindingStatus added in v1.4.0

func (f *Framework) WaitForScanSettingBindingStatus(namespace, name string, targetStatus compv1alpha1.ScanSettingBindingStatusPhase) error

func (*Framework) WaitForScanStatus added in v1.1.0

func (f *Framework) WaitForScanStatus(namespace, name string, targetStatus compv1alpha1.ComplianceScanStatusPhase) error

func (*Framework) WaitForSuiteScansStatus added in v1.1.0

func (f *Framework) WaitForSuiteScansStatus(namespace, name string, targetStatus compv1alpha1.ComplianceScanStatusPhase, targetComplianceStatus compv1alpha1.ComplianceScanStatusResult) error

waitForScanStatus will poll until the compliancescan that we're lookingfor reaches a certain status, or until a timeout is reached.

func (*Framework) WaitForTailoredProfileStatus added in v1.4.0

func (f *Framework) WaitForTailoredProfileStatus(namespace, name string, targetStatus compv1alpha1.TailoredProfileState) error

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 ObjectResouceVersioner added in v1.1.0

type ObjectResouceVersioner interface {
	dynclient.Object
	metav1.Common
}

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