kubernetesk8s.io/kubernetes/test/integration/framework Index | Files

package framework

import "k8s.io/kubernetes/test/integration/framework"

Index

Constants

const (
	UnprivilegedUserToken = "unprivileged-user"
)

Functions

func AssertRequestResponseAsCBOR

func AssertRequestResponseAsCBOR(t testing.TB) transport.WrapperFunc

AssertRequestResponseAsCBOR returns a transport.WrapperFunc that will report a test error if a non-empty request or response body contains data that does not appear to be CBOR-encoded.

func CreateNamespaceOrDie

func CreateNamespaceOrDie(c clientset.Interface, baseName string, t testing.TB) *v1.Namespace

CreateNamespaceOrDie creates a namespace.

func DefaultEtcdOptions

func DefaultEtcdOptions() *options.EtcdOptions

DefaultEtcdOptions are the default EtcdOptions for use with integration tests.

func DefaultOpenAPIConfig

func DefaultOpenAPIConfig() *openapicommon.Config

DefaultOpenAPIConfig returns an openapicommon.Config initialized to default values.

func DefaultOpenAPIV3Config

func DefaultOpenAPIV3Config() *openapicommon.OpenAPIV3Config

DefaultOpenAPIV3Config returns an openapicommon.Config initialized to default values.

func DefaultTestServerFlags

func DefaultTestServerFlags() []string

DefaultAPIServerFlags returns the default flags used to run kube-apiserver on tests

func DeleteNamespaceOrDie

func DeleteNamespaceOrDie(c clientset.Interface, ns *v1.Namespace, t testing.TB)

DeleteNamespaceOrDie deletes a namespace.

func EnableCBORServingAndStorageForTest

func EnableCBORServingAndStorageForTest(tb testing.TB)

EnableCBORForTest patches global state to enable the CBOR serializer and reverses those changes at the end of the test. As a risk mitigation, integration tests are initially written this way so that integration tests can be implemented fully and incrementally before exposing options (including feature gates) that can enable CBOR at runtime. After integration test coverage is complete, feature gates will be introduced to completely supersede this mechanism.

func EtcdMain

func EtcdMain(tests func() int)

EtcdMain starts an etcd instance before running tests.

func Filter

func Filter(nodeList *v1.NodeList, fn func(node v1.Node) bool)

Filter filters nodes in NodeList in place, removing nodes that do not satisfy the given condition

func GetEtcdURL

func GetEtcdURL() string

GetEtcdURL returns the URL of the etcd instance started by EtcdMain or StartEtcd.

func GoleakCheck

func GoleakCheck(tb testing.TB, opts ...goleak.Option)

GoleakCheck sets up leak checking for a test or benchmark. The check runs as cleanup operation and records an error when goroutines were leaked.

func IgnoreBackgroundGoroutines

func IgnoreBackgroundGoroutines() []goleak.Option

IgnoreBackgroundGoroutines returns options for goleak.Find which ignore goroutines created by "go test" and init functions, like the one from go.opencensus.io/stats/view/worker.go.

Goroutines that normally get created later when using the apiserver get created already when calling this function, therefore they also get ignored.

func IsConditionSetAsExpected

func IsConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool

IsConditionSetAsExpected returns a wantTrue value if the node has a match to the conditionType, otherwise returns an opposite value of the wantTrue with detailed logging.

func IsConditionSetAsExpectedSilent

func IsConditionSetAsExpectedSilent(node *v1.Node, conditionType v1.NodeConditionType, wantTrue bool) bool

IsConditionSetAsExpectedSilent returns a wantTrue value if the node has a match to the conditionType, otherwise returns an opposite value of the wantTrue.

func IsNodeReady

func IsNodeReady(node *v1.Node) bool

IsNodeReady returns true if: 1) it's Ready condition is set to true 2) doesn't have NetworkUnavailable condition set to true

func IsNodeSchedulable

func IsNodeSchedulable(node *v1.Node) bool

IsNodeSchedulable returns true if: 1) doesn't have "unschedulable" field set 2) it also returns true from IsNodeReady

func NewTBWriter

func NewTBWriter(tb testing.TB) io.Writer

NewTBWriter creates an io.Writer which turns each write into a tb.Log call.

Note that no attempts are made to determine the actual call site because our caller doesn't know about the TB instance and thus cannot mark itself as helper. Therefore the code here doesn't do it either and thus shows up as call site in the testing output. To avoid that, contextual logging and ktesting have to be used.

func RedirectKlog

func RedirectKlog(tb testing.TB, output io.Writer) func()

RedirectKlog modifies the global klog logger so that it writes via the given writer. This only works when different tests run sequentially.

The returned cleanup function restores the previous state. Beware that it is not thread-safe, all goroutines which call klog must have been stopped.

func RunCustomEtcd

func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url string, stopFn func(), err error)

RunCustomEtcd starts a custom etcd instance for test purposes.

func SetTestOnlyCBORClientFeatureGatesForTest

func SetTestOnlyCBORClientFeatureGatesForTest(tb testing.TB, allowed, preferred bool)

SetTestOnlyCBORClientFeatureGatesForTest overrides the CBOR client feature gates in the test-only client feature gate instance for the duration of a test. The CBOR client feature gates are temporarily registered in their own feature gate instance that does not include runtime wiring to command-line flags or environment variables in order to mitigate the risk of enabling a new encoding before all integration tests have been demonstrated to pass.

This will be removed as an alpha requirement. The client feature gates will be registered with the existing feature gate instance and tests will use k8s.io/client-go/features/testing.SetFeatureDuringTest (which unlike k8s.io/component-base/featuregate/testing.SetFeatureGateDuringTest does not accept a feature gate instance as a parameter).

func SharedEtcd

func SharedEtcd() *storagebackend.Config

SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix.

func StartEtcd

func StartEtcd(tb testing.TB, etcdOutput io.Writer, forceCreate bool)

StartEtcd starts an etcd instance inside a test. It will abort the test if startup fails and clean up after the test automatically. Stdout and stderr of the etcd binary go to the provided writer.

In contrast to EtcdMain, StartEtcd will not do automatic leak checking. Tests can decide if and where they want to do that.

Starting etcd multiple times per test run instead of once with EtcdMain provides better separation between different tests.

Types

type TearDownFunc

type TearDownFunc func()

func StartTestServer

func StartTestServer(ctx context.Context, t testing.TB, setup TestServerSetup) (client.Interface, *rest.Config, TearDownFunc)

StartTestServer runs a kube-apiserver, optionally calling out to the setup.ModifyServerRunOptions and setup.ModifyServerConfig functions TODO (pohly): convert to ktesting contexts

type TestServerSetup

type TestServerSetup struct {
	ModifyServerRunOptions func(*options.ServerRunOptions)
	ModifyServerConfig     func(*controlplane.Config)
}

TestServerSetup holds configuration information for a kube-apiserver test server.

Source Files

cbor.go controlplane_utils.go etcd.go flags.go goleak.go logger.go serializer.go test_server.go util.go

Version
v1.32.0-beta.0
Published
Nov 5, 2024
Platform
js/wasm
Imports
61 packages
Last checked
11 seconds ago

Tools for package owners.