Skip to content

Commit 9c07dcd

Browse files
committed
Listen for secret changes
1 parent 726ab72 commit 9c07dcd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/deployment/deployment.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
120120
go d.run()
121121
go d.listenForPodEvents(d.stopCh)
122122
go d.listenForPVCEvents(d.stopCh)
123+
go d.listenForSecretEvents(d.stopCh)
123124
go d.listenForServiceEvents(d.stopCh)
124125
if apiObject.Spec.GetMode() == api.DeploymentModeCluster {
125126
ci := newClusterScalingIntegration(d)

pkg/deployment/informers.go

+43
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,49 @@ func (d *Deployment) listenForPVCEvents(stopCh <-chan struct{}) {
112112
informer.Run(stopCh)
113113
}
114114

115+
// listenForSecretEvents keep listening for changes in Secrets's until the given channel is closed.
116+
func (d *Deployment) listenForSecretEvents(stopCh <-chan struct{}) {
117+
source := cache.NewListWatchFromClient(
118+
d.deps.KubeCli.CoreV1().RESTClient(),
119+
"secrets",
120+
d.apiObject.GetNamespace(),
121+
fields.Everything())
122+
123+
getSecret := func(obj interface{}) (*v1.Secret, bool) {
124+
secret, ok := obj.(*v1.Secret)
125+
if !ok {
126+
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
127+
if !ok {
128+
return nil, false
129+
}
130+
secret, ok = tombstone.Obj.(*v1.Secret)
131+
return secret, ok
132+
}
133+
return secret, true
134+
}
135+
136+
_, informer := cache.NewIndexerInformer(source, &v1.Secret{}, 0, cache.ResourceEventHandlerFuncs{
137+
// Note: For secrets we look at all of them because they do not have to be owned by this deployment.
138+
AddFunc: func(obj interface{}) {
139+
if _, ok := getSecret(obj); ok {
140+
d.triggerInspection()
141+
}
142+
},
143+
UpdateFunc: func(oldObj, newObj interface{}) {
144+
if _, ok := getSecret(newObj); ok {
145+
d.triggerInspection()
146+
}
147+
},
148+
DeleteFunc: func(obj interface{}) {
149+
if _, ok := getSecret(obj); ok {
150+
d.triggerInspection()
151+
}
152+
},
153+
}, cache.Indexers{})
154+
155+
informer.Run(stopCh)
156+
}
157+
115158
// listenForServiceEvents keep listening for changes in Service's until the given channel is closed.
116159
func (d *Deployment) listenForServiceEvents(stopCh <-chan struct{}) {
117160
source := cache.NewListWatchFromClient(

0 commit comments

Comments
 (0)