testutils

package
v0.0.0-...-d6154db Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ControlPlaneNamespace = "kcp-system"

	KLMPodPrefix    = "klm-controller-manager"
	KLMPodContainer = "manager"
	RemoteNamespace = "kyma-system"
)
View Source
const (
	TestModuleCRName                   = "sample-yaml"
	TestModuleResourceNamespace        = "template-operator-system"
	ModuleDeploymentName               = "template-operator-controller-manager"
	ModuleServiceAccountName           = "template-operator-controller-manager"
	ModuleManagedCRName                = "template-operator-managed-resource"
	ModuleDeploymentNameInNewerVersion = "template-operator-v2-controller-manager"
	ModuleDeploymentNameInOlderVersion = "template-operator-v1-controller-manager"
)
View Source
const (
	Timeout                = time.Second * 40
	ConsistentCheckTimeout = time.Second * 10
	Interval               = time.Millisecond * 250
)
View Source
const (
	OCIRegistryCredLabelKeyForTest = shared.OperatorGroup + shared.Separator + "oci-registry-cred"
)

Variables

View Source
var (
	ErrDeploymentNotReady = errors.New("deployment is not ready")
	ErrDeploymentUpdating = errors.New("deployment is still updating")
)
View Source
var (
	ErrPodNotFound = errors.New("could not find pod")
	ErrLogNotFound = errors.New("logMsg was not found in log")
)
View Source
var (
	ErrStatusModuleStateMismatch        = errors.New("status.modules.state not match")
	ErrContainsUnexpectedModules        = errors.New("kyma CR contains unexpected modules")
	ErrNotContainsExpectedModules       = errors.New("kyma CR not contains expected modules")
	ErrModuleVersionInStatusIsIncorrect = errors.New("status.modules.version is incorrect")
)
View Source
var (
	ErrManifestResourceIsNil = errors.New("manifest spec.resource is nil")
	ErrManifestsExist        = errors.New("cluster contains manifest CRs")
)
View Source
var (
	ErrNotFound                   = errors.New("resource not exists")
	ErrNotDeleted                 = errors.New("resource not deleted")
	ErrDeletionTimestampFound     = errors.New("deletion timestamp not nil")
	ErrEmptyRestConfig            = errors.New("rest.Config is nil")
	ErrSampleCrNotInExpectedState = errors.New("resource not in expected state")
	ErrFetchingStatus             = errors.New("could not fetch status from resource")
)
View Source
var ErrManifestStateMisMatch = errors.New("ManifestState mismatch")
View Source
var ErrMetricNotFound = errors.New("metric was not found")

Functions

func AddFinalizerToManifest

func AddFinalizerToManifest(ctx context.Context, clnt client.Client, kymaName,
	kymaNamespace,
	moduleName, finalizer string,
) error

func AddFinalizerToModuleCR

func AddFinalizerToModuleCR(ctx context.Context, clnt client.Client, moduleCR *unstructured.Unstructured,
	finalizer string,
) error

func AllModuleTemplatesExists

func AllModuleTemplatesExists(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma) error

func AppendExternalCRDs

func AppendExternalCRDs(path string, files ...string) ([]*apiextensionsv1.CustomResourceDefinition, error)

func ApplyYAML

func ApplyYAML(ctx context.Context, clnt client.Client, yamlFilePath string) error

func AssertKymaStateMetricNotFound

func AssertKymaStateMetricNotFound(ctx context.Context, kymaName string, state shared.State) error

func CRExists

func CRExists(obj apimetav1.Object, clientError error) error

func CRIsInState

func CRIsInState(ctx context.Context, group, version, kind, name, namespace string, statusPath []string,
	clnt client.Client, expectedState shared.State,
) error

func CertificateSecretExists

func CertificateSecretExists(ctx context.Context,
	namespacedSecretName types.NamespacedName, k8sClient client.Client,
) error

func CertificateSecretIsCreatedAfter

func CertificateSecretIsCreatedAfter(ctx context.Context,
	namespacedSecretName types.NamespacedName, k8sClient client.Client, notBeforeTime *apimetav1.Time,
) error

func CertificateSecretIsSyncedToSkrCluster

func CertificateSecretIsSyncedToSkrCluster(ctx context.Context,
	kcpNamespacedSecretName types.NamespacedName, controlPlaneClient client.Client,
	skrNamespacedSecretName types.NamespacedName, runtimeClient client.Client,
) error

func CheckKLMLogs

func CheckKLMLogs(ctx context.Context,
	logMsg string,
	controlPlaneConfig, runtimeConfig *rest.Config,
	k8sClient, runtimeClient client.Client,
	logsSince *apimetav1.Time,
) error

func CheckManifestIsInState

func CheckManifestIsInState(
	ctx context.Context,
	kymaName, kymaNamespace, moduleName string,
	clnt client.Client,
	expectedState shared.State,
) error

func CheckModuleState

func CheckModuleState(ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, moduleName string,
	state shared.State,
) error

func ContainsKymaManagerField

func ContainsKymaManagerField(
	ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, managerName string,
) (bool, error)

func ContainsModuleInSpec

func ContainsModuleInSpec(ctx context.Context,
	clnt client.Client,
	kymaName, kymaNamespace,
	moduleName string,
) error

func CreateCR

func CreateCR(ctx context.Context, clnt client.Client, obj client.Object) error

func CreateImageSpecLayer

func CreateImageSpecLayer(manifestFilePath string) (containerregistryv1.Layer, error)

func CreateOCIImageSpec

func CreateOCIImageSpec(name, repo, manifestFilePath string, enableCredSecretSelector bool) (v1beta2.ImageSpec, error)

func CredSecretLabelSelector

func CredSecretLabelSelector(labelValue string) *apimetav1.LabelSelector

func DeleteCR

func DeleteCR(ctx context.Context, clnt client.Client, obj client.Object) error

func DeleteCRWithGVK

func DeleteCRWithGVK(ctx context.Context, clnt client.Client, name, namespace, group, version, kind string) error

func DeleteCertificateSecret

func DeleteCertificateSecret(ctx context.Context, namespacedSecretName types.NamespacedName, k8sClient client.Client,
) error

func DeleteKyma

func DeleteKyma(ctx context.Context,
	clnt client.Client,
	kyma *v1beta2.Kyma,
	deletionPropagation apimetav1.DeletionPropagation,
) error

func DeleteKymaByForceRemovePurgeFinalizer

func DeleteKymaByForceRemovePurgeFinalizer(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma) error

func DeleteManifest

func DeleteManifest(ctx context.Context, clnt client.Client, kymaName, kymaNamespace, moduleName string) error

func DeleteManifestAndVerify

func DeleteManifestAndVerify(ctx context.Context, clnt client.Client, manifest *v1beta2.Manifest) func() error

func DeleteModule

func DeleteModule(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma, moduleName string) error

func DeleteModuleTemplate

func DeleteModuleTemplate(ctx context.Context,
	clnt client.Client, module v1beta2.Module, kymaChannel string,
) error

func DeletionTimeStampExists

func DeletionTimeStampExists(ctx context.Context, group, version, kind, name, namespace string,
	clnt client.Client,
) (bool, error)

func DeploymentIsReady

func DeploymentIsReady(ctx context.Context, clnt client.Client, name, namespace string) error

func DisableModule

func DisableModule(ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, moduleName string,
) error

func EnableDeployment

func EnableDeployment(ctx context.Context, clnt client.Client,
	name, namespace string,
) error

func EnableModule

func EnableModule(ctx context.Context,
	clnt client.Client,
	kymaName, kymaNamespace string,
	module v1beta2.Module,
) error

func ExpectManifestLastOperationMessageContains

func ExpectManifestLastOperationMessageContains(ctx context.Context, clnt client.Client,
	manifestName, message string,
) error

func ExpectManifestStateIn

func ExpectManifestStateIn(ctx context.Context, clnt client.Client,
	state shared.State,
) func(manifestName string) error

func ExpectOCISyncRefAnnotationExists

func ExpectOCISyncRefAnnotationExists(ctx context.Context, clnt client.Client,
	mustExist bool,
) func(manifestName string) error

func FinalizerIsRemoved

func FinalizerIsRemoved(ctx context.Context, clnt client.Client, moduleCR *unstructured.Unstructured,
	finalizer string,
) error

func GetCACertificate

func GetCACertificate(ctx context.Context, namespacedCertName types.NamespacedName, k8sClient client.Client,
) (*certmanagerv1.Certificate, error)

func GetClusterRoleBindingPolicyRules

func GetClusterRoleBindingPolicyRules(ctx context.Context, clnt client.Client, roleName string,
	clusterRoleBindings apirbacv1.ClusterRoleBindingList,
) ([]apirbacv1.PolicyRule, error)

func GetDeployment

func GetDeployment(ctx context.Context, clnt client.Client,
	name, namespace string,
) (*apiappsv1.Deployment, error)

func GetKyma

func GetKyma(ctx context.Context, clnt client.Client, name, namespace string) (*v1beta2.Kyma, error)

func GetKymaStateMetricCount

func GetKymaStateMetricCount(ctx context.Context, kymaName string, state shared.State) (int, error)

func GetMandatoryModuleStateMetric

func GetMandatoryModuleStateMetric(ctx context.Context, kymaName, moduleName, state string) (int, error)

func GetMandatoryModuleTemplateCountMetric

func GetMandatoryModuleTemplateCountMetric(ctx context.Context) (int, error)

func GetManifest

func GetManifest(ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
) (*v1beta2.Manifest, error)

GetManifest should be only used when manifest still been tracked in kyma.status.

func GetManifestResource

func GetManifestResource(ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
) (*unstructured.Unstructured, error)

func GetManifestSpecRemote

func GetManifestSpecRemote(
	ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
) (bool, error)

func GetManifestStatus

func GetManifestStatus(ctx context.Context, clnt client.Client, manifestName string) (shared.Status, error)

func GetManifestWithMetadata

func GetManifestWithMetadata(ctx context.Context,
	clnt client.Client, manifestNamespace, manifestName string,
) (*v1beta2.Manifest, error)

func GetManifestWithName

func GetManifestWithName(ctx context.Context, clnt client.Client, manifestName string) (*v1beta2.Manifest, error)

func GetModuleStateMetricCount

func GetModuleStateMetricCount(ctx context.Context, kymaName, moduleName string, state shared.State) (int, error)

func GetModuleTemplate

func GetModuleTemplate(ctx context.Context,
	clnt client.Client,
	module v1beta2.Module,
	defaultChannel string,
) (*v1beta2.ModuleTemplate, error)

func GetRequeueReasonCount

func GetRequeueReasonCount(ctx context.Context,
	requeueReason, requeueType string,
) (int, error)

func GetRoleBindingRolePolicyRules

func GetRoleBindingRolePolicyRules(ctx context.Context, clnt client.Client, roleName, namespace string,
	roleBindings apirbacv1.RoleBindingList,
) ([]apirbacv1.PolicyRule, error)

func GetRoleBindingwithClusterRolePolicyRules

func GetRoleBindingwithClusterRolePolicyRules(ctx context.Context, clnt client.Client, roleName string,
	roleBindings apirbacv1.RoleBindingList,
) ([]apirbacv1.PolicyRule, error)

func GetSelfSignedCertNotRenewMetricsGauge

func GetSelfSignedCertNotRenewMetricsGauge(ctx context.Context, kymaName string) (int, error)

func InstallManifest

func InstallManifest(ctx context.Context, clnt client.Client, manifest *v1beta2.Manifest, installSpecByte []byte,
	enableResource bool,
) error

func IsManifestRequeueReasonCountIncreased

func IsManifestRequeueReasonCountIncreased(ctx context.Context, requeueReason, requeueType string) (bool,
	error,
)

func IsResourceVersionSame

func IsResourceVersionSame(ctx context.Context, clnt client.Client,
	objectKey client.ObjectKey,
	gvk schema.GroupVersionKind, expectedVersion string,
) (bool, error)

func KymaDeleted

func KymaDeleted(ctx context.Context,
	kymaName string, kymaNamespace string, k8sClient client.Client,
) error

func KymaExists

func KymaExists(ctx context.Context, clnt client.Client, name, namespace string) error

func KymaHasDeletionTimestamp

func KymaHasDeletionTimestamp(ctx context.Context,
	clnt client.Client,
	kymaName string,
	kymaNamespace string,
) bool

func KymaIsInState

func KymaIsInState(ctx context.Context, name, namespace string, clnt client.Client, state shared.State) error

func ListKlmClusterRoleBindings

func ListKlmClusterRoleBindings(clnt client.Client, ctx context.Context,
	serviceAccountName string,
) (apirbacv1.ClusterRoleBindingList, error)

func ListKlmRoleBindings

func ListKlmRoleBindings(clnt client.Client, ctx context.Context,
	serviceAccountName, namespace string,
) (apirbacv1.RoleBindingList, error)

func MandatoryManifestExistsWithLabelAndAnnotation

func MandatoryManifestExistsWithLabelAndAnnotation(ctx context.Context, clnt client.Client,
	annotationKey, annotationValue string,
) error

func ManifestExists

func ManifestExists(
	ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
) error

func ManifestExistsByMetadata

func ManifestExistsByMetadata(
	ctx context.Context,
	clnt client.Client,
	manifestNamespace,
	manifestName string,
) error

func ManifestNoDeletionTimeStampSet

func ManifestNoDeletionTimeStampSet(ctx context.Context,
	kymaName, kymaNamespace, moduleName string,
	clnt client.Client,
) error

func ManifestStatusLastUpdateTimeIsNotChanged

func ManifestStatusLastUpdateTimeIsNotChanged(ctx context.Context,
	clnt client.Client,
	kymaName, kymaNamespace, moduleName string,
	oldStatus shared.Status,
) error

func ManifestStatusOperationContainsMessage

func ManifestStatusOperationContainsMessage(ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, moduleName, msg string,
) error

func ManifestVersionIsCorrect

func ManifestVersionIsCorrect(ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, moduleName, version string,
) error

func ModuleCRExists

func ModuleCRExists(ctx context.Context, clnt client.Client, moduleCR *unstructured.Unstructured) error

func ModuleCRIsInExpectedState

func ModuleCRIsInExpectedState(ctx context.Context,
	clnt client.Client,
	moduleCR *unstructured.Unstructured,
	expectedState shared.State,
) bool

func ModuleTemplateExists

func ModuleTemplateExists(ctx context.Context,
	clnt client.Client,
	module v1beta2.Module,
	defaultChannel string,
) error

func ModuleVersionInKymaStatusIsCorrect

func ModuleVersionInKymaStatusIsCorrect(ctx context.Context,
	clnt client.Client, kymaName, kymaNamespace, moduleName, moduleVersion string,
) error

func NewKymaWithSyncLabel

func NewKymaWithSyncLabel(name, namespace, channel, syncStrategy string) *v1beta2.Kyma

NewKymaWithSyncLabel use this function to initialize kyma CR with SyncStrategyLocalSecret are typically used in e2e test, which expect related access secret provided.

func NewSKRCluster

func NewSKRCluster(scheme *machineryruntime.Scheme) (client.Client, *envtest.Environment, error)

func NewTemplateOperator

func NewTemplateOperator(channel string) v1beta2.Module

func NewTestIssuer

func NewTestIssuer(namespace string) *certmanagerv1.Issuer

func NewTestKyma

func NewTestKyma(name string) *v1beta2.Kyma

func NewTestManifest

func NewTestManifest(prefix string) *v1beta2.Manifest

func NewTestModule

func NewTestModule(name, channel string) v1beta2.Module

func NewTestModuleCR

func NewTestModuleCR(namespace string) *unstructured.Unstructured

NewTestModuleCR init one module cr used by template-operator.

func NewTestModuleWithFixName

func NewTestModuleWithFixName(name, channel string) v1beta2.Module

func NewTestNamespace

func NewTestNamespace(namespace string) *apicorev1.Namespace

func NoManifestExist

func NoManifestExist(ctx context.Context,
	clnt client.Client,
) error

func NotContainsModuleInSpec

func NotContainsModuleInSpec(ctx context.Context,
	clnt client.Client,
	kymaName, kymaNamespace,
	moduleName string,
) error

func PurgeMetricsAreAsExpected

func PurgeMetricsAreAsExpected(ctx context.Context,
	timeShouldBeMoreThan float64,
	expectedRequests int,
) bool

func PushToRemoteOCIRegistry

func PushToRemoteOCIRegistry(server *httptest.Server, manifestFilePath, layerName string) error

func ReadModuleVersionFromModuleTemplate

func ReadModuleVersionFromModuleTemplate(ctx context.Context, clnt client.Client, module v1beta2.Module,
	channel string,
) (string, error)

func SampleCRDeletionTimeStampSet

func SampleCRDeletionTimeStampSet(ctx context.Context, name, namespace string, clnt client.Client) error

func SampleCRNoDeletionTimeStampSet

func SampleCRNoDeletionTimeStampSet(ctx context.Context, name, namespace string, clnt client.Client) error

func SetKymaState

func SetKymaState(ctx context.Context, kyma *v1beta2.Kyma, clnt client.Client, state shared.State) error

func SetSkipLabelToMandatoryManifests

func SetSkipLabelToMandatoryManifests(ctx context.Context, clnt client.Client, ifSkip bool,
) error

func SetSkipLabelToManifest

func SetSkipLabelToManifest(
	ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
	ifSkip bool,
) error

func SkipLabelExistsInManifest

func SkipLabelExistsInManifest(ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
) bool

func StopDeployment

func StopDeployment(ctx context.Context, clnt client.Client,
	name, namespace string,
) error

func SyncKyma

func SyncKyma(ctx context.Context, clnt client.Client, kyma *v1beta2.Kyma) error

func UpdateKymaLabel

func UpdateKymaLabel(
	ctx context.Context,
	clnt client.Client,
	kymaName, kymaNamespace,
	labelKey, labelValue string,
) error

func UpdateKymaModuleChannel

func UpdateKymaModuleChannel(ctx context.Context, clnt client.Client,
	kymaName, kymaNamespace, channel string,
) error

func UpdateManifestSpec

func UpdateManifestSpec(cxt context.Context, clnt client.Client, manifestName string, spec v1beta2.ManifestSpec) error

func UpdateManifestState

func UpdateManifestState(
	ctx context.Context,
	clnt client.Client,
	kymaName,
	kymaNamespace,
	moduleName string,
	state shared.State,
) error

func UpdateModuleTemplateSpec

func UpdateModuleTemplateSpec(ctx context.Context,
	clnt client.Client,
	module v1beta2.Module,
	key,
	newValue,
	kymaChannel string,
) error

func WithInvalidInstallImageSpec

func WithInvalidInstallImageSpec(ctx context.Context, clnt client.Client,
	enableResource bool, manifestFilePath string,
) func(manifest *v1beta2.Manifest) error

func WithValidInstallImageSpec

func WithValidInstallImageSpec(ctx context.Context, clnt client.Client, name, manifestFilePath, serverURL string,
	enableResource, enableCredSecretSelector bool,
) func(manifest *v1beta2.Manifest) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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