Skip to content

Commit

Permalink
fix: Ensure include works
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Mar 16, 2024
1 parent b23438f commit 27884e6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"path/filepath"
Expand Down Expand Up @@ -231,29 +232,29 @@ func getNsName(ctx context.Context, clientset *kubernetes.Clientset, namespace s

var nsExcludeCache = map[string]bool{}

func includeNamespace(ctx context.Context, clientset *kubernetes.Clientset, namespace string) bool {
func includeNamespace(ctx context.Context, clientset *kubernetes.Clientset, name string) bool {
// Single namespace mode is always included
if namespace != "" {
return true
}

// Check cache
if val, ok := nsExcludeCache[namespace]; ok {
if val, ok := nsExcludeCache[name]; ok {
return val
}

// Check annotation
ns, err := clientset.CoreV1().Namespaces().Get(ctx, namespace, v1.GetOptions{})
ns, err := clientset.CoreV1().Namespaces().Get(ctx, name, v1.GetOptions{})
if err != nil {
return false
}

nsExcludeCache[namespace] = false
nsExcludeCache[name] = false
if val, ok := ns.Annotations["k8status.stenic.io/include"]; ok && val == "true" {
nsExcludeCache[namespace] = true
nsExcludeCache[name] = true
}

return nsExcludeCache[namespace]
return nsExcludeCache[name]
}

func getSvcStatus(svcs []SvcRep) int {
Expand Down

0 comments on commit 27884e6

Please sign in to comment.