blob: f7e7e5677c8d6531b1b982c889c6b87009379605 [file] [log] [blame]
Jan Schära48bd3c2024-07-29 17:22:18 +02001package object
2
3// Taken and modified from the Kubernetes plugin of CoreDNS, under Apache 2.0.
4
5import (
6 "fmt"
7
8 api "k8s.io/api/core/v1"
9 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
10 "k8s.io/apimachinery/pkg/runtime"
11)
12
13// Namespace is a stripped down api.Namespace with only the items we need.
14type Namespace struct {
15 Version string
16 Name string
17
18 *Empty
19}
20
21// ToNamespace returns a function that converts an api.Namespace to a *Namespace.
22func ToNamespace(obj meta.Object) (meta.Object, error) {
23 ns, ok := obj.(*api.Namespace)
24 if !ok {
25 return nil, fmt.Errorf("unexpected object %v", obj)
26 }
27 n := &Namespace{
28 Version: ns.GetResourceVersion(),
29 Name: ns.GetName(),
30 }
31 *ns = api.Namespace{}
32 return n, nil
33}
34
35var _ runtime.Object = &Namespace{}
36
37// DeepCopyObject implements the ObjectKind interface.
38func (n *Namespace) DeepCopyObject() runtime.Object {
39 n1 := &Namespace{
40 Version: n.Version,
41 Name: n.Name,
42 }
43 return n1
44}
45
46// GetNamespace implements the metav1.Object interface.
47func (n *Namespace) GetNamespace() string { return "" }
48
49// SetNamespace implements the metav1.Object interface.
50func (n *Namespace) SetNamespace(namespace string) {}
51
52// GetName implements the metav1.Object interface.
53func (n *Namespace) GetName() string { return n.Name }
54
55// SetName implements the metav1.Object interface.
56func (n *Namespace) SetName(name string) {}
57
58// GetResourceVersion implements the metav1.Object interface.
59func (n *Namespace) GetResourceVersion() string { return n.Version }
60
61// SetResourceVersion implements the metav1.Object interface.
62func (n *Namespace) SetResourceVersion(version string) {}