@@ -35,6 +35,18 @@ import (
35
35
// CodeGenerator generates code for Kubernetes resources and controllers
36
36
type CodeGenerator struct {}
37
37
38
+ var kblabels = map [string ]string {
39
+ "platform" : "kubernetes_sigs_kubebuilder" ,
40
+ }
41
+
42
+ func addLabels (m map [string ]string ) map [string ]string {
43
+ for k , v := range kblabels {
44
+ m [k ] = v
45
+ }
46
+ m ["api" ] = name
47
+ return m
48
+ }
49
+
38
50
// Execute parses packages and executes the code generators against the resource and controller packages
39
51
func (g CodeGenerator ) Execute () error {
40
52
arguments := args .Default ()
@@ -84,10 +96,8 @@ func getClusterRole(p *parse.APIs) string {
84
96
APIVersion : "rbac.authorization.k8s.io/v1" ,
85
97
},
86
98
ObjectMeta : metav1.ObjectMeta {
87
- Name : name + "-role" ,
88
- Labels : map [string ]string {
89
- "api" : name ,
90
- },
99
+ Name : name + "-role" ,
100
+ Labels : addLabels (map [string ]string {}),
91
101
},
92
102
Rules : rules ,
93
103
}
@@ -107,9 +117,7 @@ func getClusterRoleBinding(p *parse.APIs) string {
107
117
ObjectMeta : metav1.ObjectMeta {
108
118
Name : fmt .Sprintf ("%s-rolebinding" , name ),
109
119
Namespace : fmt .Sprintf ("%s-system" , name ),
110
- Labels : map [string ]string {
111
- "api" : name ,
112
- },
120
+ Labels : addLabels (map [string ]string {}),
113
121
},
114
122
Subjects : []rbacv1.Subject {
115
123
{
@@ -133,9 +141,7 @@ func getClusterRoleBinding(p *parse.APIs) string {
133
141
}
134
142
135
143
func getDeployment (p * parse.APIs ) string {
136
- labels := map [string ]string {
137
- "api" : name ,
138
- }
144
+ labels := addLabels (map [string ]string {})
139
145
dep := appsv1.Deployment {
140
146
TypeMeta : metav1.TypeMeta {
141
147
APIVersion : "apps/v1" ,
@@ -191,9 +197,7 @@ func getCrds(p *parse.APIs) []string {
191
197
for _ , v := range g .Versions {
192
198
for _ , r := range v .Resources {
193
199
crd := r .CRD
194
- crd .Labels = map [string ]string {
195
- "api" : name ,
196
- }
200
+ crd .Labels = addLabels (map [string ]string {})
197
201
s , err := yaml .Marshal (crd )
198
202
if err != nil {
199
203
glog .Fatalf ("Error: %v" , err )
@@ -208,10 +212,8 @@ func getCrds(p *parse.APIs) []string {
208
212
func getNamespace (p * parse.APIs ) string {
209
213
ns := corev1.Namespace {
210
214
ObjectMeta : metav1.ObjectMeta {
211
- Name : fmt .Sprintf ("%v-system" , name ),
212
- Labels : map [string ]string {
213
- "api" : name ,
214
- },
215
+ Name : fmt .Sprintf ("%v-system" , name ),
216
+ Labels : addLabels (map [string ]string {}),
215
217
},
216
218
TypeMeta : metav1.TypeMeta {
217
219
APIVersion : "v1" ,
0 commit comments