e2eutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Purge = func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
	client, err := cfg.NewClient()
	if err != nil {
		return nil, fmt.Errorf("failed to create client during setup/purge: %s", err)
	}
	var list corev1.NamespaceList
	err = client.Resources().List(ctx, &list, func(opts *metav1.ListOptions) {
		opts.LabelSelector = "app.kubernetes.io/managed-by=e2eutil"
	})

	if err != nil {
		fmt.Printf("error while listing namespaces to purge past test runs: %s\n", err)
		return ctx, err
	}
	for _, item := range list.Items {
		err = client.Resources().Delete(ctx, &item)
		if err != nil {
			fmt.Printf("error while cleaning up namespace %q: %s\n", item.Name, err)
			return ctx, err
		}
	}

	promClusterRoleBinding := &rbacv1.ClusterRoleBinding{ObjectMeta: metav1.ObjectMeta{
		Name: fixtures.PromServer,
	}}
	if err := client.Resources().Delete(ctx, promClusterRoleBinding); err != nil && !k8serrors.IsNotFound(err) {
		return ctx, err
	}

	promClusterRole := &rbacv1.ClusterRole{ObjectMeta: metav1.ObjectMeta{
		Name: fixtures.PromServer,
	}}
	if err := client.Resources().Delete(ctx, promClusterRole); err != nil && !k8serrors.IsNotFound(err) {
		return ctx, err
	}

	return ctx, nil
}

Purge cleans up resources created by the previous run.

Functions

func CreateNSForTest added in v0.0.2

func CreateNSForTest(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error)

CreateNSForTest creates a random namespace with the runID as a prefix. It is stored in the context so that the deleteNSForTest routine can look it up and delete it.

func DeleteNSForTest added in v0.0.2

func DeleteNSForTest(ctx context.Context, cfg *envconf.Config, t *testing.T) (context.Context, error)

DeleteNSForTest looks up the namespace corresponding to the given test and deletes it.

func EnsureExternalDns added in v0.0.3

func EnsureExternalDns(ctx context.Context, client klient.Client, name string) error

func EnsureExternalDnsCleaned added in v0.0.3

func EnsureExternalDnsCleaned(ctx context.Context, client klient.Client, name string) error

func GetDeployment added in v0.0.3

func GetDeployment(ctx context.Context) (*appsv1.Deployment, error)

func GetHostname added in v0.0.2

func GetHostname(ns, dnsZoneId string) string

func GetNamespaceKey added in v0.0.2

func GetNamespaceKey(t *testing.T) string

GetNamespaceKey returns the context key for a given test

func RetryBackoff added in v0.0.3

func RetryBackoff(tries int, initialSleep time.Duration, f func() error) error

func SetDeployment added in v0.0.3

func SetDeployment(ctx context.Context, deployment *appsv1.Deployment) context.Context

func UpdateContainerDnsZoneIds added in v0.0.3

func UpdateContainerDnsZoneIds(deployment *appsv1.Deployment, dnsIds []string) ([]corev1.Container, error)

UpdateContainerDnsZoneIds updates the dns zone ids for the operator container in the given deployment and returns the new containers. This does not update the deployment.

func UpdateContainers added in v0.0.3

func UpdateContainers(ctx context.Context, client klient.Client, deployment *appsv1.Deployment, containers []corev1.Container) error

UpdateContainers updates the containers in the deployment

Types

This section is empty.

Jump to

Keyboard shortcuts

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