@@ -5,6 +5,19 @@ package v1alpha1
5
5
6
6
import " strings "
7
7
8
+ // Annotations defines the schema for Kubernetes object metadata annotations.
9
+ #Annotations : {[string & strings .MaxRunes (253 )]: string }
10
+
11
+ // Labels defines the schema for Kubernetes object metadata labels.
12
+ #Labels : {[string & strings .MaxRunes (253 )]: string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$ " & strings .MaxRunes (63 )}
13
+
14
+ #StdLabelName : " app.kubernetes.io/name "
15
+ #StdLabelVersion : " app.kubernetes.io/version "
16
+ #StdLabelPartOf : " app.kubernetes.io/part-of "
17
+ #StdLabelManagedBy : " app.kubernetes.io/managed-by "
18
+ #StdLabelComponent : " app.kubernetes.io/component "
19
+ #StdLabelInstance : " app.kubernetes.io/instance "
20
+
8
21
// Metadata defines the schema for Kubernetes object metadata.
9
22
#Metadata : {
10
23
// Version should be in the strict semver format. Is required when creating resources.
@@ -13,24 +26,90 @@ import "strings"
13
26
// Name must be unique within a namespace. Is required when creating resources.
14
27
// Name is primarily intended for creation idempotence and configuration definition.
15
28
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names
16
- name ! : string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$ " & strings . MaxRunes ( 63 )
29
+ name ! : #InstanceName
17
30
18
31
// Namespace defines the space within which each name must be unique.
19
32
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces
20
- namespace ! : string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$ " & strings . MaxRunes ( 63 )
33
+ namespace ! : #InstanceNamespace
21
34
22
35
// Annotations is an unstructured key value map stored with a resource that may be
23
36
// set to store and retrieve arbitrary metadata.
24
37
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
25
- annotations ?: {[ string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_./]*)?[A-Za-z0-9])?$ " & strings . MaxRunes ( 63 )]: string }
38
+ annotations ?: #Annotations
26
39
27
40
// Map of string keys and values that can be used to organize and categorize (scope and select) objects.
28
41
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels
29
- labels : {[ string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_./]*)?[A-Za-z0-9])?$ " & strings . MaxRunes ( 63 )]: string & =~ " ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$ " & strings . MaxRunes ( 63 )}
42
+ labels : #Labels
30
43
31
- // Standard Kubernetes labels: app name and version .
44
+ // Standard Kubernetes labels: app name, version and managed-by .
32
45
labels : {
33
- " app.kubernetes.io/name " : name
34
- " app.kubernetes.io/version " : #Version
46
+ " \(#StdLabelName ) " : name
47
+ " \(#StdLabelVersion ) " : #Version
48
+ " \(#StdLabelManagedBy ) " : " Timoni "
49
+ }
50
+
51
+ // LabelSelector selects Pods based on the app.kubernetes.io/name label.
52
+ #LabelSelector : #Labels & {
53
+ " \(#StdLabelName ) " : name
54
+ }
55
+ }
56
+
57
+ // MetaComponent generates the Kubernetes object metadata for a module namespaced component.
58
+ // The metadata.name is composed of the instance name and the component name.
59
+ // The metadata.labels contain the app.kubernetes.io/component label.
60
+ #MetaComponent : {
61
+ // Meta is the Kubernetes object's metadata generated by Timoni.
62
+ #Meta ! : #Metadata
63
+
64
+ // Component is the name of the component used
65
+ // as a suffix for the generate object name.
66
+ #Component ! : string & strings .MaxRunes (30 )
67
+
68
+ name : #Meta .name + " - " + #Component
69
+ namespace : #Meta .namespace
70
+
71
+ labels : #Meta .labels
72
+ labels : " \(#StdLabelComponent ) " : #Component
73
+
74
+ annotations ?: #Annotations
75
+ if #Meta .annotations != _|_ {
76
+ annotations : #Meta .annotations
77
+ }
78
+
79
+ // LabelSelector selects Pods based on the app.kubernetes.io/name
80
+ // and app.kubernetes.io/component labels.
81
+ #LabelSelector : #Labels & {
82
+ " \(#StdLabelComponent ) " : #Component
83
+ " \(#StdLabelName ) " : #Meta .name
84
+ }
85
+ }
86
+
87
+ // MetaClusterComponent generates the Kubernetes object metadata for a module non-namespaced component.
88
+ // The metadata.name is composed of the instance name and the component name.
89
+ // The metadata.namespace is unset.
90
+ // The metadata.labels contain the app.kubernetes.io/component label.
91
+ #MetaClusterComponent : {
92
+ // Meta is the Kubernetes object's metadata generated by Timoni.
93
+ #Meta ! : #Metadata
94
+
95
+ // Component is the name of the component used
96
+ // as a suffix for the generate object name.
97
+ #Component ! : string & strings .MaxRunes (30 )
98
+
99
+ name : #Meta .name + " - " + #Component
100
+
101
+ labels : #Meta .labels
102
+ labels : " \(#StdLabelComponent ) " : #Component
103
+
104
+ annotations ?: #Annotations
105
+ if #Meta .annotations != _|_ {
106
+ annotations : #Meta .annotations
107
+ }
108
+
109
+ // LabelSelector selects Pods based on the app.kubernetes.io/name
110
+ // and app.kubernetes.io/component labels.
111
+ #LabelSelector : #Labels & {
112
+ " \(#StdLabelComponent ) " : #Component
113
+ " \(#StdLabelName ) " : #Meta .name
35
114
}
36
115
}
0 commit comments