Documentation
¶
Index ¶
- Constants
- func CheckAllConditionsFalse(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
- func CheckAllConditionsTrue(resource k8sutils.ConditionsAware, conditionTypes ...kcfgconsts.ConditionType) (bool, string)
- func CountHTTPGetResponses(t *testing.T, proxyURL *url.URL, cfg CountHTTPResponsesConfig, ...) map[string]int
- func CreateHTTPClient(tlsSecret *corev1.Secret, host string) (*http.Client, error)
- func CreateIngressClass(ctx context.Context, ingressClassName string, client *kubernetes.Clientset) error
- func CreateKongLicense(ctx context.Context, cl client.Client, generateNamePrefix string) (cleanup func() error, err error)
- func CreateKongLicenseForTest(t *testing.T, ctx context.Context, cl client.Client, generateNamePrefix string)
- func DefaultHTTPClient(opts ...HTTPClientOption) *http.Client
- func DeployGateway(ctx context.Context, client *gatewayclient.Clientset, ...) (*gatewayapi.Gateway, error)
- func DeployGatewayClass(ctx context.Context, client *gatewayclient.Clientset, gatewayClassName string, ...) (*gatewayapi.GatewayClass, error)
- func DistributionOfMapValues(counter map[string]int) map[string]float64
- func DumpDiagnosticsIfFailed(ctx context.Context, t *testing.T, cluster clusters.Cluster) string
- func EchoResponds(t *testing.T, protocol Protocol, url string, podName string, tlsOpt ...TLSOpt) error
- func EventuallyExpectHTTP404WithNoRoute(t *testing.T, proxyURL *url.URL, host string, path string, ...)
- func EventuallyGETPath(t *testing.T, proxyURL *url.URL, host string, path string, ...)
- func ExitOnErr(ctx context.Context, err error)
- func ExitOnErrWithCode(ctx context.Context, err error, exitCode int, fns ...CleanupFunc)
- 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 GenerateTCPRoute(namespace string, gatewayName, serviceName string, portNumber int, ...) *gatewayv1.TCPRoute
- func GenerateTLSRoute(namespace string, gatewayName, serviceName string, portNumber int, ...) *gatewayv1.TLSRoute
- func GetDefaultDataPlaneBaseImage() string
- func GetDefaultDataPlaneImage() string
- func GetFreePort(t *testing.T) int
- func GetGatewayIsLinkedCallback(ctx context.Context, t *testing.T, c *gatewayclient.Clientset, ...) func() bool
- func GetGatewayIsUnlinkedCallback(ctx context.Context, t *testing.T, c *gatewayclient.Clientset, ...) func() bool
- func GetKongDBMode(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (dpconf.DBMode, error)
- func GetKongLicenses(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) ([]*kong.License, error)
- func GetKongRouterFlavor(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (dpconf.RouterFlavor, error)
- func GetVerifyProgrammedConditionCallback(t *testing.T, c *gatewayclient.Clientset, protocolType gatewayapi.ProtocolType, ...) func() bool
- func KongWithHelmChartVersion(builder *ktfkong.Builder, version string)
- func KongWithProxyEnvVar(builder *ktfkong.Builder, name, value string)
- func LabelValueForTest(t *testing.T) 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 MustHTTPRequest(t *testing.T, method string, host, path string, headers map[string]string) *http.Request
- func NewKongAdminClient(proxyAdminURL *url.URL, kongTestPassword string) (*kong.Client, error)
- func ProjectRootPath() string
- func RemoveCluster(ctx context.Context, cluster clusters.Cluster) error
- func SetDefaultDataPlaneBaseImage(image string)
- func SetDefaultDataPlaneImage(image string)
- func Setup(ctx context.Context, t *testing.T, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
- 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 TeardownCluster(ctx context.Context, t *testing.T, cluster clusters.Cluster)
- func UpdateWithRetry[T any](ctx context.Context, cl getUpdater[T], name string, mutate func(T)) (T, error)
- func WaitForDeploymentRollout(ctx context.Context, t *testing.T, cluster clusters.Cluster, ...)
- func WatchFor[T client.Object](t *testing.T, ctx context.Context, w apiwatch.Interface, ...) T
- type Cert
- type CleanupFunc
- type ConditionsChecker
- type ControllerManagerOpt
- type CountHTTPResponsesConfig
- type HTTPClientOption
- type HTTPSOptions
- type KongBuilder
- type KongVersion
- type Protocol
- type ResponseMatcher
- type TLSOpt
- type TooOldKongGatewayError
Constants ¶
const DefaultGatewayName = ic.DefaultGatewayName
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 CountHTTPGetResponses ¶ added in v2.2.0
func CountHTTPGetResponses(t *testing.T, proxyURL *url.URL, cfg CountHTTPResponsesConfig, matchers ...ResponseMatcher) map[string]int
CountHTTPGetResponses bridges to ingress-controller test helpers.
func CreateHTTPClient ¶
CreateHTTPClient creates an HTTP client with the given TLS secret and host and returns an error if it fails.
func CreateIngressClass ¶ added in v2.2.0
func CreateIngressClass(ctx context.Context, ingressClassName string, client *kubernetes.Clientset) error
CreateIngressClass bridges to ingress-controller test helpers.
func CreateKongLicense ¶ added in v2.3.0
func CreateKongLicense(ctx context.Context, cl client.Client, generateNamePrefix string) (cleanup func() error, err error)
CreateKongLicense creates a KongLicense resource read from the KONG_LICENSE_DATA environment variable, retrying creation a few times in case the cluster isn't fully ready yet. It returns an error if KONG_LICENSE_DATA is not set.
func CreateKongLicenseForTest ¶ added in v2.3.0
func CreateKongLicenseForTest(t *testing.T, ctx context.Context, cl client.Client, generateNamePrefix string)
CreateKongLicenseForTest is a *testing.T friendly wrapper around CreateKongLicense.
func DefaultHTTPClient ¶ added in v2.2.0
func DefaultHTTPClient(opts ...HTTPClientOption) *http.Client
DefaultHTTPClient bridges to ingress-controller test helpers.
func DeployGateway ¶ added in v2.2.0
func DeployGateway(ctx context.Context, client *gatewayclient.Clientset, namespace, gatewayClassName string, opts ...func(*gatewayapi.Gateway)) (*gatewayapi.Gateway, error)
DeployGateway bridges to ingress-controller test helpers.
func DeployGatewayClass ¶ added in v2.2.0
func DeployGatewayClass(ctx context.Context, client *gatewayclient.Clientset, gatewayClassName string, opts ...func(*gatewayapi.GatewayClass)) (*gatewayapi.GatewayClass, error)
DeployGatewayClass bridges to ingress-controller test helpers.
func DistributionOfMapValues ¶ added in v2.2.0
DistributionOfMapValues bridges to ingress-controller test helpers.
func DumpDiagnosticsIfFailed ¶ added in v2.2.0
DumpDiagnosticsIfFailed bridges to ingress-controller test helpers.
func EchoResponds ¶ added in v2.2.0
func EchoResponds(t *testing.T, protocol Protocol, url string, podName string, tlsOpt ...TLSOpt) error
EchoResponds takes a TCP, TLS or UDP address URL and a Pod name and checks if a go-echo instance is running on that Pod at that address. For TLS tlsOpt is required, otherwise it panics. It sends a message and checks if returned one matches. It returns an error with an explanation, wraps typical errors as io.EOF or syscall.ECONNRESET.
func EventuallyExpectHTTP404WithNoRoute ¶ added in v2.2.0
func EventuallyExpectHTTP404WithNoRoute( t *testing.T, proxyURL *url.URL, host string, path string, httpsOpts *HTTPSOptions, waitDuration time.Duration, waitTick time.Duration, headers map[string]string, )
EventuallyExpectHTTP404WithNoRoute bridges to ingress-controller test helpers.
func EventuallyGETPath ¶ added in v2.2.0
func EventuallyGETPath( t *testing.T, proxyURL *url.URL, host string, path string, httpsOpts *HTTPSOptions, statusCode int, bodyContent string, requestHeaders map[string]string, waitDuration time.Duration, waitTick time.Duration, responseMatchers ...ResponseMatcher, )
EventuallyGETPath bridges to ingress-controller test helpers.
func ExitOnErrWithCode ¶ added in v2.2.0
func ExitOnErrWithCode(ctx context.Context, err error, exitCode int, fns ...CleanupFunc)
ExitOnErrWithCode bridges to ingress-controller test helpers.
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 GenerateTCPRoute ¶ added in v2.3.0
func GenerateTCPRoute(namespace string, gatewayName, serviceName string, portNumber int, opts ...func(*gatewayv1.TCPRoute)) *gatewayv1.TCPRoute
GenerateTCPRoute generates a TCPRoute to be used in tests.
func GenerateTLSRoute ¶ added in v2.2.0
func GenerateTLSRoute(namespace string, gatewayName, serviceName string, portNumber int, opts ...func(*gatewayv1.TLSRoute)) *gatewayv1.TLSRoute
GenerateTLSRoute generates a TLSRoute 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 GetFreePort ¶ added in v2.2.0
GetFreePort bridges to ingress-controller test helpers.
func GetGatewayIsLinkedCallback ¶ added in v2.2.0
func GetGatewayIsLinkedCallback(ctx context.Context, t *testing.T, c *gatewayclient.Clientset, protocolType gatewayapi.ProtocolType, namespace, name string) func() bool
GetGatewayIsLinkedCallback bridges to ingress-controller test helpers.
func GetGatewayIsUnlinkedCallback ¶ added in v2.2.0
func GetGatewayIsUnlinkedCallback(ctx context.Context, t *testing.T, c *gatewayclient.Clientset, protocolType gatewayapi.ProtocolType, namespace, name string) func() bool
GetGatewayIsUnlinkedCallback bridges to ingress-controller test helpers.
func GetKongDBMode ¶ added in v2.2.0
func GetKongDBMode(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (dpconf.DBMode, error)
GetKongDBMode bridges to ingress-controller test helpers.
func GetKongLicenses ¶ added in v2.2.0
func GetKongLicenses(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) ([]*kong.License, error)
GetKongLicenses bridges to ingress-controller test helpers.
func GetKongRouterFlavor ¶ added in v2.2.0
func GetKongRouterFlavor(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (dpconf.RouterFlavor, error)
GetKongRouterFlavor bridges to ingress-controller test helpers.
func GetVerifyProgrammedConditionCallback ¶ added in v2.2.0
func GetVerifyProgrammedConditionCallback(t *testing.T, c *gatewayclient.Clientset, protocolType gatewayapi.ProtocolType, namespace, name string, expectedStatus metav1.ConditionStatus) func() bool
GetVerifyProgrammedConditionCallback bridges to ingress-controller test helpers.
func KongWithHelmChartVersion ¶ added in v2.2.0
KongWithHelmChartVersion pins helm chart version on the kong builder.
func KongWithProxyEnvVar ¶ added in v2.2.0
KongWithProxyEnvVar sets an env var on the kong builder.
func LabelValueForTest ¶ added in v2.2.0
LabelValueForTest bridges to ingress-controller test helpers.
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 MustHTTPRequest ¶ added in v2.2.0
func MustHTTPRequest(t *testing.T, method string, host, path string, headers map[string]string) *http.Request
MustHTTPRequest bridges to ingress-controller test helpers.
func NewKongAdminClient ¶ added in v2.2.0
NewKongAdminClient bridges to ingress-controller test helpers.
func ProjectRootPath ¶ added in v2.2.0
func ProjectRootPath() string
ProjectRootPath returns the root directory of this project.
func RemoveCluster ¶ added in v2.2.0
RemoveCluster bridges to ingress-controller test helpers.
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 Setup ¶ added in v2.2.0
func Setup(ctx context.Context, t *testing.T, env environments.Environment) (*corev1.Namespace, *clusters.Cleaner)
Setup bridges to ingress-controller test helpers for namespace setup.
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 TeardownCluster ¶ added in v2.2.0
TeardownCluster bridges to ingress-controller test helpers.
func UpdateWithRetry ¶ added in v2.3.1
func UpdateWithRetry[T any](ctx context.Context, cl getUpdater[T], name string, mutate func(T)) (T, error)
UpdateWithRetry re-fetches the object called name, applies mutate to the fresh copy, and updates it, retrying on conflict.
On failure it returns the zero value of T alongside the error. This matters: client-go's generated clientsets return a zero-valued object alongside an error on failure, so assigning their result straight into a variable that a retry loop later reads back (e.g. for its .Name) silently poisons every subsequent iteration. UpdateWithRetry only assigns its return value on success, so callers can never be handed a half-written object.
func WaitForDeploymentRollout ¶ added in v2.2.0
func WaitForDeploymentRollout(ctx context.Context, t *testing.T, cluster clusters.Cluster, namespace, name string)
WaitForDeploymentRollout bridges to ingress-controller test helpers.
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 CleanupFunc ¶ added in v2.2.0
type CleanupFunc = ic.CleanupFunc
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.
type ControllerManagerOpt ¶ added in v2.2.0
type ControllerManagerOpt = ic.ControllerManagerOpt
func ControllerManagerOptAdditionalWatchNamespace ¶ added in v2.2.0
func ControllerManagerOptAdditionalWatchNamespace(namespace string) ControllerManagerOpt
ControllerManagerOptAdditionalWatchNamespace bridges to ingress-controller test helpers.
func ControllerManagerOptFlagUseLastValidConfigForFallback ¶ added in v2.2.0
func ControllerManagerOptFlagUseLastValidConfigForFallback() ControllerManagerOpt
ControllerManagerOptFlagUseLastValidConfigForFallback bridges to ingress-controller test helpers.
type CountHTTPResponsesConfig ¶ added in v2.2.0
type CountHTTPResponsesConfig = ic.CountHTTPResponsesConfig
type HTTPClientOption ¶ added in v2.2.0
type HTTPClientOption = ic.HTTPClientOption
func WithInsecureSkipVerify ¶ added in v2.2.0
func WithInsecureSkipVerify() HTTPClientOption
func WithResolveHostTo ¶ added in v2.2.0
func WithResolveHostTo(host string) HTTPClientOption
WithResolveHostTo bridges to ingress-controller test helpers.
type HTTPSOptions ¶ added in v2.2.0
type HTTPSOptions = ic.HTTPSOptions
type KongBuilder ¶ added in v2.2.0
func GenerateKongBuilder ¶ added in v2.2.0
func GenerateKongBuilder(ctx context.Context) (*KongBuilder, []string, error)
GenerateKongBuilder bridges to ingress-controller test helpers.
func GenerateKongBuilderWithController ¶ added in v2.2.0
func GenerateKongBuilderWithController() (*KongBuilder, error)
GenerateKongBuilderWithController bridges to ingress-controller test helpers.
type KongVersion ¶ added in v2.2.0
func GetKongVersion ¶ added in v2.2.0
func GetKongVersion(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (KongVersion, error)
GetKongVersion bridges to ingress-controller test helpers.
func ValidateMinimalSupportedKongVersion ¶ added in v2.2.0
func ValidateMinimalSupportedKongVersion(ctx context.Context, proxyAdminURL *url.URL, kongTestPassword string) (KongVersion, error)
ValidateMinimalSupportedKongVersion bridges to ingress-controller test helpers.
type ResponseMatcher ¶ added in v2.2.0
type ResponseMatcher = ic.ResponseMatcher
func MatchRespByStatusAndContent ¶ added in v2.2.0
func MatchRespByStatusAndContent(responseName string, expectedStatusCode int, expectedBodyContents string) ResponseMatcher
MatchRespByStatusAndContent bridges to ingress-controller test helpers.
type TooOldKongGatewayError ¶ added in v2.2.0
type TooOldKongGatewayError = ic.TooOldKongGatewayError
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. |