testutils

package
v1.18.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Scheme for object types used in Cilium. Excludes the core Kubernetes schema
	// in favour of the slim one.
	//
	// The scheme can be extended by init() functions since [Decoder] is
	// lazily constructed.
	Scheme = runtime.NewScheme()

	// KubernetesScheme is the core Kubernetes scheme.
	KubernetesScheme = runtime.NewScheme()
)
View Source
var (
	DefaultVersion = "1.26"

	// APIResources is the list of API resources for the k8s version that we're mocking.
	// This is mostly relevant for the feature detection at pkg/k8s/version/version.go.
	// The lists here are currently not exhaustive and expanded on need-by-need basis.
	APIResources = map[string][]*metav1.APIResourceList{
		"1.16": {
			CoreV1APIResources,
			CiliumV2APIResources,
		},
		"1.24": {
			CoreV1APIResources,
			DiscoveryV1APIResources,
			DiscoveryV1Beta1APIResources,
			CiliumV2APIResources,
		},
		"1.25": {
			CoreV1APIResources,
			DiscoveryV1APIResources,
			CiliumV2APIResources,
		},
		"1.26": {
			CoreV1APIResources,
			DiscoveryV1APIResources,
			CiliumV2APIResources,
		},
	}

	CoreV1APIResources = &metav1.APIResourceList{
		GroupVersion: corev1.SchemeGroupVersion.String(),
		APIResources: []metav1.APIResource{
			{Name: "nodes", Kind: "Node"},
			{Name: "pods", Namespaced: true, Kind: "Pod"},
			{Name: "services", Namespaced: true, Kind: "Service"},
			{Name: "endpoints", Namespaced: true, Kind: "Endpoint"},
		},
	}

	CiliumV2APIResources = &metav1.APIResourceList{
		TypeMeta:     metav1.TypeMeta{},
		GroupVersion: cilium_v2.SchemeGroupVersion.String(),
		APIResources: []metav1.APIResource{
			{Name: cilium_v2.CNPluralName, Kind: cilium_v2.CNKindDefinition},
			{Name: cilium_v2.CEPPluralName, Namespaced: true, Kind: cilium_v2.CEPKindDefinition},
			{Name: cilium_v2.CIDPluralName, Namespaced: true, Kind: cilium_v2.CIDKindDefinition},
			{Name: cilium_v2.CEGPPluralName, Namespaced: true, Kind: cilium_v2.CEGPKindDefinition},
			{Name: cilium_v2.CNPPluralName, Namespaced: true, Kind: cilium_v2.CNPKindDefinition},
			{Name: cilium_v2.CCNPPluralName, Namespaced: true, Kind: cilium_v2.CCNPKindDefinition},
			{Name: cilium_v2.CLRPPluralName, Namespaced: true, Kind: cilium_v2.CLRPKindDefinition},
			{Name: cilium_v2.CCECPluralName, Namespaced: true, Kind: cilium_v2.CCECKindDefinition},
			{Name: cilium_v2.CECPluralName, Namespaced: true, Kind: cilium_v2.CECKindDefinition},
		},
	}

	DiscoveryV1APIResources = &metav1.APIResourceList{
		TypeMeta:     metav1.TypeMeta{},
		GroupVersion: discov1.SchemeGroupVersion.String(),
		APIResources: []metav1.APIResource{
			{Name: "endpointslices", Namespaced: true, Kind: "EndpointSlice"},
		},
	}

	DiscoveryV1Beta1APIResources = &metav1.APIResourceList{
		GroupVersion: discov1beta1.SchemeGroupVersion.String(),
		APIResources: []metav1.APIResource{
			{Name: "endpointslices", Namespaced: true, Kind: "EndpointSlice"},
		},
	}
)

Functions

func DecodeFile

func DecodeFile(path string) (runtime.Object, error)

func DecodeKubernetesObject added in v1.17.4

func DecodeKubernetesObject(bytes []byte) (runtime.Object, *schema.GroupVersionKind, error)

func DecodeObject

func DecodeObject(bytes []byte) (runtime.Object, error)

func DecodeObjectGVK

func DecodeObjectGVK(bytes []byte) (runtime.Object, *schema.GroupVersionKind, error)

func Decoder

func Decoder() runtime.Decoder

Decoder returns an object decoder for Cilium and Slim objects. The DecodeObject and DecodeFile functions are provided as shorthands for decoding from bytes and files respectively.

func KubernetesDecoder added in v1.18.0

func KubernetesDecoder() runtime.Decoder

Types

type FakeListerWatcher

type FakeListerWatcher struct {
	// contains filtered or unexported fields
}

FakeListerWatcher implements a fake cache.ListerWatcher that can be fed objects directly, or from YAML files or strings. The YAML data is decoded with a schema that covers the Cilium CRDs and Slim schemas.

func NewFakeListerWatcher

func NewFakeListerWatcher(objs ...runtime.Object) *FakeListerWatcher

func (*FakeListerWatcher) Delete

func (f *FakeListerWatcher) Delete(obj runtime.Object)

func (*FakeListerWatcher) DeleteFromFile

func (f *FakeListerWatcher) DeleteFromFile(path string) error

func (*FakeListerWatcher) DeleteFromText

func (f *FakeListerWatcher) DeleteFromText(content string) error

func (*FakeListerWatcher) List

func (f *FakeListerWatcher) List(options v1.ListOptions) (runtime.Object, error)

List implements cache.ListerWatcher.

func (*FakeListerWatcher) Stop

func (f *FakeListerWatcher) Stop()

func (*FakeListerWatcher) Upsert

func (f *FakeListerWatcher) Upsert(obj runtime.Object)

func (*FakeListerWatcher) UpsertFromFile

func (f *FakeListerWatcher) UpsertFromFile(path string) error

func (*FakeListerWatcher) UpsertFromText

func (f *FakeListerWatcher) UpsertFromText(content string) error

func (*FakeListerWatcher) Watch

func (f *FakeListerWatcher) Watch(options v1.ListOptions) (watch.Interface, error)

Watch implements cache.ListerWatcher.

Jump to

Keyboard shortcuts

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