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