diff --git a/docs/UNIFIED_AGENT.md b/docs/UNIFIED_AGENT.md index b4714bb..92529a7 100644 --- a/docs/UNIFIED_AGENT.md +++ b/docs/UNIFIED_AGENT.md @@ -49,8 +49,8 @@ curl -fsSL http://:7655/install.sh | \ | `--disable-proxmox` | - | Disable Proxmox even if detected | - | | `--kubeconfig` | `PULSE_KUBECONFIG` | Kubeconfig path (optional) | *(auto)* | | `--kube-context` | `PULSE_KUBE_CONTEXT` | Kubeconfig context (optional) | *(auto)* | -| `--kube-include-namespace` | `PULSE_KUBE_INCLUDE_NAMESPACES` | Limit namespaces (repeatable or CSV) | *(all)* | -| `--kube-exclude-namespace` | `PULSE_KUBE_EXCLUDE_NAMESPACES` | Exclude namespaces (repeatable or CSV) | *(none)* | +| `--kube-include-namespace` | `PULSE_KUBE_INCLUDE_NAMESPACES` | Limit namespaces (repeatable or CSV, wildcards supported) | *(all)* | +| `--kube-exclude-namespace` | `PULSE_KUBE_EXCLUDE_NAMESPACES` | Exclude namespaces (repeatable or CSV, wildcards supported) | *(none)* | | `--kube-include-all-pods` | `PULSE_KUBE_INCLUDE_ALL_PODS` | Include all non-succeeded pods | `false` | | `--kube-max-pods` | `PULSE_KUBE_MAX_PODS` | Max pods per report | `200` | | `--disable-auto-update` | `PULSE_DISABLE_AUTO_UPDATE` | Disable auto-updates | `false` | diff --git a/go.mod b/go.mod index be0e260..2e61380 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.24.0 toolchain go1.24.7 require ( + github.com/IGLOU-EU/go-wildcard/v2 v2.1.0 github.com/coreos/go-oidc/v3 v3.17.0 github.com/docker/docker v28.5.2+incompatible github.com/fsnotify/fsnotify v1.9.0 diff --git a/go.sum b/go.sum index 46a8ff4..4f20a72 100644 Binary files a/go.sum and b/go.sum differ diff --git a/internal/kubernetesagent/agent.go b/internal/kubernetesagent/agent.go index 1b89708..3107eb2 100644 --- a/internal/kubernetesagent/agent.go +++ b/internal/kubernetesagent/agent.go @@ -15,6 +15,7 @@ import ( "strings" "time" + "github.com/IGLOU-EU/go-wildcard/v2" "github.com/rcourtman/pulse-go-rewrite/internal/buffer" agentsk8s "github.com/rcourtman/pulse-go-rewrite/pkg/agents/kubernetes" "github.com/rs/zerolog" @@ -69,8 +70,8 @@ type Agent struct { clusterContext string clusterVersion string - includeNamespaces sets.Set[string] - excludeNamespaces sets.Set[string] + includeNamespaces []string + excludeNamespaces []string reportBuffer *buffer.Queue[agentsk8s.Report] } @@ -164,8 +165,8 @@ func New(cfg Config) (*Agent, error) { clusterName: clusterName, clusterServer: clusterServer, clusterContext: clusterContext, - includeNamespaces: makeNamespaceSet(cfg.IncludeNamespaces), - excludeNamespaces: makeNamespaceSet(cfg.ExcludeNamespaces), + includeNamespaces: cfg.IncludeNamespaces, + excludeNamespaces: cfg.ExcludeNamespaces, reportBuffer: buffer.New[agentsk8s.Report](60), } @@ -241,17 +242,6 @@ func buildRESTConfig(kubeconfigPath, kubeContext string) (*rest.Config, string, return restCfg, contextName, nil } -func makeNamespaceSet(values []string) sets.Set[string] { - set := sets.New[string]() - for _, v := range values { - v = strings.TrimSpace(v) - if v != "" { - set.Insert(v) - } - } - return set -} - func computeClusterID(server, context, name string) string { payload := strings.TrimSpace(server) + "|" + strings.TrimSpace(context) + "|" + strings.TrimSpace(name) sum := sha256.Sum256([]byte(payload)) @@ -321,13 +311,20 @@ func (a *Agent) namespaceAllowed(ns string) bool { if ns == "" { return false } - if a.excludeNamespaces.Has(ns) { - return false + for _, excludeNamespace := range a.excludeNamespaces { + if wildcard.Match(excludeNamespace, ns) { + return false + } } - if a.includeNamespaces.Len() == 0 { + if len(a.includeNamespaces) == 0 { return true } - return a.includeNamespaces.Has(ns) + for _, includeNamespace := range a.includeNamespaces { + if wildcard.Match(includeNamespace, ns) { + return true + } + } + return false } func (a *Agent) collectReport(ctx context.Context) (agentsk8s.Report, error) {