forked from openshift/library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.go
100 lines (90 loc) · 2.93 KB
/
controllers.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package encryption
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"github.com/openshift/library-go/pkg/operator/encryption/controllers/migrators"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
configv1informers "github.com/openshift/client-go/config/informers/externalversions/config/v1"
"github.com/openshift/library-go/pkg/operator/events"
operatorv1helpers "github.com/openshift/library-go/pkg/operator/v1helpers"
"github.com/openshift/library-go/pkg/operator/encryption/controllers"
"github.com/openshift/library-go/pkg/operator/encryption/secrets"
"github.com/openshift/library-go/pkg/operator/encryption/statemachine"
)
type runner interface {
Run(stopCh <-chan struct{})
}
func NewControllers(
component string,
deployer statemachine.Deployer,
migrator migrators.Migrator,
operatorClient operatorv1helpers.OperatorClient,
apiServerClient configv1client.APIServerInterface,
apiServerInformer configv1informers.APIServerInformer,
kubeInformersForNamespaces operatorv1helpers.KubeInformersForNamespaces,
secretsClient corev1.SecretsGetter,
eventRecorder events.Recorder,
encryptedGRs ...schema.GroupResource,
) (*Controllers, error) {
// avoid using the CachedSecretGetter as we need strong guarantees that our encryptionSecretSelector works
// otherwise we could see secrets from a different component (which will break our keyID invariants)
// this is fine in terms of performance since these controllers will be idle most of the time
// TODO: update the eventHandlers used by the controllers to ignore components that do not match their own
encryptionSecretSelector := metav1.ListOptions{LabelSelector: secrets.EncryptionKeySecretsLabel + "=" + component}
return &Controllers{
controllers: []runner{
controllers.NewKeyController(
component,
deployer,
operatorClient,
apiServerClient,
apiServerInformer,
kubeInformersForNamespaces,
secretsClient,
encryptionSecretSelector,
eventRecorder,
encryptedGRs,
),
controllers.NewStateController(
component,
deployer,
operatorClient,
kubeInformersForNamespaces,
secretsClient,
encryptionSecretSelector,
eventRecorder,
encryptedGRs,
),
controllers.NewPruneController(
deployer,
operatorClient,
kubeInformersForNamespaces,
secretsClient,
encryptionSecretSelector,
eventRecorder,
encryptedGRs,
),
controllers.NewMigrationController(
deployer,
migrator,
operatorClient,
kubeInformersForNamespaces,
secretsClient,
encryptionSecretSelector,
eventRecorder,
encryptedGRs,
),
},
}, nil
}
type Controllers struct {
controllers []runner
}
func (c *Controllers) Run(stopCh <-chan struct{}) {
for _, controller := range c.controllers {
con := controller // capture range variable
go con.Run(stopCh)
}
<-stopCh
}