util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package util contains all the utility methods to execute the test (APIServer interaction, wait for condition, etc.).

Index

Constants

View Source
const (
	// PodLocal -> the pod is local.
	PodLocal = "local"
	// PodRemote -> the pod is remote.
	PodRemote = "remote"
)

Variables

This section is empty.

Functions

func ActivateTenants added in v1.0.0

func ActivateTenants(ctx context.Context, cl client.Client) error

ActivateTenants sets the TenantCondition of all Tenants to Active.

func AddArgumentToDeployment added in v1.0.0

func AddArgumentToDeployment(ctx context.Context, cl client.Client, namespace, name, argument string, index int) error

AddArgumentToDeployment adds an argument to the containers of a Deployment with the given name in the given namespace.

func ArePodsUp

func ArePodsUp(ctx context.Context, clientset kubernetes.Interface, namespace string) (ready, notReady []string, retErr error)

ArePodsUp check if all the pods of a specific namespace are ready. It returns a list of ready pods, a list of unready pods and occurred errors.

func CheckIfTestIsSkipped added in v0.3.1

func CheckIfTestIsSkipped(t *testing.T, clustersRequired int, testName string)

CheckIfTestIsSkipped checks if the number of clusters required by the test is less than the number of cluster really present.

func CheckVirtualNodes

func CheckVirtualNodes(ctx context.Context, homeClusterClient kubernetes.Interface, clusterNumber int) (ready bool)

CheckVirtualNodes checks if the Liqo virtual nodes of cluster C.

func CordonTenants added in v1.0.0

func CordonTenants(ctx context.Context, cl client.Client) error

CordonTenants sets the TenantCondition of all Tenants to Cordoned.

func CreateNamespaceOffloading added in v0.3.1

CreateNamespaceOffloading creates a new NamespaceOffloading resource, with the given parameters.

func DeleteResource added in v1.0.0

func DeleteResource(ctx context.Context, cl client.Client, obj client.Object) error

DeleteResource deletes a generic Resource given its metadata.

func DescribeTableArgs added in v0.6.0

func DescribeTableArgs(itBody interface{}, entries ...ginkgo.TableEntry) []interface{}

DescribeTableArgs is an helper function to pack the arguments for DescribeTable, when entries are generated by an external function.

func DrainTenants added in v1.0.0

func DrainTenants(ctx context.Context, cl client.Client) error

DrainTenants sets the TenantCondition of all Tenants to Drained.

func EnforceConfigMap added in v1.0.0

func EnforceConfigMap(ctx context.Context, cl client.Client, namespace, name string, options ...ConfigMapOption) error

EnforceConfigMap creates or updates a ConfigMap with the given name in the given namespace.

func EnforceDeployment added in v1.0.0

func EnforceDeployment(ctx context.Context, cl client.Client, namespace, name string, options ...DeploymentOption) error

EnforceDeployment creates or updates a Deployment with the given name in the given namespace.

func EnforceEvent added in v1.0.0

func EnforceEvent(ctx context.Context, cl client.Client, namespace, name string,
	involvedObject *corev1.ObjectReference, options ...EventOption) error

EnforceEvent creates or updates a Event with the given name in the given namespace.

func EnforceIngress added in v1.0.0

func EnforceIngress(ctx context.Context, cl client.Client, namespace, name string, options ...IngressOption) error

EnforceIngress creates or updates a Ingress with the given name in the given namespace.

func EnforceNamespace

func EnforceNamespace(ctx context.Context, cl kubernetes.Interface, cluster liqov1beta1.ClusterID,
	name string) (*corev1.Namespace, error)

EnforceNamespace creates and returns a namespace. If it already exists, it just returns the namespace.

func EnforcePod added in v1.0.0

func EnforcePod(ctx context.Context, cl client.Client, namespace, name string, options ...PodOption) error

EnforcePod creates or updates a Pod with the given name in the given namespace.

func EnforceSecret added in v1.0.0

func EnforceSecret(ctx context.Context, cl client.Client, namespace, name string, options ...SecretOption) error

EnforceSecret creates or updates a Secret with the given name in the given namespace.

func EnforceService added in v1.0.0

func EnforceService(ctx context.Context, cl client.Client, namespace, name string, options ...ServiceOption) error

EnforceService creates or updates a Service with the given name in the given namespace.

func EnsureDeploymentDeletion added in v1.0.0

func EnsureDeploymentDeletion(ctx context.Context, cl client.Client, namespace, name string) error

EnsureDeploymentDeletion deletes a Deployment with the given name in the given namespace.

func EnsureNamespaceDeletion added in v0.3.1

func EnsureNamespaceDeletion(ctx context.Context, cl kubernetes.Interface, name string) error

EnsureNamespaceDeletion deletes the namespace with the given name.

func EnsureNamespacesDeletionWithSelector added in v1.0.0

func EnsureNamespacesDeletionWithSelector(ctx context.Context, cl kubernetes.Interface, labelSelector map[string]string) error

EnsureNamespacesDeletionWithSelector wrap the deletion of namespaces matching the given labelSelector.

func ExecCmd

func ExecCmd(ctx context.Context, config *rest.Config, client kubernetes.Interface,
	podName, namespace, command string) (stdOut, stdErr string, retErr error)

ExecCmd executes a command inside a pod.

func ExecLiqoctl added in v0.5.0

func ExecLiqoctl(kubeconfig string, args []string, output io.Writer) error

ExecLiqoctl runs a liqoctl command targeting the cluster specified by the given kubeconfig.

func First added in v1.0.0

func First[F any, S any](first F, _ S) F

First returns the first element of the tuple.

func GetClusterLabels added in v0.3.1

func GetClusterLabels(index int) map[string]string

GetClusterLabels provides the labels which characterize the indexed cluster when exposed remotely as a virtual node.

func GetControllerClient added in v0.3.1

func GetControllerClient(scheme *runtime.Scheme, config *rest.Config) client.Client

GetControllerClient creates a new controller runtime client for the given config. If there is an error calls klog.Fatal().

func GetEnvironmentVariableOrDie added in v0.3.1

func GetEnvironmentVariableOrDie(key string) string

GetEnvironmentVariableOrDie retrieves the value of the environment variable named by the key. If the variable is not present calls klog.Fatal().

func GetNameNamespaceTest added in v1.0.0

func GetNameNamespaceTest(testName string) string

GetNameNamespaceTest returns the name of the namespace where resources for the test are created.

func GetNamespaceOffloading added in v1.0.0

func GetNamespaceOffloading(ctx context.Context, cl client.Client, namespace string) (*offloadingv1beta1.NamespaceOffloading, error)

GetNamespaceOffloading returns the NamespaceOffloading resource for the given namespace.

func GetNodes

func GetNodes(ctx context.Context, client kubernetes.Interface,
	clusterID liqov1beta1.ClusterID, labelSelector string) (*corev1.NodeList, error)

GetNodes returns the list of nodes of the cluster matching the given labels.

func GetPodsFromDeployment added in v1.0.0

func GetPodsFromDeployment(ctx context.Context, cl client.Client, namespace, name string) ([]corev1.Pod, error)

GetPodsFromDeployment returns the Pods of a Deployment with the given name in the given namespace.

func GetResource added in v1.0.0

func GetResource(ctx context.Context, cl client.Client, obj client.Object) error

GetResource retrieves a generic Resource.

func GetRestConfigOrDie added in v0.3.1

func GetRestConfigOrDie(kubeconfig string) *rest.Config

GetRestConfigOrDie retrieves the rest.Config from the kubeconfig variable. If there is an error calls klog.Fatal().

func GetWorkerNodes added in v1.0.0

func GetWorkerNodes(ctx context.Context, client kubernetes.Interface, clusterID, labelSelector string) (*corev1.NodeList, error)

GetWorkerNodes returns the list of worker nodes of the cluster.

func IsNodeControlPlane added in v1.0.0

func IsNodeControlPlane(taints []corev1.Taint) bool

IsNodeControlPlane checks if the node has the control-plane taint.

func IsPodUp

func IsPodUp(ctx context.Context, clientset kubernetes.Interface, namespace, podName string, podType PodType) bool

IsPodUp waits for a specific namespace/podName to be ready. It returns true if the pod within the timeout, false otherwise.

func NumPodsInTenantNs added in v1.0.0

func NumPodsInTenantNs(networkingEnabled bool, role liqov1beta1.RoleType, gwReplicas, vkReplicas int) int

NumPodsInTenantNs returns the number of pods that should be present in a tenant namespace.

func NumTenantNamespaces added in v1.0.0

func NumTenantNamespaces(numPeeredConsumers, numPeeredProviders int, role liqov1beta1.RoleType) int

NumTenantNamespaces returns the number of tenant namespaces that should be present in a cluster.

func OffloadNamespace added in v0.5.0

func OffloadNamespace(kubeconfig, namespace string, args ...string) error

OffloadNamespace offloads a namespace using liqoctl.

func RemoveArgumentFromDeployment added in v1.0.0

func RemoveArgumentFromDeployment(ctx context.Context, cl client.Client, namespace, name, argument string, index int) error

RemoveArgumentFromDeployment removes an argument from the containers of a Deployment with the given name in the given namespace.

func ResourceRequirements added in v0.6.0

func ResourceRequirements() corev1.ResourceRequirements

ResourceRequirements returns the default resource requirements for a pod during tests.

func Second added in v1.0.0

func Second[F any, S any](_ F, second S) S

Second returns the second element of the tuple.

func TriggerCheckNodeConnectivity

func TriggerCheckNodeConnectivity(localNodes *v1.NodeList, command string, nodePortValue int) error

TriggerCheckNodeConnectivity checks nodePort service connectivity, executing a command for every node in the target cluster.

func UnoffloadNamespace added in v0.5.0

func UnoffloadNamespace(kubeconfig, namespace string) error

UnoffloadNamespace unoffloads a namespace using liqoctl.

Types

type ConfigMapOption added in v1.0.0

type ConfigMapOption func(*corev1.ConfigMap)

ConfigMapOption is a function that modifies a ConfigMap.

type DeploymentOption added in v1.0.0

type DeploymentOption func(*appsv1.Deployment)

DeploymentOption is a function that modifies a Deployment.

func LocalDeploymentOption added in v1.0.0

func LocalDeploymentOption() DeploymentOption

LocalDeploymentOption sets the Deployment to be scheduled on local nodes.

func RemoteDeploymentOption added in v1.0.0

func RemoteDeploymentOption() DeploymentOption

RemoteDeploymentOption sets the Deployment to be scheduled on remote nodes.

func RuntimeClassOption added in v1.0.0

func RuntimeClassOption(runtimeClass string) DeploymentOption

RuntimeClassOption sets the RuntimeClass of the Deployment.

type EventOption added in v1.0.0

type EventOption func(*corev1.Event)

EventOption is a function that modifies a Event.

type IngressOption added in v1.0.0

type IngressOption func(*netv1.Ingress)

IngressOption is a function that modifies a Ingress.

type PodOption added in v1.0.0

type PodOption func(*corev1.Pod)

PodOption is a function that modifies a Pod.

func RemotePodOption added in v1.0.0

func RemotePodOption(virtualNode bool, nodeName *string) PodOption

RemotePodOption sets the Pod to be scheduled on remote nodes.

type PodType added in v0.3.2

type PodType string

PodType -> defines the type of a pod (local/remote).

type SecretOption added in v1.0.0

type SecretOption func(*corev1.Secret)

SecretOption is a function that modifies a Secret.

type ServiceOption added in v1.0.0

type ServiceOption func(*corev1.Service)

ServiceOption is a function that modifies a Service.

func WithNodePort added in v1.0.0

func WithNodePort() ServiceOption

WithNodePort sets the Service type to NodePort.

Jump to

Keyboard shortcuts

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