@@ -50,28 +50,35 @@ var configurationResourceNameError = "ConfigurationResource name must be prefixe
50
50
// stackset resources and starts and maintains other controllers per
51
51
// stackset resource.
52
52
type StackSetController struct {
53
- logger * log.Entry
54
- client clientset.Interface
55
- namespace string
56
- syncIngressAnnotations []string
57
- controllerID string
58
- backendWeightsAnnotationKey string
59
- clusterDomains []string
60
- interval time.Duration
61
- stacksetEvents chan stacksetEvent
62
- stacksetStore map [types.UID ]zv1.StackSet
63
- recorder kube_record.EventRecorder
64
- metricsReporter * core.MetricsReporter
65
- HealthReporter healthcheck.Handler
66
- routeGroupSupportEnabled bool
67
- now func () string
68
- reconcileWorkers int
69
- configMapSupportEnabled bool
70
- secretSupportEnabled bool
71
- pcsSupportEnabled bool
53
+ logger * log.Entry
54
+ client clientset.Interface
55
+ config StackSetConfig
56
+ stacksetEvents chan stacksetEvent
57
+ stacksetStore map [types.UID ]zv1.StackSet
58
+ recorder kube_record.EventRecorder
59
+ metricsReporter * core.MetricsReporter
60
+ HealthReporter healthcheck.Handler
61
+ now func () string
72
62
sync.Mutex
73
63
}
74
64
65
+ type StackSetConfig struct {
66
+ Namespace string
67
+ ControllerID string
68
+
69
+ ClusterDomains []string
70
+ BackendWeightsAnnotationKey string
71
+ SyncIngressAnnotations []string
72
+
73
+ ReconcileWorkers int
74
+ Interval time.Duration
75
+
76
+ RouteGroupSupportEnabled bool
77
+ ConfigMapSupportEnabled bool
78
+ SecretSupportEnabled bool
79
+ PcsSupportEnabled bool
80
+ }
81
+
75
82
type stacksetEvent struct {
76
83
Deleted bool
77
84
StackSet * zv1.StackSet
@@ -93,44 +100,24 @@ func now() string {
93
100
// NewStackSetController initializes a new StackSetController.
94
101
func NewStackSetController (
95
102
client clientset.Interface ,
96
- namespace string ,
97
- controllerID string ,
98
- parallelWork int ,
99
- backendWeightsAnnotationKey string ,
100
- clusterDomains []string ,
101
103
registry prometheus.Registerer ,
102
- interval time.Duration ,
103
- routeGroupSupportEnabled bool ,
104
- syncIngressAnnotations []string ,
105
- configMapSupportEnabled bool ,
106
- secretSupportEnabled bool ,
107
- pcsSupportEnabled bool ,
104
+ config StackSetConfig ,
108
105
) (* StackSetController , error ) {
109
106
metricsReporter , err := core .NewMetricsReporter (registry )
110
107
if err != nil {
111
108
return nil , err
112
109
}
113
110
114
111
return & StackSetController {
115
- logger : log .WithFields (log.Fields {"controller" : "stackset" }),
116
- client : client ,
117
- namespace : namespace ,
118
- controllerID : controllerID ,
119
- backendWeightsAnnotationKey : backendWeightsAnnotationKey ,
120
- clusterDomains : clusterDomains ,
121
- interval : interval ,
122
- stacksetEvents : make (chan stacksetEvent , 1 ),
123
- stacksetStore : make (map [types.UID ]zv1.StackSet ),
124
- recorder : recorder .CreateEventRecorder (client ),
125
- metricsReporter : metricsReporter ,
126
- HealthReporter : healthcheck .NewHandler (),
127
- routeGroupSupportEnabled : routeGroupSupportEnabled ,
128
- syncIngressAnnotations : syncIngressAnnotations ,
129
- configMapSupportEnabled : configMapSupportEnabled ,
130
- secretSupportEnabled : secretSupportEnabled ,
131
- pcsSupportEnabled : pcsSupportEnabled ,
132
- now : now ,
133
- reconcileWorkers : parallelWork ,
112
+ logger : log .WithFields (log.Fields {"controller" : "stackset" }),
113
+ client : client ,
114
+ config : config ,
115
+ stacksetEvents : make (chan stacksetEvent , 1 ),
116
+ stacksetStore : make (map [types.UID ]zv1.StackSet ),
117
+ recorder : recorder .CreateEventRecorder (client ),
118
+ metricsReporter : metricsReporter ,
119
+ HealthReporter : healthcheck .NewHandler (),
120
+ now : now ,
134
121
}, nil
135
122
}
136
123
@@ -157,7 +144,7 @@ func (c *StackSetController) Run(ctx context.Context) error {
157
144
158
145
// We're not alive if nextCheck is too far in the past
159
146
c .HealthReporter .AddLivenessCheck ("nextCheck" , func () error {
160
- if time .Since (nextCheck ) > 5 * c .interval {
147
+ if time .Since (nextCheck ) > 5 * c .config . Interval {
161
148
return fmt .Errorf ("nextCheck too old" )
162
149
}
163
150
return nil
@@ -170,13 +157,13 @@ func (c *StackSetController) Run(ctx context.Context) error {
170
157
171
158
http .HandleFunc ("/healthz" , c .HealthReporter .LiveEndpoint )
172
159
173
- nextCheck = time .Now ().Add (- c .interval )
160
+ nextCheck = time .Now ().Add (- c .config . Interval )
174
161
175
162
for {
176
163
select {
177
164
case <- time .After (time .Until (nextCheck )):
178
165
179
- nextCheck = time .Now ().Add (c .interval )
166
+ nextCheck = time .Now ().Add (c .config . Interval )
180
167
181
168
stackSetContainers , err := c .collectResources (ctx )
182
169
if err != nil {
@@ -185,7 +172,7 @@ func (c *StackSetController) Run(ctx context.Context) error {
185
172
}
186
173
187
174
var reconcileGroup errgroup.Group
188
- reconcileGroup .SetLimit (c .reconcileWorkers )
175
+ reconcileGroup .SetLimit (c .config . ReconcileWorkers )
189
176
for stackset , container := range stackSetContainers {
190
177
container := container
191
178
stackset := stackset
@@ -263,9 +250,9 @@ func (c *StackSetController) collectResources(ctx context.Context) (map[types.UI
263
250
stacksetContainer := core .NewContainer (
264
251
& stackset ,
265
252
reconciler ,
266
- c .backendWeightsAnnotationKey ,
267
- c .clusterDomains ,
268
- c .syncIngressAnnotations ,
253
+ c .config . BackendWeightsAnnotationKey ,
254
+ c .config . ClusterDomains ,
255
+ c .config . SyncIngressAnnotations ,
269
256
)
270
257
stacksets [uid ] = stacksetContainer
271
258
}
@@ -280,7 +267,7 @@ func (c *StackSetController) collectResources(ctx context.Context) (map[types.UI
280
267
return nil , err
281
268
}
282
269
283
- if c .routeGroupSupportEnabled {
270
+ if c .config . RouteGroupSupportEnabled {
284
271
err = c .collectRouteGroups (ctx , stacksets )
285
272
if err != nil {
286
273
return nil , err
@@ -302,21 +289,21 @@ func (c *StackSetController) collectResources(ctx context.Context) (map[types.UI
302
289
return nil , err
303
290
}
304
291
305
- if c .configMapSupportEnabled {
292
+ if c .config . ConfigMapSupportEnabled {
306
293
err = c .collectConfigMaps (ctx , stacksets )
307
294
if err != nil {
308
295
return nil , err
309
296
}
310
297
}
311
298
312
- if c .secretSupportEnabled {
299
+ if c .config . SecretSupportEnabled {
313
300
err = c .collectSecrets (ctx , stacksets )
314
301
if err != nil {
315
302
return nil , err
316
303
}
317
304
}
318
305
319
- if c .pcsSupportEnabled {
306
+ if c .config . PcsSupportEnabled {
320
307
err = c .collectPlatformCredentialsSet (ctx , stacksets )
321
308
if err != nil {
322
309
return nil , err
@@ -327,7 +314,7 @@ func (c *StackSetController) collectResources(ctx context.Context) (map[types.UI
327
314
}
328
315
329
316
func (c * StackSetController ) collectIngresses (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
330
- ingresses , err := c .client .NetworkingV1 ().Ingresses (c .namespace ).List (ctx , metav1.ListOptions {})
317
+ ingresses , err := c .client .NetworkingV1 ().Ingresses (c .config . Namespace ).List (ctx , metav1.ListOptions {})
331
318
332
319
if err != nil {
333
320
return fmt .Errorf ("failed to list Ingresses: %v" , err )
@@ -363,7 +350,7 @@ func (c *StackSetController) collectIngresses(ctx context.Context, stacksets map
363
350
}
364
351
365
352
func (c * StackSetController ) collectRouteGroups (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
366
- rgs , err := c .client .RouteGroupV1 ().RouteGroups (c .namespace ).List (
353
+ rgs , err := c .client .RouteGroupV1 ().RouteGroups (c .config . Namespace ).List (
367
354
ctx ,
368
355
metav1.ListOptions {},
369
356
)
@@ -401,7 +388,7 @@ func (c *StackSetController) collectRouteGroups(ctx context.Context, stacksets m
401
388
}
402
389
403
390
func (c * StackSetController ) collectStacks (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
404
- stacks , err := c .client .ZalandoV1 ().Stacks (c .namespace ).List (ctx , metav1.ListOptions {})
391
+ stacks , err := c .client .ZalandoV1 ().Stacks (c .config . Namespace ).List (ctx , metav1.ListOptions {})
405
392
if err != nil {
406
393
return fmt .Errorf ("failed to list Stacks: %v" , err )
407
394
}
@@ -423,7 +410,7 @@ func (c *StackSetController) collectStacks(ctx context.Context, stacksets map[ty
423
410
}
424
411
425
412
func (c * StackSetController ) collectDeployments (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
426
- deployments , err := c .client .AppsV1 ().Deployments (c .namespace ).List (ctx , metav1.ListOptions {})
413
+ deployments , err := c .client .AppsV1 ().Deployments (c .config . Namespace ).List (ctx , metav1.ListOptions {})
427
414
if err != nil {
428
415
return fmt .Errorf ("failed to list Deployments: %v" , err )
429
416
}
@@ -443,7 +430,7 @@ func (c *StackSetController) collectDeployments(ctx context.Context, stacksets m
443
430
}
444
431
445
432
func (c * StackSetController ) collectServices (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
446
- services , err := c .client .CoreV1 ().Services (c .namespace ).List (ctx , metav1.ListOptions {})
433
+ services , err := c .client .CoreV1 ().Services (c .config . Namespace ).List (ctx , metav1.ListOptions {})
447
434
if err != nil {
448
435
return fmt .Errorf ("failed to list Services: %v" , err )
449
436
}
@@ -472,7 +459,7 @@ Items:
472
459
}
473
460
474
461
func (c * StackSetController ) collectHPAs (ctx context.Context , stacksets map [types.UID ]* core.StackSetContainer ) error {
475
- hpas , err := c .client .AutoscalingV2 ().HorizontalPodAutoscalers (c .namespace ).List (ctx , metav1.ListOptions {})
462
+ hpas , err := c .client .AutoscalingV2 ().HorizontalPodAutoscalers (c .config . Namespace ).List (ctx , metav1.ListOptions {})
476
463
if err != nil {
477
464
return fmt .Errorf ("failed to list HPAs: %v" , err )
478
465
}
@@ -504,7 +491,7 @@ func (c *StackSetController) collectConfigMaps(
504
491
ctx context.Context ,
505
492
stacksets map [types.UID ]* core.StackSetContainer ,
506
493
) error {
507
- configMaps , err := c .client .CoreV1 ().ConfigMaps (c .namespace ).List (ctx , metav1.ListOptions {})
494
+ configMaps , err := c .client .CoreV1 ().ConfigMaps (c .config . Namespace ).List (ctx , metav1.ListOptions {})
508
495
if err != nil {
509
496
return fmt .Errorf ("failed to list ConfigMaps: %v" , err )
510
497
}
@@ -527,7 +514,7 @@ func (c *StackSetController) collectSecrets(
527
514
ctx context.Context ,
528
515
stacksets map [types.UID ]* core.StackSetContainer ,
529
516
) error {
530
- secrets , err := c .client .CoreV1 ().Secrets (c .namespace ).List (ctx , metav1.ListOptions {})
517
+ secrets , err := c .client .CoreV1 ().Secrets (c .config . Namespace ).List (ctx , metav1.ListOptions {})
531
518
if err != nil {
532
519
return fmt .Errorf ("failed to list Secrets: %v" , err )
533
520
}
@@ -550,7 +537,7 @@ func (c *StackSetController) collectPlatformCredentialsSet(
550
537
ctx context.Context ,
551
538
stacksets map [types.UID ]* core.StackSetContainer ,
552
539
) error {
553
- platformCredentialsSets , err := c .client .ZalandoV1 ().PlatformCredentialsSets (c .namespace ).
540
+ platformCredentialsSets , err := c .client .ZalandoV1 ().PlatformCredentialsSets (c .config . Namespace ).
554
541
List (ctx , metav1.ListOptions {})
555
542
if err != nil {
556
543
return fmt .Errorf ("failed to list PlatformCredentialsSet: %v" , err )
@@ -603,15 +590,15 @@ func (c *StackSetController) errorEventf(object runtime.Object, reason string, e
603
590
func (c * StackSetController ) hasOwnership (stackset * zv1.StackSet ) bool {
604
591
if stackset .Annotations != nil {
605
592
if owner , ok := stackset .Annotations [StacksetControllerControllerAnnotationKey ]; ok {
606
- return owner == c .controllerID
593
+ return owner == c .config . ControllerID
607
594
}
608
595
}
609
- return c .controllerID == ""
596
+ return c .config . ControllerID == ""
610
597
}
611
598
612
599
func (c * StackSetController ) startWatch (ctx context.Context ) error {
613
600
informer := cache .NewSharedIndexInformer (
614
- cache .NewListWatchFromClient (c .client .ZalandoV1 ().RESTClient (), "stacksets" , c .namespace , fields .Everything ()),
601
+ cache .NewListWatchFromClient (c .client .ZalandoV1 ().RESTClient (), "stacksets" , c .config . Namespace , fields .Everything ()),
615
602
& zv1.StackSet {},
616
603
0 , // skip resync
617
604
cache.Indexers {},
@@ -770,7 +757,7 @@ func (c *StackSetController) CreateCurrentStack(ctx context.Context, ssc *core.S
770
757
return nil
771
758
}
772
759
773
- if c .configMapSupportEnabled || c .secretSupportEnabled {
760
+ if c .config . ConfigMapSupportEnabled || c .config . SecretSupportEnabled {
774
761
// ensure that ConfigurationResources are prefixed by Stack name.
775
762
if err := validateAllConfigurationResourcesNames (newStack .Stack ); err != nil {
776
763
return err
@@ -1022,7 +1009,7 @@ func (c *StackSetController) ReconcileStackResources(ctx context.Context, ssc *c
1022
1009
return c .errorEventf (sc .Stack , "FailedManageIngressSegment" , err )
1023
1010
}
1024
1011
1025
- if c .routeGroupSupportEnabled {
1012
+ if c .config . RouteGroupSupportEnabled {
1026
1013
err = c .ReconcileStackRouteGroup (ctx , sc .Stack , sc .Resources .RouteGroup , sc .GenerateRouteGroup )
1027
1014
if err != nil {
1028
1015
return c .errorEventf (sc .Stack , "FailedManageRouteGroup" , err )
@@ -1043,21 +1030,21 @@ func (c *StackSetController) ReconcileStackResources(ctx context.Context, ssc *c
1043
1030
}
1044
1031
}
1045
1032
1046
- if c .configMapSupportEnabled {
1033
+ if c .config . ConfigMapSupportEnabled {
1047
1034
err := c .ReconcileStackConfigMapRefs (ctx , sc .Stack , sc .UpdateObjectMeta )
1048
1035
if err != nil {
1049
1036
return c .errorEventf (sc .Stack , "FailedManageConfigMapRefs" , err )
1050
1037
}
1051
1038
}
1052
1039
1053
- if c .secretSupportEnabled {
1040
+ if c .config . SecretSupportEnabled {
1054
1041
err := c .ReconcileStackSecretRefs (ctx , sc .Stack , sc .UpdateObjectMeta )
1055
1042
if err != nil {
1056
1043
return c .errorEventf (sc .Stack , "FailedManageSecretRefs" , err )
1057
1044
}
1058
1045
}
1059
1046
1060
- if c .pcsSupportEnabled {
1047
+ if c .config . PcsSupportEnabled {
1061
1048
err = c .ReconcileStackPlatformCredentialsSets (
1062
1049
ctx ,
1063
1050
sc .Stack ,
0 commit comments