-
Notifications
You must be signed in to change notification settings - Fork 0
/
reference.go
50 lines (43 loc) · 1.25 KB
/
reference.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
type nsGetter interface {
GetNamespace() string
}
// String implements the Stringer interface for a reference.
func (r Reference) String() string {
return r.NamespacedName().String()
}
// NamespacedName returns the namespaced name for this reference.
func (r Reference) NamespacedName() types.NamespacedName {
return types.NamespacedName{
Name: r.Name,
Namespace: r.Namespace,
}
}
// ObjectMeta returns an ObjectMeta of the referenced object.
// Does not populate anything else than Name and Namespace.
func (r Reference) ObjectMeta() metav1.ObjectMeta {
return metav1.ObjectMeta{
Name: r.Name,
Namespace: r.Namespace,
}
}
// NamespacedName returns the namespaced name of this local refenece with
// the namespace set to the given ns.
func (l LocalReference) NamespacedName(ns nsGetter) types.NamespacedName {
return types.NamespacedName{
Name: l.Name,
Namespace: ns.GetNamespace(),
}
}
// InNamespace returns a Reference based on the LocalReference with the
// namespace set to the given ns.
func (l LocalReference) InNamespace(ns nsGetter) Reference {
return Reference{
Name: l.Name,
Namespace: ns.GetNamespace(),
}
}