Skip to content

Commit 0fd1fc3

Browse files
committed
check if ServiceAccount has secrets permission and dont poll if thats not the case
1 parent 57c012c commit 0fd1fc3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/registry_checker/checker.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
appsv1informers "k8s.io/client-go/informers/apps/v1"
2222
batchv1informers "k8s.io/client-go/informers/batch/v1"
2323
corev1informers "k8s.io/client-go/informers/core/v1"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425

2526
"k8s.io/client-go/informers"
2627

@@ -193,7 +194,17 @@ func NewRegistryChecker(
193194
}
194195
rc.controllerIndexers.cronJobIndexer = rc.cronJobsInformer.Informer().GetIndexer()
195196

196-
rc.controllerIndexers.secretIndexer = rc.secretsInformer.Informer().GetIndexer()
197+
namespace := "default"
198+
// Create a context
199+
ctx := context.TODO()
200+
// Attempt to list secrets in the default namespace
201+
_, enumerr := kubeClient.CoreV1().Secrets(namespace).List(ctx, metav1.ListOptions{})
202+
if enumerr != nil {
203+
// Not add the secret indexer to automatic cache updater
204+
logrus.Warn("Provided ServiceAccount does not seem to be able to list secrets. Image availability check for images in private registries not having spec.imagePullSecrets configured will fail!")
205+
} else {
206+
rc.controllerIndexers.secretIndexer = rc.secretsInformer.Informer().GetIndexer()
207+
}
197208

198209
go informerFactory.Start(stopCh)
199210
logrus.Info("Waiting for cache sync")

0 commit comments

Comments
 (0)