blob: dc78fac0bbc82e3f2a71bc78f6debe39f7922f75 [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 +02004package object
5
6// Taken and modified from the Kubernetes plugin of CoreDNS, under Apache 2.0.
7
8import (
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.
17type 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.
25func 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
38var _ runtime.Object = &Namespace{}
39
40// DeepCopyObject implements the ObjectKind interface.
41func (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.
50func (n *Namespace) GetNamespace() string { return "" }
51
52// SetNamespace implements the metav1.Object interface.
53func (n *Namespace) SetNamespace(namespace string) {}
54
55// GetName implements the metav1.Object interface.
56func (n *Namespace) GetName() string { return n.Name }
57
58// SetName implements the metav1.Object interface.
59func (n *Namespace) SetName(name string) {}
60
61// GetResourceVersion implements the metav1.Object interface.
62func (n *Namespace) GetResourceVersion() string { return n.Version }
63
64// SetResourceVersion implements the metav1.Object interface.
65func (n *Namespace) SetResourceVersion(version string) {}