| Jan Schär | a48bd3c | 2024-07-29 17:22:18 +0200 | [diff] [blame^] | 1 | package object |
| 2 | |
| 3 | // Taken and modified from the Kubernetes plugin of CoreDNS, under Apache 2.0. |
| 4 | |
| 5 | import ( |
| 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. |
| 14 | type 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. |
| 22 | func 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 | |
| 35 | var _ runtime.Object = &Namespace{} |
| 36 | |
| 37 | // DeepCopyObject implements the ObjectKind interface. |
| 38 | func (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. |
| 47 | func (n *Namespace) GetNamespace() string { return "" } |
| 48 | |
| 49 | // SetNamespace implements the metav1.Object interface. |
| 50 | func (n *Namespace) SetNamespace(namespace string) {} |
| 51 | |
| 52 | // GetName implements the metav1.Object interface. |
| 53 | func (n *Namespace) GetName() string { return n.Name } |
| 54 | |
| 55 | // SetName implements the metav1.Object interface. |
| 56 | func (n *Namespace) SetName(name string) {} |
| 57 | |
| 58 | // GetResourceVersion implements the metav1.Object interface. |
| 59 | func (n *Namespace) GetResourceVersion() string { return n.Version } |
| 60 | |
| 61 | // SetResourceVersion implements the metav1.Object interface. |
| 62 | func (n *Namespace) SetResourceVersion(version string) {} |