Skip to content

Commit 15fe5fd

Browse files
authoredJul 15, 2021
Add arg key to inspect specific namespace in k8s cluster (#32)
* feat(k8s): add key to inspect only specific namespace * docs(k8s): add key "namespace" information
1 parent 07016f1 commit 15fe5fd

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ spec:
204204
* Default: `5m`
205205
* `--ignored-images` — comma-separated list of images to ignore while checking absent images.
206206
* `--skip-registry-cert-verification` — whether to skip registries' certificate verification.
207+
* `--namespace` — inspect specific namespace instead of whole k8s cluster.
207208

208209
## Metrics
209210

‎main.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func main() {
3131
ignoredImagesStr := flag.String("ignored-images", "", "comma-separated image names to ignore")
3232
bindAddr := flag.String("bind-address", ":8080", "address:port to bind /metrics endpoint to")
3333
insecureSkipVerify := flag.Bool("skip-registry-cert-verification", false, "whether to skip registries' certificate verification")
34+
specificNamespace := flag.String("namespace", "", "inspect specific namespace instead of whole k8s cluster")
3435
flag.Parse()
3536

3637
logrus.SetFormatter(&logrus.TextFormatter{
@@ -64,6 +65,7 @@ func main() {
6465
kubeClient,
6566
*insecureSkipVerify,
6667
strings.Split(*ignoredImagesStr, ","),
68+
*specificNamespace,
6769
)
6870
prometheus.MustRegister(registryChecker)
6971

‎pkg/registry_checker/checker.go

+4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ func NewRegistryChecker(
5353
kubeClient *kubernetes.Clientset,
5454
skipVerify bool,
5555
ignoredImages []string,
56+
specificNamespace string,
5657
) *RegistryChecker {
5758
informerFactory := informers.NewSharedInformerFactory(kubeClient, time.Hour)
59+
if specificNamespace != "" {
60+
informerFactory = informers.NewSharedInformerFactoryWithOptions(kubeClient, time.Hour, informers.WithNamespace(specificNamespace))
61+
}
5862

5963
customTransport := http.DefaultTransport.(*http.Transport).Clone()
6064
if skipVerify {

0 commit comments

Comments
 (0)
Please sign in to comment.