1
1
import { ApiObject } from 'cdk8s' ;
2
2
import { Construct } from 'constructs' ;
3
3
export * as k8s from './imports/k8s' ;
4
+ import * as k8s from './imports/k8s' ;
4
5
5
6
export class ControllerStrategy {
6
7
readonly type ?: string ;
@@ -14,12 +15,13 @@ export class SealedSecretsControllerOptions {
14
15
readonly strategy ?: ControllerStrategy ;
15
16
readonly args ?: string [ ] ;
16
17
readonly command ?: string [ ] ;
17
- readonly env ?: string [ ] ;
18
+ readonly env ?: k8s . EnvVar [ ] ;
18
19
readonly image ?: string ;
19
20
readonly runAsNonRoot ?: boolean ;
20
21
readonly minReadySeconds ?: number ;
21
22
readonly replicas ?: number ;
22
- readonly selector ?: string ;
23
+ readonly labels ?: { [ key : string ] : string } ;
24
+ readonly resources ?: k8s . ResourceRequirements ;
23
25
}
24
26
25
27
export class SealedSecretsTemplate extends Construct {
@@ -28,11 +30,13 @@ export class SealedSecretsTemplate extends Construct {
28
30
private namespace : string ;
29
31
private args : string [ ] ;
30
32
private command : string [ ] ;
31
- private env : string [ ] ;
33
+ private env : k8s . EnvVar [ ] ;
32
34
private image : string ;
33
35
private runAsNonRoot : boolean ;
34
36
private minReadySeconds : number ;
35
37
private replicas : number ;
38
+ private labels ?: { [ key : string ] : string } ;
39
+ private resources ?: k8s . ResourceRequirements ;
36
40
37
41
constructor ( scope : Construct , id : string , options : SealedSecretsControllerOptions ) {
38
42
super ( scope , id ) ;
@@ -42,78 +46,71 @@ export class SealedSecretsTemplate extends Construct {
42
46
this . args = [ ] ;
43
47
this . command = options . command ?? [ 'controller' ] ;
44
48
this . env = [ ] ;
45
- this . image = options . image ?? 'quay.io/ bitnami/sealed-secrets-controller:v0.9.8' ;
49
+ this . image = options . image ?? 'bitnami/sealed-secrets-controller:v0.9.8' ;
46
50
this . runAsNonRoot = options . runAsNonRoot ?? true ;
47
51
this . minReadySeconds = options . minReadySeconds ?? 30 ;
48
52
this . replicas = options . replicas ?? 1 ;
53
+ this . labels = options . labels ?? {
54
+ name : this . name ,
55
+ } ;
56
+ this . resources = options . resources ?? {
57
+ limits : {
58
+ cpu : 2 ,
59
+ memory : '2Gi' ,
60
+ } ,
61
+ requests : {
62
+ cpu : '1' ,
63
+ memory : '1Gi' ,
64
+ } ,
65
+ } ;
49
66
50
67
// ServiceAccount
51
68
new ApiObject ( this , 'sealed-secrets-service-account' , {
52
69
apiVersion : 'v1' ,
53
70
kind : 'ServiceAccount' ,
54
71
metadata : {
55
- annotations : { } ,
56
- labels : {
57
- name : this . name ,
58
- } ,
72
+ labels : this . labels ,
59
73
name : this . name ,
60
74
namespace : this . namespace ,
61
75
} ,
62
76
} ) ;
63
77
64
78
// Deployment
65
- new ApiObject ( this , 'sealed-secrets-controller' , {
66
- apiVersion : 'apps/v1' ,
67
- kind : 'Deployment' ,
79
+ new k8s . KubeDeployment ( this , 'sealed-secrets-controller' , {
68
80
metadata : {
69
- annotations : { } ,
70
- labels : {
71
- name : this . name ,
72
- } ,
81
+ labels : this . labels ,
73
82
name : this . name ,
74
83
namespace : this . namespace ,
75
84
} ,
76
85
spec : {
77
86
minReadySeconds : this . minReadySeconds ?? 30 ,
78
87
replicas : this . replicas ?? 1 ,
79
88
revisionHistoryLimit : 10 ,
80
- ... options . selector ? {
81
- selector : {
82
- matchLabels : {
83
- name : options . selector ,
84
- } ,
85
- } ,
86
- } :{
87
- selector : {
88
- matchLabels : {
89
- name : options . name ,
90
- } ,
91
- } ,
89
+ selector : {
90
+ matchLabels : this . labels ,
92
91
} ,
93
92
strategy : {
94
93
... this . getStrategy ( ) ,
95
94
} ,
96
95
template : {
97
96
metadata : {
98
- annotations : { } ,
99
- labels : {
100
- name : this . name ,
101
- } ,
97
+ labels : this . labels ,
102
98
} ,
103
99
spec : {
104
100
containers : [
105
101
{
106
- args : this . args ?? [ ] ,
107
- command : this . command ?? [ 'controller' ] ,
108
- env : this . env ?? [ ] ,
109
- image : this . image ?? 'quay.io/bitnami/sealed-secrets-controller:v0.9.8' ,
102
+ args : this . args ,
103
+ command : this . command ,
104
+ env : this . env ,
105
+ image : this . image ,
110
106
imagePullPolicy : 'Always' ,
111
107
livenessProbe : {
112
108
httpGet : {
113
109
path : '/healthz' ,
114
110
port : 'http' ,
115
111
} ,
116
112
} ,
113
+ resources : this . resources ,
117
114
name : this . name ,
118
115
ports : [
119
116
{
@@ -142,8 +139,6 @@ export class SealedSecretsTemplate extends Construct {
142
139
] ,
143
140
} ,
144
141
] ,
145
- initContainers : [ ] ,
146
- imagePullSecrets : [ ] ,
147
142
securityContext : {
148
143
fsGroup : 65534 ,
149
144
} ,
@@ -165,10 +160,7 @@ export class SealedSecretsTemplate extends Construct {
165
160
apiVersion : 'v1' ,
166
161
kind : 'Service' ,
167
162
metadata : {
168
- annotations : { } ,
169
- labels : {
170
- name : this . name ,
171
- } ,
163
+ labels : this . labels ,
172
164
name : this . name ,
173
165
namespace : this . namespace ,
174
166
} ,
@@ -179,9 +171,7 @@ export class SealedSecretsTemplate extends Construct {
179
171
targetPort : 8080 ,
180
172
} ,
181
173
] ,
182
- selector : {
183
- name : this . name ,
184
- } ,
174
+ selector : this . labels ,
185
175
type : 'ClusterIP' ,
186
176
} ,
187
177
} ) ;
@@ -191,7 +181,6 @@ export class SealedSecretsTemplate extends Construct {
191
181
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
192
182
kind : 'Role' ,
193
183
metadata : {
194
- annotations : { } ,
195
184
labels : {
196
185
name : 'sealed-secrets-service-proxier' ,
197
186
} ,
@@ -223,7 +212,6 @@ export class SealedSecretsTemplate extends Construct {
223
212
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
224
213
kind : 'ClusterRole' ,
225
214
metadata : {
226
- annotations : { } ,
227
215
labels : {
228
216
name : 'sealed-secrets-key-admin' ,
229
217
} ,
@@ -251,7 +239,6 @@ export class SealedSecretsTemplate extends Construct {
251
239
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
252
240
kind : 'ClusterRole' ,
253
241
metadata : {
254
- annotations : { } ,
255
242
labels : {
256
243
name : 'secrets-unsealer' ,
257
244
} ,
@@ -326,7 +313,6 @@ export class SealedSecretsTemplate extends Construct {
326
313
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
327
314
kind : 'RoleBinding' ,
328
315
metadata : {
329
- annotations : { } ,
330
316
labels : {
331
317
name : 'sealed-secrets-service-proxier' ,
332
318
} ,
@@ -353,10 +339,7 @@ export class SealedSecretsTemplate extends Construct {
353
339
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
354
340
kind : 'RoleBinding' ,
355
341
metadata : {
356
- annotations : { } ,
357
- labels : {
358
- name : this . name ,
359
- } ,
342
+ labels : this . labels ,
360
343
name : this . name ,
361
344
namespace : this . namespace ,
362
345
} ,
@@ -379,7 +362,6 @@ export class SealedSecretsTemplate extends Construct {
379
362
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
380
363
kind : 'ClusterRoleBinding' ,
381
364
metadata : {
382
- annotations : { } ,
383
365
labels : {
384
366
name : this . name + '-key-admin' ,
385
367
} ,
@@ -405,7 +387,6 @@ export class SealedSecretsTemplate extends Construct {
405
387
apiVersion : 'rbac.authorization.k8s.io/v1beta1' ,
406
388
kind : 'ClusterRoleBinding' ,
407
389
metadata : {
408
- annotations : { } ,
409
390
labels : {
410
391
name : this . name + '-unsealer' ,
411
392
} ,
@@ -436,4 +417,4 @@ export class SealedSecretsTemplate extends Construct {
436
417
type : 'RollingUpdate' ,
437
418
} ;
438
419
}
439
- }
420
+ }
0 commit comments