Documentation
¶
Index ¶
- Constants
- Variables
- func AdminAPIOptFns(fns ...mocks.AdminAPIHandlerOpt) []mocks.AdminAPIHandlerOpt
- func CreateNamespace(ctx context.Context, t *testing.T, client ctrlclient.Client) corev1.Namespace
- func CreatePod(ctx context.Context, t *testing.T, client ctrlclient.Client, ns string) corev1.Pod
- func DumpLogsIfTestFailed(t *testing.T, logs LogsObserver)
- func NewControllerClient(t *testing.T, scheme *runtime.Scheme, cfg *rest.Config) ctrlclient.Client
- func Scheme(t *testing.T, opts ...SchemeOption) *k8sruntime.Scheme
- func Setup(t *testing.T, scheme *k8sruntime.Scheme, optModifiers ...OptionModifier) *rest.Config
- func SetupManager(ctx context.Context, t *testing.T, mgrID manager.ID, envcfg *rest.Config, ...) *manager.Manager
- func StartAdminAPIServerMock(t *testing.T, opts ...mocks.AdminAPIHandlerOpt) *httptest.Server
- func StartReconcilers(ctx context.Context, t *testing.T, scheme *runtime.Scheme, cfg *rest.Config, ...)
- func WaitForManagerStart(t *testing.T, logsObserver LogsObserver)
- func WithAdmissionWebhookEnabled(key, cert []byte, port int) func(cfg *managercfg.Config)
- func WithCacheSyncTimeout(d time.Duration) func(cfg *managercfg.Config)
- func WithDefaultEnvTestsConfig(envcfg *rest.Config) func(cfg *managercfg.Config)
- func WithDiagnosticsServer(port int) func(cfg *managercfg.Config)
- func WithDiagnosticsWithoutServer() func(cfg *managercfg.Config)
- func WithFeatureGate(name string, enabled bool) func(cfg *managercfg.Config)
- func WithGatewayAPI(t *testing.T, s *k8sruntime.Scheme)
- func WithGatewayAPIControllers() func(cfg *managercfg.Config)
- func WithGatewayFeatureEnabled(cfg *managercfg.Config)
- func WithGatewayToReconcile(gatewayNN string) func(cfg *managercfg.Config)
- func WithHealthProbePort(port int) func(cfg *managercfg.Config)
- func WithIngressClass(name string) func(cfg *managercfg.Config)
- func WithKong(t *testing.T, s *k8sruntime.Scheme)
- func WithKongAdminURLs(urls ...string) func(cfg *managercfg.Config)
- func WithKongServiceFacadeFeatureEnabled() func(cfg *managercfg.Config)
- func WithKongUpstreamPolicyEnabled() func(cfg *managercfg.Config)
- func WithMetricsAddr(addr string) func(cfg *managercfg.Config)
- func WithProfiling() func(cfg *managercfg.Config)
- func WithProxySyncSeconds(period float32) func(cfg *managercfg.Config)
- func WithPublishService(namespace string) func(cfg *managercfg.Config)
- func WithPublishStatusAddress(addresses []string, udps []string) func(cfg *managercfg.Config)
- func WithTelemetry(splunkEndpoint string, telemetryPeriod time.Duration) managercfg.Opt
- func WithUpdateStatus() func(cfg *managercfg.Config)
- type LogsObserver
- type OptionModifier
- type Options
- type SchemeOption
- type TelemetryServer
Constants ¶
const ( // PublishServiceName is the name of the publish service used in Gateway API tests. PublishServiceName = "publish-svc" // ManagerStartupWaitTime is the time to wait for the manager to start. ManagerStartupWaitTime = 5 * time.Second // ManagerStartupWaitInterval is the interval to wait for the manager to start. ManagerStartupWaitInterval = time.Millisecond )
Variables ¶
var DefaultEnvTestOpts = Options{ InstallGatewayCRDs: true, InstallKongCRDs: true, }
Functions ¶
func AdminAPIOptFns ¶
func AdminAPIOptFns(fns ...mocks.AdminAPIHandlerOpt) []mocks.AdminAPIHandlerOpt
AdminAPIOptFns wraps a variadic list of mocks.AdminAPIHandlerOpt and returns a slice containing all of them. The purpose of this is func is to make the call sites a bit less verbose.
NOTE: Ideally we'd refactor the RunManager() so that it'd not need to accept an empty slice of mocks.AdminAPIHandlerOpt or a call to AdminAPIOptFns() with no arguments but we can't accept 2 variadic list parameters. A slight refactor might be beneficial here.
func CreateNamespace ¶
CreateNamespace creates namespace using the provided client and returns it.
func DumpLogsIfTestFailed ¶ added in v3.1.0
func DumpLogsIfTestFailed(t *testing.T, logs LogsObserver)
DumpLogsIfTestFailed dumps the provided logs the if the test failed.
func NewControllerClient ¶
NewControllerClient returns a new controller-runtime Client for provided runtime.Scheme and rest.Config.
func Scheme ¶
func Scheme(t *testing.T, opts ...SchemeOption) *k8sruntime.Scheme
Scheme returns a new scheme with the default Kubernetes types registered. It accepts optional SchemeOptions to register additional types.
func Setup ¶
func Setup(t *testing.T, scheme *k8sruntime.Scheme, optModifiers ...OptionModifier) *rest.Config
Setup sets up the envtest environment which will be stopped on test cleanup using t.Cleanup().
Note: If you want apiserver output on stdout set KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT to true when running tests.
func SetupManager ¶ added in v3.4.4
func StartAdminAPIServerMock ¶
StartAdminAPIServerMock starts a mock Kong Admin API server. It accepts a variadic list of options which can configure the test server.
Server's .Close() method will be called during test's cleanup.
func StartReconcilers ¶
func StartReconcilers(ctx context.Context, t *testing.T, scheme *runtime.Scheme, cfg *rest.Config, reconcilers ...controllers.Reconciler)
StartReconcilers creates a controller manager and starts the provided reconciler as its runnable. It also adds a t.Cleanup which waits for the manager to exit so that the test can be self contained and logs from different tests' managers don't mix up.
func WaitForManagerStart ¶ added in v3.1.1
func WaitForManagerStart(t *testing.T, logsObserver LogsObserver)
WaitForManagerStart waits for the manager to start. The indication of the manager starting is the "Starting manager" log entry that is emitted just before the manager starts. Note: We cannot rely here on the manager's readiness probe because it returns 200 OK as soon as it starts listening which happens before the manager actually starts.
func WithAdmissionWebhookEnabled ¶ added in v3.1.1
func WithAdmissionWebhookEnabled(key, cert []byte, port int) func(cfg *managercfg.Config)
func WithCacheSyncTimeout ¶ added in v3.4.4
func WithCacheSyncTimeout(d time.Duration) func(cfg *managercfg.Config)
func WithDefaultEnvTestsConfig ¶ added in v3.4.4
func WithDefaultEnvTestsConfig(envcfg *rest.Config) func(cfg *managercfg.Config)
WithDefaultEnvTestsConfig modifies a managercfg.Config for use in envtests.
func WithDiagnosticsServer ¶
func WithDiagnosticsServer(port int) func(cfg *managercfg.Config)
func WithDiagnosticsWithoutServer ¶ added in v3.4.4
func WithDiagnosticsWithoutServer() func(cfg *managercfg.Config)
func WithFeatureGate ¶ added in v3.4.4
func WithFeatureGate(name string, enabled bool) func(cfg *managercfg.Config)
func WithGatewayAPI ¶
func WithGatewayAPI(t *testing.T, s *k8sruntime.Scheme)
WithGatewayAPI registers the Gateway API types with the scheme.
func WithGatewayAPIControllers ¶
func WithGatewayAPIControllers() func(cfg *managercfg.Config)
func WithGatewayFeatureEnabled ¶
func WithGatewayFeatureEnabled(cfg *managercfg.Config)
func WithGatewayToReconcile ¶ added in v3.1.0
func WithGatewayToReconcile(gatewayNN string) func(cfg *managercfg.Config)
func WithHealthProbePort ¶
func WithHealthProbePort(port int) func(cfg *managercfg.Config)
func WithIngressClass ¶
func WithIngressClass(name string) func(cfg *managercfg.Config)
func WithKong ¶
func WithKong(t *testing.T, s *k8sruntime.Scheme)
WithKong registers the Kong types with the scheme.
func WithKongAdminURLs ¶ added in v3.1.1
func WithKongAdminURLs(urls ...string) func(cfg *managercfg.Config)
func WithKongServiceFacadeFeatureEnabled ¶ added in v3.1.0
func WithKongServiceFacadeFeatureEnabled() func(cfg *managercfg.Config)
func WithKongUpstreamPolicyEnabled ¶ added in v3.5.0
func WithKongUpstreamPolicyEnabled() func(cfg *managercfg.Config)
func WithMetricsAddr ¶ added in v3.4.0
func WithMetricsAddr(addr string) func(cfg *managercfg.Config)
func WithProfiling ¶
func WithProfiling() func(cfg *managercfg.Config)
func WithProxySyncSeconds ¶
func WithProxySyncSeconds(period float32) func(cfg *managercfg.Config)
func WithPublishService ¶
func WithPublishService(namespace string) func(cfg *managercfg.Config)
func WithPublishStatusAddress ¶
func WithPublishStatusAddress(addresses []string, udps []string) func(cfg *managercfg.Config)
func WithTelemetry ¶ added in v3.4.4
func WithTelemetry(splunkEndpoint string, telemetryPeriod time.Duration) managercfg.Opt
func WithUpdateStatus ¶
func WithUpdateStatus() func(cfg *managercfg.Config)
Types ¶
type LogsObserver ¶ added in v3.1.1
type LogsObserver interface { // All returns all the logs that have been observed so far. All() []observer.LoggedEntry }
func CreateTestLogger ¶ added in v3.1.0
CreateTestLogger creates a logger for use in tests. It returns the logger - which is also added to the context - and the observer which can be used to dump logs if the test fails.
func RunManager ¶
func RunManager( ctx context.Context, t *testing.T, envcfg *rest.Config, adminAPIOpts []mocks.AdminAPIHandlerOpt, modifyCfgFns ...managercfg.Opt, ) LogsObserver
RunManager runs the manager in a goroutine. It's possible to modify the manager's configuration by passing in modifyCfgFns. The manager is stopped when the context is canceled.
type OptionModifier ¶
func WithInstallGatewayCRDs ¶
func WithInstallGatewayCRDs(install bool) OptionModifier
func WithInstallKongCRDs ¶
func WithInstallKongCRDs(install bool) OptionModifier
type SchemeOption ¶
type SchemeOption func(t *testing.T, s *k8sruntime.Scheme)
type TelemetryServer ¶ added in v3.5.0
type TelemetryServer struct {
// contains filtered or unexported fields
}
TelemetryServer represents a server that listens for telemetry data over a TLS connection.
func NewTelemetryServer ¶ added in v3.5.0
func NewTelemetryServer(t *testing.T) *TelemetryServer
NewTelemetryServer creates and configures a new TelemetryServer instance. It generates a TLS listener using a self-signed certificate.
func (*TelemetryServer) Endpoint ¶ added in v3.5.0
func (ts *TelemetryServer) Endpoint() string
Endpoint returns the address of the telemetry server.
func (*TelemetryServer) ReportChan ¶ added in v3.5.0
func (ts *TelemetryServer) ReportChan() <-chan []byte
ReportChan provides access to the telemetry report channel.
func (*TelemetryServer) Start ¶ added in v3.5.0
func (ts *TelemetryServer) Start(ctx context.Context, t *testing.T)
Start begins the telemetry server, accepting incoming connections and processing telemetry data. It does not block.
func (*TelemetryServer) Stop ¶ added in v3.5.0
func (ts *TelemetryServer) Stop(t *testing.T)
Stop shuts down the telemetry server, closing the listener and canceling the context.