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