Documentation
¶
Index ¶
- func CheckAllConditionsFalse(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
- func CheckAllConditionsTrue(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
- func CreateHTTPClient(tlsSecret *corev1.Secret, host string) (*http.Client, error)
- func GenerateGateway(gatewayNSN types.NamespacedName, gatewayClass *gatewayv1.GatewayClass, ...) *gwtypes.Gateway
- func GenerateGatewayConfiguration(namespace string, opts ...gatewayConfigurationOption) *operatorv2beta1.GatewayConfiguration
- func GenerateHTTPRoute(namespace string, gatewayName, serviceName string, ...) *gatewayv1.HTTPRoute
- func GetDefaultDataPlaneBaseImage() string
- func GetDefaultDataPlaneImage() string
- func MustBuildRequest(t *testing.T, ctx context.Context, method, url, host string) *http.Request
- func MustCreateHTTPClient(t *testing.T, tlsSecret *corev1.Secret, host string) *http.Client
- func MustGenerateGatewayClass(t *testing.T, parametersRefs ...gatewayv1.ParametersReference) *gatewayv1.GatewayClass
- func SetDefaultDataPlaneBaseImage(image string)
- func SetDefaultDataPlaneImage(image string)
- func SetupControllerOperatorResources(ctx context.Context, namespace string, cl client.Client) (func(), error)
- func SetupFakePodLabels() (cleanup func(), err error)
- func SetupKubernetesServiceHost(restConfig *rest.Config)
- func SetupTelepresence(ctx context.Context) (func(), error)
- func SetupTestEnv(t *testing.T, ctx context.Context, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
- func TLSSecretData(t *testing.T, ca Cert, c Cert) map[string][]byte
- func WatchFor[T client.Object](t *testing.T, ctx context.Context, w apiwatch.Interface, ...) T
- type Cert
- type ConditionsChecker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAllConditionsFalse ¶
func CheckAllConditionsFalse(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
CheckAllConditionsFalse returns true if all the conditions with given type in `conditionTypes` are set to `False` in the given resource. If it returns `false`, the second return value contains a message to tell what conditions are not `False`.
func CheckAllConditionsTrue ¶
func CheckAllConditionsTrue(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
CheckAllConditionsTrue returns true if all the conditions with given type in `conditionTypes` are set to `True` in the given resource. If it returns `false`, the second return value contains a message to tell what conditions are not `True`.
func CreateHTTPClient ¶
CreateHTTPClient creates an HTTP client with the given TLS secret and host and returns an error if it fails
func GenerateGateway ¶
func GenerateGateway(gatewayNSN types.NamespacedName, gatewayClass *gatewayv1.GatewayClass, opts ...func(gateway *gatewayv1.Gateway)) *gwtypes.Gateway
GenerateGateway generates a Gateway to be used in tests
func GenerateGatewayConfiguration ¶
func GenerateGatewayConfiguration(namespace string, opts ...gatewayConfigurationOption) *operatorv2beta1.GatewayConfiguration
GenerateGatewayConfiguration generates a GatewayConfiguration to be used in tests
func GenerateHTTPRoute ¶
func GenerateHTTPRoute(namespace string, gatewayName, serviceName string, opts ...func(*gatewayv1.HTTPRoute)) *gatewayv1.HTTPRoute
GenerateHTTPRoute generates an HTTPRoute to be used in tests
func GetDefaultDataPlaneBaseImage ¶
func GetDefaultDataPlaneBaseImage() string
GetDefaultDataPlaneBaseImage returns the default data plane base image.
func GetDefaultDataPlaneImage ¶
func GetDefaultDataPlaneImage() string
GetDefaultDataPlaneImage returns the default data plane image.
func MustBuildRequest ¶
MustBuildRequest creates an HTTP request with the given method, URL, and host
func MustCreateHTTPClient ¶
MustCreateHTTPClient creates an HTTP client with the given TLS secret and host
func MustGenerateGatewayClass ¶
func MustGenerateGatewayClass(t *testing.T, parametersRefs ...gatewayv1.ParametersReference) *gatewayv1.GatewayClass
MustGenerateGatewayClass generates the default GatewayClass to be used in tests
func SetDefaultDataPlaneBaseImage ¶
func SetDefaultDataPlaneBaseImage(image string)
SetDefaultDataPlaneBaseImage sets the default data plane base image.
func SetDefaultDataPlaneImage ¶
func SetDefaultDataPlaneImage(image string)
SetDefaultDataPlaneImage sets the default data plane image.
func SetupControllerOperatorResources ¶ added in v2.1.1
func SetupControllerOperatorResources( ctx context.Context, namespace string, cl client.Client, ) (func(), error)
SetupControllerOperatorResources sets up the controller namespace and CA secret that are required for the operator to run. It returns a cleanup function that should be called when done.
func SetupFakePodLabels ¶ added in v2.1.1
func SetupFakePodLabels() (cleanup func(), err error)
SetupFakePodLabels creates a fake pod labels file for testing. The controller expects this file when RunningOnKubernetes() is true. This function should be called after SetupKubernetesServiceHost().
Returns a cleanup function that should be called to remove the created file, and an error if the setup failed.
func SetupKubernetesServiceHost ¶ added in v2.1.1
SetupKubernetesServiceHost sets KUBERNETES_SERVICE_HOST environment variable from the cluster config if not already set. This enables NetworkPolicy creation in tests by making RunningOnKubernetes() return true. See: https://github.com/Kong/kong-operator/issues/2074
func SetupTelepresence ¶
SetupTelepresence installs the telepresence traffic manager in the cluster and connects to it. It returns a cleanup function that should be called when the test is done.
func SetupTestEnv ¶
func SetupTestEnv(t *testing.T, ctx context.Context, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
SetupTestEnv is a helper function for tests which conveniently creates a cluster cleaner (to clean up test resources automatically after the test finishes) and creates a new namespace for the test to use. The namespace is being automatically deleted during the test teardown using t.Cleanup().
func TLSSecretData ¶
TLSSecretData creates TLS secret data that can be then used as Secret.Data field when using certificates secrets in tests.
func WatchFor ¶ added in v2.1.1
func WatchFor[ T client.Object, ]( t *testing.T, ctx context.Context, w apiwatch.Interface, eventType apiwatch.EventType, timeout time.Duration, predicate func(T) bool, failMsg string, ) T
WatchFor watches for an event of type eventType using the provided watch.Interface. It returns when either context is done - and then it marks the test as failed - or when the event has been received and predicate returned true. This is a more generic helper watch function that can watch for both our own CRDs and other resources.
Types ¶
type Cert ¶
type Cert struct {
Cert *x509.Certificate
CertPEM *bytes.Buffer
Key *ecdsa.PrivateKey
KeyPEM *bytes.Buffer
}
Cert represents a TLS certificate that can be used for testing purposes.
func CreateCert ¶
func CreateCert(t *testing.T, name string, caCert *x509.Certificate, caPrivKey *ecdsa.PrivateKey) Cert
CreateCert creates a certificates using the provided CA and its private key.
type ConditionsChecker ¶
type ConditionsChecker func(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
ConditionsChecker is a function type that checks the conditions of a resource. It takes a resource of type k8sutils.ConditionsAware and a variadic number of condition types. It returns a boolean indicating whether all specified conditions are met and a string message.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package kcfg (Kubernetes configuration) is a single source of truth for common Kubernetes configuration used by tests - CRDs, RBAC, namespaces, etc.
|
Package kcfg (Kubernetes configuration) is a single source of truth for common Kubernetes configuration used by tests - CRDs, RBAC, namespaces, etc. |