blob: b9f77d5aefd12b7e7e3112b76b60c1ae5ed9ff49 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Jan Schära48bd3c2024-07-29 17:22:18 +02004// Package object holds functions that convert the objects from the k8s API in
5// to a more memory efficient structures.
6//
7// Adding new fields to any of the structures defined in pod.go, endpoint.go
8// and service.go should not be done lightly as this increases the memory use
9// and will leads to OOMs in the k8s scale test.
10package object
11
12// Taken and modified from the Kubernetes plugin of CoreDNS, under Apache 2.0.
13
14import (
15 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16 "k8s.io/apimachinery/pkg/runtime/schema"
17 "k8s.io/apimachinery/pkg/types"
18 "k8s.io/client-go/tools/cache"
19)
20
21// ToFunc converts one v1.Object to another v1.Object.
22type ToFunc func(v1.Object) (v1.Object, error)
23
24// ProcessorBuilder returns function to process cache events.
25type ProcessorBuilder func(cache.Indexer, cache.ResourceEventHandler) cache.ProcessFunc
26
27// Empty is an empty struct.
28type Empty struct{}
29
30// GetObjectKind implements the ObjectKind interface as a noop.
31func (e *Empty) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
32
33// GetGenerateName implements the metav1.Object interface.
34func (e *Empty) GetGenerateName() string { return "" }
35
36// SetGenerateName implements the metav1.Object interface.
37func (e *Empty) SetGenerateName(name string) {}
38
39// GetUID implements the metav1.Object interface.
40func (e *Empty) GetUID() types.UID { return "" }
41
42// SetUID implements the metav1.Object interface.
43func (e *Empty) SetUID(uid types.UID) {}
44
45// GetGeneration implements the metav1.Object interface.
46func (e *Empty) GetGeneration() int64 { return 0 }
47
48// SetGeneration implements the metav1.Object interface.
49func (e *Empty) SetGeneration(generation int64) {}
50
51// GetSelfLink implements the metav1.Object interface.
52func (e *Empty) GetSelfLink() string { return "" }
53
54// SetSelfLink implements the metav1.Object interface.
55func (e *Empty) SetSelfLink(selfLink string) {}
56
57// GetCreationTimestamp implements the metav1.Object interface.
58func (e *Empty) GetCreationTimestamp() v1.Time { return v1.Time{} }
59
60// SetCreationTimestamp implements the metav1.Object interface.
61func (e *Empty) SetCreationTimestamp(timestamp v1.Time) {}
62
63// GetDeletionTimestamp implements the metav1.Object interface.
64func (e *Empty) GetDeletionTimestamp() *v1.Time { return &v1.Time{} }
65
66// SetDeletionTimestamp implements the metav1.Object interface.
67func (e *Empty) SetDeletionTimestamp(timestamp *v1.Time) {}
68
69// GetDeletionGracePeriodSeconds implements the metav1.Object interface.
70func (e *Empty) GetDeletionGracePeriodSeconds() *int64 { return nil }
71
72// SetDeletionGracePeriodSeconds implements the metav1.Object interface.
73func (e *Empty) SetDeletionGracePeriodSeconds(*int64) {}
74
75// GetLabels implements the metav1.Object interface.
76func (e *Empty) GetLabels() map[string]string { return nil }
77
78// SetLabels implements the metav1.Object interface.
79func (e *Empty) SetLabels(labels map[string]string) {}
80
81// GetAnnotations implements the metav1.Object interface.
82func (e *Empty) GetAnnotations() map[string]string { return nil }
83
84// SetAnnotations implements the metav1.Object interface.
85func (e *Empty) SetAnnotations(annotations map[string]string) {}
86
87// GetFinalizers implements the metav1.Object interface.
88func (e *Empty) GetFinalizers() []string { return nil }
89
90// SetFinalizers implements the metav1.Object interface.
91func (e *Empty) SetFinalizers(finalizers []string) {}
92
93// GetOwnerReferences implements the metav1.Object interface.
94func (e *Empty) GetOwnerReferences() []v1.OwnerReference { return nil }
95
96// SetOwnerReferences implements the metav1.Object interface.
97func (e *Empty) SetOwnerReferences([]v1.OwnerReference) {}
98
99// GetZZZ_DeprecatedClusterName implements the metav1.Object interface.
100func (e *Empty) GetZZZ_DeprecatedClusterName() string { return "" }
101
102// SetZZZ_DeprecatedClusterName implements the metav1.Object interface.
103func (e *Empty) SetZZZ_DeprecatedClusterName(clusterName string) {}
104
105// GetManagedFields implements the metav1.Object interface.
106func (e *Empty) GetManagedFields() []v1.ManagedFieldsEntry { return nil }
107
108// SetManagedFields implements the metav1.Object interface.
109func (e *Empty) SetManagedFields(managedFields []v1.ManagedFieldsEntry) {}