-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.go
63 lines (53 loc) · 1.64 KB
/
meta.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
51
52
53
54
55
56
57
58
59
60
61
62
63
package resource
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Kubernetes recommended labels
// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
const (
// appNameLabel is the name of the application.
AppNameLabel = "app.kubernetes.io/name"
// appInstanceLabel is a unique name identifying the instance of an application.
AppInstanceLabel = "app.kubernetes.io/instance"
// appComponentLabel is the component within the architecture.
AppComponentLabel = "app.kubernetes.io/component"
// appPartOfLabel is the name of a higher level application this one is part of.
AppPartOfLabel = "app.kubernetes.io/part-of"
// appManagedByLabel is the tool being used to manage the operation of an application.
AppManagedByLabel = "app.kubernetes.io/managed-by"
)
// Common label values
const (
PartOf = "typhoon"
ManagedBy = "core-controller"
)
type MetaOption func(*metav1.ObjectMeta)
func NewMeta(ns, name string, opts ...MetaOption) *metav1.ObjectMeta {
m := &metav1.ObjectMeta{
Namespace: ns,
Name: name,
}
for _, opt := range opts {
opt(m)
}
return m
}
func MetaAddOwner(o metav1.Object, gvk schema.GroupVersionKind) MetaOption {
return func(m *metav1.ObjectMeta) {
m.OwnerReferences = append(m.OwnerReferences, *metav1.NewControllerRef(o, gvk))
}
}
func MetaAddLabel(key, value string) MetaOption {
return func(m *metav1.ObjectMeta) {
if m.Labels == nil {
m.Labels = make(map[string]string, 1)
}
m.Labels[key] = value
}
}
func MetaSetDeletion(t *metav1.Time) MetaOption {
return func(m *metav1.ObjectMeta) {
m.DeletionTimestamp = t
}
}