utils

package
v0.103.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAnnotationForDeployItem

func AddAnnotationForDeployItem(ctx context.Context, testenv *envtest.Environment, di *lsv1alpha1.DeployItem,
	annotation, value string) error

func AddMimicKCMSecretControllerToManager

func AddMimicKCMSecretControllerToManager(mgr manager.Manager) error

AddMimicKCMSecretControllerToManager adds the mock kcm controller to a manager.

func AddMimicKCMServiceAccountControllerToManager

func AddMimicKCMServiceAccountControllerToManager(mgr manager.Manager) error

AddMimicKCMServiceAccountControllerToManager adds the mock kcm controller to a manager.

func AddReconcileAnnotation

func AddReconcileAnnotation(ctx context.Context, testenv *envtest.Environment, inst *lsv1alpha1.Installation) error

func BuildContainerDeployItem

func BuildContainerDeployItem(configuration *containerv1alpha1.ProviderConfiguration) *lsv1alpha1.DeployItem

BuildContainerDeployItem builds a new deploy item of type container.

func BuildInternalKubernetesTarget

func BuildInternalKubernetesTarget(ctx context.Context, kubeClient client.Client, namespace, name string, restConfig *rest.Config) (*lsv1alpha1.Target, error)

BuildInternalKubernetesTarget creates a new target of type kubernetes whereas a local hostname of the cluster will be set to the cluster internal host.

func BuildTargetAndSecretFromKubernetesTarget

func BuildTargetAndSecretFromKubernetesTarget(target *lsv1alpha1.Target) (*lsv1alpha1.Target, *corev1.Secret, error)

func CheckConfigMap

func CheckConfigMap(ctx context.Context, state *envtest.State, name string, expectedData map[string]string) error

func CheckDataObjectMap

func CheckDataObjectMap(ctx context.Context, state *envtest.State, name string, expectedData map[string]string) error

func CheckDataObjectString

func CheckDataObjectString(ctx context.Context, state *envtest.State, name string, expectedValue string) error

func CheckDeployment

func CheckDeployment(deployment *appsv1.Deployment) error

CheckDeployment checks whether the given Deployment is healthy. A deployment is considered healthy if the controller observed its current revision and if the number of updated replicas is equal to the number of replicas.

func CreateBlueprintFromFile

func CreateBlueprintFromFile(filePath, contentPath string) *blueprints.Blueprint

CreateBlueprintFromFile reads a blueprint from the given file and creates a internal blueprint object.

func CreateContextFromFile

func CreateContextFromFile(ctx context.Context, state *envtest.State, contxt *lsv1alpha1.Context, path string) error

func CreateDataObjectFromFile

func CreateDataObjectFromFile(ctx context.Context, state *envtest.State, do *lsv1alpha1.DataObject, path string) error

func CreateDefaultContext

func CreateDefaultContext(ctx context.Context, kubeClient client.Client, repoCtx cdv2.TypedObjectAccessor, namespaces ...string) error

CreateDefaultContext creates default context with a given repository context.

func CreateExampleDefaultContext

func CreateExampleDefaultContext(ctx context.Context, kubeClient client.Client, namespaces ...string) error

CreateExampleDefaultContext creates default context with the example repository.

func CreateInstallationFromFile

func CreateInstallationFromFile(ctx context.Context, state *envtest.State, inst *lsv1alpha1.Installation, path string) error

func CreateKubernetesTarget

func CreateKubernetesTarget(namespace, name string, restConfig *rest.Config) (*lsv1alpha1.Target, error)

CreateKubernetesTarget creates a new target of type kubernetes

func CreateKubernetesTargetFromSecret

func CreateKubernetesTargetFromSecret(namespace, name string, secret *corev1.Secret) (*lsv1alpha1.Target, error)

CreateKubernetesTargetFromSecret creates a new target of type kubernetes from a secret

func CreateNamespaceDataObjectFromFile

func CreateNamespaceDataObjectFromFile(ctx context.Context, state *envtest.State, do *lsv1alpha1.DataObject, path string) error

func CreateOrUpdateTarget

func CreateOrUpdateTarget(ctx context.Context, client client.Client, namespace, name, ttype string, config interface{}) (*lsv1alpha1.Target, error)

CreateOrUpdateTarget creates or updates a target with specific name, namespace and type

func DefaultRepositoryContext

func DefaultRepositoryContext(baseUrl string) *cdv2.UnstructuredTypedObject

DefaultRepositoryContext creates a new oci registry repository context.

func DeleteDeployItemForNewReconcile

func DeleteDeployItemForNewReconcile(
	ctx context.Context,
	kubeClient client.Client,
	di *v1alpha1.DeployItem,
	timeout time.Duration) error

func DeleteExecutionForNewReconcile

func DeleteExecutionForNewReconcile(
	ctx context.Context,
	kubeClient client.Client,
	exec *v1alpha1.Execution,
	timeout time.Duration) error

func DeleteObject

func DeleteObject(
	ctx context.Context,
	kubeClient client.Client,
	obj client.Object,
	timeout time.Duration) error

DeleteObject deletes a object and waits until the given object is deleted

func ExampleRepositoryContext

func ExampleRepositoryContext() *cdv2.UnstructuredTypedObject

ExampleRepositoryContext creates a new example repository context.

func ExpectNoError

func ExpectNoError(err error, extra ...interface{})

func ExpectNoErrorWithOffset

func ExpectNoErrorWithOffset(offset int, err error, extra ...interface{})

func GetDataObjectData

func GetDataObjectData(do *lsv1alpha1.DataObject, data interface{})

func GetDeployItemsOfInstallation

func GetDeployItemsOfInstallation(ctx context.Context, kubeClient client.Client, inst *lsv1alpha1.Installation) ([]*lsv1alpha1.DeployItem, error)

func GetNextCounter

func GetNextCounter() string

func GetTargetConfiguration

func GetTargetConfiguration(target *lsv1alpha1.Target, config interface{})

func InjectImageTagIntoValues

func InjectImageTagIntoValues(values *json.RawMessage, imageTag string)

InjectImageTagIntoValues injects (and potentially overwrites) an Image tag into a values JSON raw message

func InjectTargetSelectorIntoValues

func InjectTargetSelectorIntoValues(values *json.RawMessage, targetSelector []lsv1alpha1.TargetSelector)

InjectTargetSelectorIntoValues injects (and potentially overwrites) a TargetSelector into a values JSON raw message

func LocalRemoteBlueprintRef

func LocalRemoteBlueprintRef(resourceName string) lsv1alpha1.BlueprintDefinition

LocalRemoteBlueprintRef creates a new default local remote blueprint reference

func LocalRepositoryContext

func LocalRepositoryContext(baseurl string) *cdv2.UnstructuredTypedObject

LocalRepositoryContext returns a new 'local' repository context.

func MakeRepositoryContext

func MakeRepositoryContext(rc cdv2.TypedObjectAccessor) *cdv2.UnstructuredTypedObject

MakeRepositoryContext creates a new oci registry repository context.

func MimicKCMServiceAccount

func MimicKCMServiceAccount(ctx context.Context, client client.Client, args MimicKCMServiceAccountArgs)

MimicKCMServiceAccount mimics the kube controller manager behavior for service accounts. The apiserver is watched for service accounts and a account secret is created.

func MimicKCMServiceAccountTokenGeneration

func MimicKCMServiceAccountTokenGeneration(ctx context.Context, client client.Client, args MimicKCMServiceAccountArgs)

MimicKCMServiceAccountTokenGeneration mimics the kube controller manager behavior for service accounts. The apiserver is watched for secrets of a service account, and a token is added to the secret.

func ReadAndCreateOrUpdateDeployItem

func ReadAndCreateOrUpdateDeployItem(ctx context.Context, testenv *envtest.Environment, state *envtest.State, diName, file string) *lsv1alpha1.DeployItem

ReadAndCreateOrUpdateDeployItem reads a deploy item from the given file and creates or updated the deploy item

func ReadBlueprintFromFile

func ReadBlueprintFromFile(testfile string) (*lsv1alpha1.Blueprint, error)

ReadBlueprintFromFile reads a file and parses it to a Blueprint

func ReadChartFrom

func ReadChartFrom(path string) ([]byte, func())

ReadChartFrom reads a Helm chart from a filesystem path and returns it as raw bytes array

func ReadResourceFromFile

func ReadResourceFromFile(obj runtime.Object, testfile string) error

ReadResourceFromFile reads a file and parses it to the given object

func ReadValuesFromFile

func ReadValuesFromFile(path string) json.RawMessage

ReadValuesFromFile reads Helm values from a file and returns them as JSON raw message

func Request

func Request(name, namespace string) reconcile.Request

Request creates a new reconcile.Request

func RequestFromObject

func RequestFromObject(obj client.Object) reconcile.Request

RequestFromObject creates a new reconcile.for a object

func SetDaemonSetReady

func SetDaemonSetReady(ctx context.Context, client client.Client, ds *appsv1.DaemonSet) error

SetDaemonSetReady sets a DaemonSet status to Ready.

func SetDataObjectData

func SetDataObjectData(do *lsv1alpha1.DataObject, data interface{})

func SetDeploymentReady

func SetDeploymentReady(ctx context.Context, client client.Client, dp *appsv1.Deployment) error

SetDeploymentReady sets a Deployment status to Ready.

func SetPodReady

func SetPodReady(ctx context.Context, client client.Client, pod *corev1.Pod) error

SetPodReady sets a Pod status to Ready.

func SetReadyStatus

func SetReadyStatus(ctx context.Context, c client.Client, u *unstructured.Unstructured) error

SetReadyStatus sets the object status to Ready for workload type resources.

func SetReplicaSetReady

func SetReplicaSetReady(ctx context.Context, client client.Client, rs *appsv1.ReplicaSet) error

SetReplicaSetReady sets a ReplicaSet status to Ready.

func SetReplicationControllerReady

func SetReplicationControllerReady(ctx context.Context, client client.Client, rc *corev1.ReplicationController) error

SetReplicationControllerReady sets a ReplicationController status to Ready.

func SetStatefulSetReady

func SetStatefulSetReady(ctx context.Context, client client.Client, sts *appsv1.StatefulSet) error

SetStatefulSetReady sets a StatefulSet status to Ready.

func ShouldNotReconcile

func ShouldNotReconcile(ctx context.Context, reconciler reconcile.Reconciler, req reconcile.Request, optionalDescription ...interface{}) error

ShouldNotReconcile reconciles the given reconciler with the given request and expects that an error occurred

func ShouldReconcile

func ShouldReconcile(ctx context.Context, reconciler reconcile.Reconciler, req reconcile.Request, optionalDescription ...interface{})

ShouldReconcile reconciles the given reconciler with the given request and expects that no error occurred

func ShouldReconcileButRetry

func ShouldReconcileButRetry(ctx context.Context, reconciler reconcile.Reconciler, req reconcile.Request, optionalDescription ...interface{})

func UpdateDataObjectFromFile

func UpdateDataObjectFromFile(ctx context.Context, state *envtest.State, do *lsv1alpha1.DataObject, path string) error

func UpdateInstallationFromFile

func UpdateInstallationFromFile(ctx context.Context, state *envtest.State, inst *lsv1alpha1.Installation, path string) error

func UpdateJobIdForDeployItem

func UpdateJobIdForDeployItem(ctx context.Context, testenv *envtest.Environment, di *lsv1alpha1.DeployItem, time metav1.Time) error

func UpdateJobIdForDeployItemC

func UpdateJobIdForDeployItemC(ctx context.Context, cl client.Client, di *lsv1alpha1.DeployItem, time metav1.Time) error

func UpdateJobIdForExecution

func UpdateJobIdForExecution(ctx context.Context, testenv *envtest.Environment, exec *lsv1alpha1.Execution) error

func UpdateJobIdForExecutionC

func UpdateJobIdForExecutionC(ctx context.Context, cl client.Client, exec *lsv1alpha1.Execution) error

func UpdateJobIdForInstallation

func UpdateJobIdForInstallation(ctx context.Context, testenv *envtest.Environment, inst *lsv1alpha1.Installation) error

func WaitForContextToBeReady

func WaitForContextToBeReady(ctx context.Context, logger utils.Logger, kubeClient client.Client, objKey types.NamespacedName, timeout time.Duration) error

WaitForContextToBeReady waits for a context to be ready

func WaitForDeploymentToBeReady

func WaitForDeploymentToBeReady(ctx context.Context, logger utils.Logger, kubeClient client.Client, objKey types.NamespacedName, timeout time.Duration) error

WaitForDeploymentToBeReady waits for a deployment to be ready

func WaitForObjectDeletion

func WaitForObjectDeletion(
	ctx context.Context,
	kubeClient client.Client,
	obj client.Object,
	timeout time.Duration) error

WaitForObjectDeletion waits until the given object is deleted

Types

type MimicKCMSecretController

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

MimicKCMSecretController is a controller that mimics the service account token secret handling of the KCM.

func (*MimicKCMSecretController) Reconcile

type MimicKCMServiceAccountArgs

type MimicKCMServiceAccountArgs struct {
	Name      string
	Namespace string
	Token     string

	Timeout time.Duration
}

MimicKCMServiceAccountArgs describes the configuration for mimicing the service account behavior of the MimicKCMServiceAccount func.

type MimicKCMServiceAccountController

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

MimicKCMServiceAccountController is a controller that mimics the service account token creation of the KCM.

func (*MimicKCMServiceAccountController) Reconcile

type TestInstallationConfig

type TestInstallationConfig struct {
	// +optional
	MockClient *k8smock.MockClient
	// Defines the installation that should be used to create a blueprint and operations
	// If it is not defined a default one is created with the given name and namespace
	// +optional
	Installation *lsv1alpha1.Installation

	// Configures the default created installation
	InstallationName             string
	InstallationNamespace        string
	RemoteBlueprintComponentName string
	RemoteBlueprintResourceName  string
	RemoteBlueprintVersion       string
	RemoteBlueprintBaseURL       string

	BlueprintContentPath string
	// BlueprintFilePath defines the filepath to the blueprint definition.
	// Will be defaulted to <BlueprintContentPath>/blueprint.yaml if not defined.
	BlueprintFilePath string
}

TestInstallationConfig defines a installation configuration which can be used to create a test environment with a installation, a blueprint and a operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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