test

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2025 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GatewayClassAcceptanceTimeLimit is the amount of time that the operator
	// will wait for a GatewayClass to be accepted.
	GatewayClassAcceptanceTimeLimit = time.Second * 7

	// GatewaySchedulingTimeLimit is the maximum amount of time to wait for
	// a supported Gateway to be marked as Scheduled by the gateway controller.
	GatewaySchedulingTimeLimit = time.Second * 7

	// GatewayReadyTimeLimit is the maximum amount of time to wait for a
	// supported Gateway to be fully provisioned and marked as Ready by the
	// gateway controller.
	GatewayReadyTimeLimit = time.Minute * 3
)
View Source
const (
	// ControlPlaneCondDeadline is the default timeout for checking on controlplane resources.
	ControlPlaneCondDeadline = time.Minute
	// ControlPlaneCondTick is the default tick for checking on controlplane resources.
	ControlPlaneCondTick = 250 * time.Millisecond
	// ControlPlaneSchedulingTimeLimit is the maximum amount of time to wait for
	// a supported ControlPlane to be created after a Gateway resource is
	// created
	ControlPlaneSchedulingTimeLimit = time.Minute * 3

	// DataPlaneCondDeadline is the default timeout for checking on dataplane resources.
	DataPlaneCondDeadline = 1 * time.Minute
	// DataPlaneCondTick is the default tick for checking on dataplane resources.
	DataPlaneCondTick = 2 * time.Second
)
View Source
const (
	// WaitIngressTick is the default timeout tick interval for checking on ingress resources.
	WaitIngressTick = time.Second * 1
	// DefaultIngressWait is the default timeout for checking on ingress resources.
	DefaultIngressWait = time.Minute * 3
)
View Source
const (
	// HTTPBinImage is the container image name we use for deploying the "httpbin" HTTP testing tool.
	// if you need a simple HTTP server for tests you're writing, use this and check the documentation.
	// See: https://github.com/kong/httpbin
	HTTPBinImage = "kong/httpbin:0.1.0"

	// TCPEchoImage echoes TCP text sent to it after printing out basic information about its environment, e.g.
	// Welcome, you are connected to node kind-control-plane.
	// Running on Pod tcp-echo-58ccd6b78d-hn9t8.
	// In namespace foo.
	// With IP address 10.244.0.13.
	TCPEchoImage = "kong/go-echo:0.1.0"
)
View Source
const (
	// ObjectUpdateTimeout is the amount of time that will be allowed for
	// conflicts to be resolved before an object update will be considered failed.
	ObjectUpdateTimeout = time.Second * 30

	// ObjectUpdateTick is the time duration between checks for object updates.
	ObjectUpdateTick = 100 * time.Millisecond

	// SubresourceReadinessWait is the maximum amount of time allowed for
	// sub-resources to become "Ready" after being created on behalf of a
	// parent resource.
	SubresourceReadinessWait = time.Second * 30

	// DefaultHTTPPort is the default HTTP port.
	DefaultHTTPPort = 80
)
View Source
const (
	// GatewayStandardCRDsKustomizeURL is a URL that provides standard Gateway API CRDs.
	GatewayStandardCRDsKustomizeURL = "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v1.3.0"
	// GatewayExperimentalCRDsKustomizeURL is a URL that provides experimental Gateway API CRDs.
	GatewayExperimentalCRDsKustomizeURL = "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=v1.3.0"
	// GatewayRawRepoURL is the base URL to the raw Gateway API repository.
	GatewayRawRepoURL = "https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/v1.3.0"
)
View Source
const (
	// KubernetesConfigurationModuleName is the name of the module where we import and install Kong configuration CRDs from.
	KubernetesConfigurationModuleName = "github.com/kong/kubernetes-configuration"
)
View Source
const ServiceAccountToImpersonate = "system:serviceaccount:kong-system:controller-manager"

ServiceAccountToImpersonate is the service account to impersonate when running tests, to ensure that the same RBAC rules as presented in Helm chart are used.

Variables

This section is empty.

Functions

func BuildEnvironment

func BuildEnvironment(ctx context.Context, existingCluster string, builderOpts ...BuilderOpt) (environments.Environment, error)

BuildEnvironment builds the k8s environment for the tests. Args:

  • ctx: the context to use for the environment build.
  • existingCluster: the name of the existing cluster to use for the tests. If empty, a new kind cluster will be created.
  • builderOpts: accept a list of builder options that will be applied to the builder before buildling the environment.

Returns the environment on success and an error on failure.

func BuildMTLSCredentials

func BuildMTLSCredentials(ctx context.Context, k8sClient *kubernetes.Clientset, httpc *http.Client) error

BuildMTLSCredentials builds the mTLS credentials for the tests. Args:

  • ctx: the context to use.
  • k8sClient: the k8s client to use.
  • httpc: the http client to configure with the mTLS credentials.

func ControlPlaneCRBContainsCRAndSA

func ControlPlaneCRBContainsCRAndSA(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneCRBContainsCRAndSA is a helper function for tests that returns a function that can be used to check if the ClusterRoleBinding of a ControPlane has the reference of ClusterRole belonging to the ControlPlane and contains the service account used by the Deployment of the ControlPlane.

func ControlPlaneDetectedNoDataPlane

func ControlPlaneDetectedNoDataPlane(t *testing.T, ctx context.Context, controlPlane types.NamespacedName, clients K8sClients) func() bool

ControlPlaneDetectedNoDataPlane is a helper function for tests that returns a function that can be used to check if a ControlPlane detected unset dataplane. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasActiveDeployment

func ControlPlaneHasActiveDeployment(t *testing.T, ctx context.Context, controlplaneName types.NamespacedName, clients K8sClients) func() bool

ControlPlaneHasActiveDeployment is a helper function for tests that returns a function that can be used to check if a ControlPlane has an active deployment. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasAdmissionWebhookCertificateSecret

func ControlPlaneHasAdmissionWebhookCertificateSecret(t *testing.T, ctx context.Context, cp *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneHasAdmissionWebhookCertificateSecret is a helper function for tests that returns a function that can be used to check if a ControlPlane has an admission webhook certificate Secret. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasAdmissionWebhookConfiguration

func ControlPlaneHasAdmissionWebhookConfiguration(t *testing.T, ctx context.Context, cp *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneHasAdmissionWebhookConfiguration is a helper function for tests that returns a function that can be used to check if a ControlPlane has an admission webhook configuration.

func ControlPlaneHasAdmissionWebhookService

func ControlPlaneHasAdmissionWebhookService(t *testing.T, ctx context.Context, cp *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneHasAdmissionWebhookService is a helper function for tests that returns a function that can be used to check if a ControlPlane has an admission webhook Service. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasClusterRole

func ControlPlaneHasClusterRole(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneHasClusterRole is a helper function for tests that returns a function that can be used to check if a ControlPlane has a ClusterRole. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasClusterRoleBinding

func ControlPlaneHasClusterRoleBinding(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) func() bool

ControlPlaneHasClusterRoleBinding is a helper function for tests that returns a function that can be used to check if a ControlPlane has a ClusterRoleBinding. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneHasNReadyPods

func ControlPlaneHasNReadyPods(t *testing.T, ctx context.Context, controlplaneName types.NamespacedName, clients K8sClients, n int32) func() bool

ControlPlaneHasNReadyPods checks if a ControlPlane has at least N ready Pods.

func ControlPlaneIsNotReady

func ControlPlaneIsNotReady(t *testing.T, ctx context.Context, controlplane types.NamespacedName, clients K8sClients) func() bool

ControlPlaneIsNotReady is a helper function for tests. It returns a function that can be used to check if a ControlPlane is marked as not Ready. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneIsProvisioned

func ControlPlaneIsProvisioned(t *testing.T, ctx context.Context, controlPlane types.NamespacedName, clients K8sClients) func() bool

ControlPlaneIsProvisioned is a helper function for tests that returns a function that can be used to check if a ControlPlane was provisioned. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneIsReady

func ControlPlaneIsReady(t *testing.T, ctx context.Context, controlplane types.NamespacedName, clients K8sClients) func() bool

ControlPlaneIsReady is a helper function for tests. It returns a function that can be used to check if a ControlPlane is marked as Ready. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneIsScheduled

func ControlPlaneIsScheduled(t *testing.T, ctx context.Context, controlPlane types.NamespacedName, operatorClient *clientset.Clientset) func() bool

ControlPlaneIsScheduled is a helper function for tests that returns a function that can be used to check if a ControlPlane was scheduled. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlaneUpdateEventually

func ControlPlaneUpdateEventually(t *testing.T, ctx context.Context, controlplaneNN types.NamespacedName, clients K8sClients, updateFunc func(*operatorv1beta1.ControlPlane)) func() bool

ControlPlaneUpdateEventually is a helper function for tests that returns a function that can be used to update the ControlPlane. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlanesClusterRoleBindingHasSubject

func ControlPlanesClusterRoleBindingHasSubject(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients, subject rbacv1.Subject) func() bool

ControlPlanesClusterRoleBindingHasSubject is a helper function for tests that returns a function that can be used to check if ControlPlane's ClusterRoleBinding contains the provided Subject. Should be used in conjunction with require.Eventually or assert.Eventually.

func ControlPlanesClusterRoleHasPolicyRule

func ControlPlanesClusterRoleHasPolicyRule(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients, pr rbacv1.PolicyRule) func() bool

ControlPlanesClusterRoleHasPolicyRule is a helper function for tests that returns a function that can be used to check if ControlPlane's ClusterRole contains the provided PolicyRule. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasActiveDeployment

func DataPlaneHasActiveDeployment(
	t *testing.T,
	ctx context.Context,
	dataplaneNN types.NamespacedName,
	ret *appsv1.Deployment,
	matchingLabels client.MatchingLabels,
	clients K8sClients,
) func() bool

DataPlaneHasActiveDeployment is a helper function for tests that returns a function that can be used to check if a DataPlane has an active deployment (that is, a Deployment that has at least 1 Replica and that all Replicas as marked as Available). Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasActiveService

func DataPlaneHasActiveService(t *testing.T, ctx context.Context, dataplaneName types.NamespacedName, ret *corev1.Service, clients K8sClients, matchingLabels client.MatchingLabels) func() bool

DataPlaneHasActiveService is a helper function for tests that returns a function that can be used to check if a DataPlane has an active proxy service. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasActiveServiceWithName added in v1.5.0

func DataPlaneHasActiveServiceWithName(t *testing.T, ctx context.Context, dataplaneName types.NamespacedName, ret *corev1.Service, clients K8sClients, matchingLabels client.MatchingLabels, name string) func() bool

DataPlaneHasActiveServiceWithName is a helper function for tests that returns a function that can be used to check if a DataPlane has an active proxy service with the specified name. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasDeployment

func DataPlaneHasDeployment(
	t *testing.T,
	ctx context.Context,
	dataplaneName types.NamespacedName,
	ret *appsv1.Deployment,
	clients K8sClients,
	matchingLabels client.MatchingLabels,
	asserts ...func(appsv1.Deployment) bool,
) func() bool

DataPlaneHasDeployment is a helper function for tests that returns a function that can be used to check if a DataPlane has a Deployment. Optionally the caller can provide a list of assertions that will be checked against the found Deployment. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasHPA

func DataPlaneHasHPA(
	t *testing.T,
	ctx context.Context,
	dataplane *operatorv1beta1.DataPlane,
	ret *autoscalingv2.HorizontalPodAutoscaler,
	clients K8sClients,
) func() bool

DataPlaneHasHPA is a helper function for tests that returns a function that can be used to check if a DataPlane has an active HPA. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasNReadyPods

func DataPlaneHasNReadyPods(t *testing.T, ctx context.Context, dataplaneName types.NamespacedName, clients K8sClients, n int32) func() bool

DataPlaneHasNReadyPods checks if a DataPlane has at least N ready Pods.

func DataPlaneHasPodDisruptionBudget added in v1.4.0

func DataPlaneHasPodDisruptionBudget(
	t *testing.T,
	ctx context.Context,
	dataplane *operatorv1beta1.DataPlane,
	ret *policyv1.PodDisruptionBudget,
	clients K8sClients,
	req PodDisruptionBudgetRequirement,
) func() bool

DataPlaneHasPodDisruptionBudget is a helper function for tests that returns a function that can be used to check if a DataPlane has a PodDisruptionBudget. It expects there is only a single PodDisruptionBudget for the DataPlane with the following requirements: - it is owned by the DataPlane, - its `app` label matches the DP name, - its `gateway-operator.konghq.com/managed-by` label is set to `dataplane`. Additionally, the caller can provide a requirement function that will be used to verify the PodDisruptionBudget (e.g. to check if it has an expected status). Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasService

func DataPlaneHasService(
	t *testing.T,
	ctx context.Context,
	dataplaneName types.NamespacedName,
	clients K8sClients,
	matchingLabels client.MatchingLabels,
	asserts ...func(corev1.Service) bool,
) func() bool

DataPlaneHasService is a helper function for tests that returns a function that can be used to check if a DataPlane has a service created. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasServiceAndAddressesInStatus

func DataPlaneHasServiceAndAddressesInStatus(t *testing.T, ctx context.Context, dataplaneName types.NamespacedName, clients K8sClients) func() bool

DataPlaneHasServiceAndAddressesInStatus is a helper function for tests that returns a function that can be used to check if a DataPlane has: - a backing service name in its .Service status field - a list of addreses of its backing service in its .Addresses status field Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneHasServiceSecret

func DataPlaneHasServiceSecret(t *testing.T, ctx context.Context, dpNN, usingSvc types.NamespacedName, ret *corev1.Secret, clients K8sClients) func() bool

DataPlaneHasServiceSecret checks if a DataPlane's Service has one owned Secret.

func DataPlaneIsReady

func DataPlaneIsReady(t *testing.T, ctx context.Context, dataplane types.NamespacedName, operatorClient *clientset.Clientset) func() bool

DataPlaneIsReady is a helper function for tests that returns a function that can be used to check if a DataPlane is ready. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlanePredicate

func DataPlanePredicate(
	t *testing.T,
	ctx context.Context,
	dataplaneName types.NamespacedName,
	predicate func(dataplane *operatorv1beta1.DataPlane) bool,
	operatorClient *clientset.Clientset,
) func() bool

DataPlanePredicate is a helper function for tests that returns a function that can be used to check if a DataPlane has a certain state.

func DataPlaneServiceHasNActiveEndpoints

func DataPlaneServiceHasNActiveEndpoints(t *testing.T, ctx context.Context, serviceName types.NamespacedName, clients K8sClients, n int) func() bool

DataPlaneServiceHasNActiveEndpoints is a helper function for tests that returns a function that can be used to check if a Service has active endpoints. Should be used in conjunction with require.Eventually or assert.Eventually.

func DataPlaneUpdateEventually

func DataPlaneUpdateEventually(t *testing.T, ctx context.Context, dataplaneNN types.NamespacedName, clients K8sClients, updateFunc func(*operatorv1beta1.DataPlane)) func() bool

DataPlaneUpdateEventually is a helper function for tests that returns a function that can be used to update the DataPlane. Should be used in conjunction with require.Eventually or assert.Eventually.

func DeployCRDs

func DeployCRDs(ctx context.Context, crdPath string, operatorClient *operatorclient.Clientset, cluster clusters.Cluster) error

DeployCRDs deploys the CRDs commonly used in tests.

func ExtractModuleVersion added in v1.4.0

func ExtractModuleVersion(moduleName string) (string, error)

ExtractModuleVersion extracts version of an imported module in go.mod. If the module is not found, or we failed to parse the module version, it will return an error.

func GatewayClassHasSupportedFeatures added in v1.5.0

func GatewayClassHasSupportedFeatures(t *testing.T, ctx context.Context, gatewayClassName string, clients K8sClients, requiredFeatures ...features.FeatureName) func() bool

GatewayClassHasSupportedFeatures checks if a GatewayClass has the expected supported features.

func GatewayClassIsAccepted

func GatewayClassIsAccepted(t *testing.T, ctx context.Context, gatewayClassName string, clients K8sClients) func() bool

GatewayClassIsAccepted is a helper function for tests that returns a function that can be used to check if a GatewayClass is accepted. Should be used in conjunction with require.Eventually or assert.Eventually.

func GatewayControlPlaneIsProvisioned

func GatewayControlPlaneIsProvisioned(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) func() bool

GatewayControlPlaneIsProvisioned returns a function that checks if a Gateway's ControlPlane is provisioned.

func GatewayDataPlaneIsReady

func GatewayDataPlaneIsReady(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) func() bool

GatewayDataPlaneIsReady returns a function that checks if a Gateway's DataPlane is ready.

func GatewayIPAddressExist

func GatewayIPAddressExist(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) func() bool

GatewayIPAddressExist checks if a Gateway has IP addresses.

func GatewayIsAccepted added in v1.2.2

func GatewayIsAccepted(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) func() bool

GatewayIsAccepted returns a function that checks if a Gateway is scheduled.

func GatewayIsProgrammed

func GatewayIsProgrammed(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) func() bool

GatewayIsProgrammed returns a function that checks if a Gateway is programmed.

func GatewayListenersAreProgrammed

func GatewayListenersAreProgrammed(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) func() bool

GatewayListenersAreProgrammed returns a function that checks if a Gateway's listeners are programmed.

func GatewayNetworkPoliciesExist

func GatewayNetworkPoliciesExist(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) func() bool

GatewayNetworkPoliciesExist is a helper function for tests that returns a function that can be used to check if a Gateway owns a networkpolicy. Should be used in conjunction with require.Eventually or assert.Eventually. Gateway object argument does need to exist in the cluster, thus, the function may be used with Not after the gateway has been deleted, to verify that the networkpolicy has been deleted too.

func GatewayNetworkPolicyForGatewayContainsRules

func GatewayNetworkPolicyForGatewayContainsRules[T ingressRuleT](t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients, rules ...T) func() bool

GatewayNetworkPolicyForGatewayContainsRules is a helper function for tets that returns a function that can be used to check if exactly 1 NetworkPolicy exist for Gateway and if it contains all the provided rules.

func GatewayNotExist

func GatewayNotExist(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) func() bool

GatewayNotExist is a helper function for tests that returns a function to check a if gateway(with specified namespace and name) does not exist.

Should be used in conjunction with require.Eventually or assert.Eventually.

func GetDataPlaneReplicaSets added in v1.6.1

func GetDataPlaneReplicaSets(
	ctx context.Context,
	cli client.Client,
	dp *operatorv1beta1.DataPlane,
) ([]*appsv1.ReplicaSet, error)

GetDataPlaneReplicaSets returns all ReplicaSets owned by the DataPlane's deployment. Returns nil if the deployment or replicasets cannot be found.

func GetResponseBodyContains

func GetResponseBodyContains(t *testing.T, clients K8sClients, httpc *http.Client, request *http.Request, responseContains string) func() bool

GetResponseBodyContains issues an HTTP request and checks if a response body contains a string.

func HPAPredicate

func HPAPredicate(
	t *testing.T,
	ctx context.Context,
	hpaName types.NamespacedName,
	predicate func(hpa *autoscalingv2.HorizontalPodAutoscaler) bool,
	client client.Client,
) func() bool

HPAPredicate is a helper function for tests that returns a function that can be used to check if an HPA has a certain state.

func HTTPRouteUpdateEventually added in v1.4.0

func HTTPRouteUpdateEventually(t *testing.T, ctx context.Context, httpRouteNN types.NamespacedName, clients K8sClients, updateFunc func(*gatewayv1.HTTPRoute)) func() bool

HTTPRouteUpdateEventually is a helper function for tests that returns a function that can be used to update the HTTPRoute. Should be used in conjunction with require.Eventually or assert.Eventually.

func InstallKubernetesConfigurationCRDs added in v1.5.0

func InstallKubernetesConfigurationCRDs(ctx context.Context, cluster clusters.Cluster) error

InstallKubernetesConfigurationCRDs installs the Kong CRDs from the `kong/kubernetes-configuration` module. The version is extracted using ExtractModuleVersion from go.mod.

func MustGetGateway

func MustGetGateway(t *testing.T, ctx context.Context, gatewayNSN types.NamespacedName, clients K8sClients) *gwtypes.Gateway

MustGetGateway is a helper function for tests that conveniently gets a gateway by name. It will fail the test if getting the gateway fails.

func MustGetGatewayClass added in v1.5.0

func MustGetGatewayClass(t *testing.T, ctx context.Context, gatewayClassName string, clients K8sClients) *gwtypes.GatewayClass

MustGetGatewayClass is a helper function for tests that conveniently gets a gatewayclass by name. It will fail the test if getting the gatewayclass fails.

func MustListControlPlaneClusterRoleBindings

func MustListControlPlaneClusterRoleBindings(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) []rbacv1.ClusterRoleBinding

MustListControlPlaneClusterRoleBindings is a helper function for tests that conveniently lists all clusterrolebindings owned by a given controlplane.

func MustListControlPlaneClusterRoles

func MustListControlPlaneClusterRoles(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) []rbacv1.ClusterRole

MustListControlPlaneClusterRoles is a helper function for tests that conveniently lists all clusterroles owned by a given controlplane.

func MustListControlPlaneDeployments

func MustListControlPlaneDeployments(t *testing.T, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, clients K8sClients) []appsv1.Deployment

MustListControlPlaneDeployments is a helper function for tests that conveniently lists all deployments managed by a given controlplane.

func MustListControlPlaneRoleBindings added in v1.6.0

func MustListControlPlaneRoleBindings(t require.TestingT, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, cl client.Client, opts ...client.ListOption) []rbacv1.ClusterRoleBinding

MustListControlPlaneRoleBindings is a helper function for tests that conveniently lists all clusterrolebindings owned by a given controlplane.

func MustListControlPlaneRoles added in v1.6.0

func MustListControlPlaneRoles(t require.TestingT, ctx context.Context, controlplane *operatorv1beta1.ControlPlane, cl client.Client, opts ...client.ListOption) []rbacv1.Role

MustListControlPlaneRoles is a helper function for tests that conveniently lists all roles owned by a given controlplane.

func MustListControlPlanesForGateway

func MustListControlPlanesForGateway(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) []operatorv1beta1.ControlPlane

MustListControlPlanesForGateway is a helper function for tests that conveniently lists all controlplanes managed by a given gateway.

func MustListDataPlaneDeployments

func MustListDataPlaneDeployments(t *testing.T, ctx context.Context, dataplane *operatorv1beta1.DataPlane, clients K8sClients, matchinglabels client.MatchingLabels) []appsv1.Deployment

MustListDataPlaneDeployments is a helper function for tests that conveniently lists all deployments managed by a given dataplane.

func MustListDataPlaneHPAs

func MustListDataPlaneHPAs(t *testing.T, ctx context.Context, dataplane *operatorv1beta1.DataPlane, clients K8sClients, matchinglabels client.MatchingLabels) []autoscalingv2.HorizontalPodAutoscaler

MustListDataPlaneHPAs is a helper function for tests that conveniently lists all HPAs managed by a given dataplane.

func MustListDataPlanePodDisruptionBudgets added in v1.4.0

func MustListDataPlanePodDisruptionBudgets(
	t *testing.T,
	ctx context.Context,
	dataplane *operatorv1beta1.DataPlane,
	clients K8sClients,
	matchinglabels client.MatchingLabels,
) []policyv1.PodDisruptionBudget

MustListDataPlanePodDisruptionBudgets is a helper function for tests that conveniently lists all PDBs managed by a given dataplane.

func MustListDataPlaneServices

func MustListDataPlaneServices(t *testing.T, ctx context.Context, dataplane *operatorv1beta1.DataPlane, mgrClient client.Client, matchingLabels client.MatchingLabels) []corev1.Service

MustListDataPlaneServices is a helper function for tests that conveniently lists all proxy services managed by a given dataplane.

func MustListDataPlanesForGateway

func MustListDataPlanesForGateway(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) []operatorv1beta1.DataPlane

MustListDataPlanesForGateway is a helper function for tests that conveniently lists all dataplanes managed by a given gateway.

func MustListNetworkPoliciesForGateway

func MustListNetworkPoliciesForGateway(t *testing.T, ctx context.Context, gateway *gwtypes.Gateway, clients K8sClients) []networkingv1.NetworkPolicy

MustListNetworkPoliciesForGateway is a helper function for tests that conveniently lists all NetworkPolicies managed by a given gateway.

func MustListServiceEndpointSlices

func MustListServiceEndpointSlices(t *testing.T, ctx context.Context, serviceName types.NamespacedName, mgrClient client.Client) []discoveryv1.EndpointSlice

MustListServiceEndpointSlices is a helper function for tests that conveniently lists all endpointSlices related to a specific service.

func Not

func Not(predicate func() bool) func() bool

Not is a helper function for tests that returns a negation of a predicate.

func ProjectRootPath added in v1.4.0

func ProjectRootPath() string

ProjectRootPath returns the root directory of this project.

func SetupControllerLogger

func SetupControllerLogger(controllerManagerOut string) (func() error, error)

SetupControllerLogger sets up the controller logger. This functions needs to be called before 30sec after the controller packages is loaded, otherwise the logger will not be initialized. Args:

  • controllerManagerOut: the path to the file where the controller logs should be written to or "stdout".

Returns:

  • The close function, that will close the log file if one was created. Should be called after the tests are done.
  • An error on failure.

Types

type BuilderOpt

type BuilderOpt func(*environments.Builder, clusters.Type)

BuilderOpt is an option function for an environment builder.

type ConditionMatcher added in v1.6.0

type ConditionMatcher[T ObjectConditionsAware] struct {
	// contains filtered or unexported fields
}

ConditionMatcher is a struct that implements the Matcher interface for matching Kubernetes objects based on their conditions.

func MatchCondition added in v1.6.0

func MatchCondition[T ObjectConditionsAware](t *testing.T) *ConditionMatcher[T]

MatchCondition is a helper function that creates a new instance of ConditionMatcher.

func (*ConditionMatcher[T]) Message added in v1.6.0

func (cm *ConditionMatcher[T]) Message(msg string) *ConditionMatcher[T]

Message sets the expected message of the condition to match.

func (ConditionMatcher[T]) Predicate added in v1.6.0

func (cm ConditionMatcher[T]) Predicate() func(T) bool

Predicate returns a function that checks if the object has conditions that match all the predicates defined in the ConditionMatcher. It is supposed to be used with require's/assert's Eventually function.

func (*ConditionMatcher[T]) Reason added in v1.6.0

func (cm *ConditionMatcher[T]) Reason(reason string) *ConditionMatcher[T]

Reason sets the expected reason of the condition to match.

func (*ConditionMatcher[T]) Status added in v1.6.0

func (cm *ConditionMatcher[T]) Status(status metav1.ConditionStatus) *ConditionMatcher[T]

Status sets the expected status of the condition to match.

func (*ConditionMatcher[T]) Type added in v1.6.0

func (cm *ConditionMatcher[T]) Type(typ string) *ConditionMatcher[T]

Type sets the expected type of the condition to match.

type K8sClients

type K8sClients struct {
	K8sClient           *kubernetesclient.Clientset
	OperatorClient      *configurationclient.Clientset
	GatewayClient       *gatewayclient.Clientset
	ConfigurationClient *configurationclient.Clientset
	MgrClient           ctrlruntimeclient.Client
}

K8sClients is a struct that contains all the Kubernetes clients needed by the tests.

func NewK8sClients

func NewK8sClients(env environments.Environment) (K8sClients, error)

NewK8sClients returns a new K8sClients struct with all the clients needed by the tests.

type Matcher added in v1.6.0

type Matcher[T client.Object] interface {
	Match() func(T) bool
}

Matcher is an interface that defines a method for matching Kubernetes objects.

type ObjectConditionsAware added in v1.6.0

type ObjectConditionsAware interface {
	k8sutils.ConditionsAware
	client.Object
}

ObjectConditionsAware is an interface that extends the ConditionsAware interface from the k8sutils package. It is used to define objects that have conditions associated with them.

type PodDisruptionBudgetRequirement added in v1.4.0

type PodDisruptionBudgetRequirement func(policyv1.PodDisruptionBudget) bool

PodDisruptionBudgetRequirement is a function type used to check if a PodDisruptionBudget meets a certain requirement.

func AnyPodDisruptionBudget added in v1.4.0

func AnyPodDisruptionBudget() PodDisruptionBudgetRequirement

AnyPodDisruptionBudget returns a function that accepts any PodDisruptionBudget.

type Predicates added in v1.6.0

type Predicates[T client.Object] struct {
	// contains filtered or unexported fields
}

Predicates aggregates a list of predicates to be used for matching objects in a Kubernetes cluster. It is a generic type that can be used with any Kubernetes object type that implements the client.Object interface.

func ObjectPredicates added in v1.6.0

func ObjectPredicates[
	T client.Object,
](
	t *testing.T,
	cl client.Client,
	predicates ...func(T) bool,
) Predicates[T]

ObjectPredicates creates a new instance of Predicates with the provided client.Client and a list of predicates. It is a helper function that simplifies the creation of Predicates for testing purposes.

func (Predicates[T]) Add added in v1.6.0

func (p Predicates[T]) Add(
	f func(T) bool,
) Predicates[T]

Add adds a new predicate to the list of predicates.

func (Predicates[T]) AddMatch added in v1.6.0

func (p Predicates[T]) AddMatch(
	m Matcher[T],
) Predicates[T]

AddMatch adds a new matcher to the list of predicates.

func (Predicates[T]) Match added in v1.6.0

func (p Predicates[T]) Match(obj T) func() bool

Match performs a match using the previously defined predicates.

Jump to

Keyboard shortcuts

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