support wildcards --kube-include-namespace/--kube-exclude-namespace

This commit is contained in:
Tomas Hruska
2025-12-18 00:00:30 +01:00
parent 65a4534be9
commit 263dd00c5b
4 changed files with 21 additions and 21 deletions
+2 -2
View File
@@ -49,8 +49,8 @@ curl -fsSL http://<pulse-ip>: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` |
+1
View File
@@ -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
+2
View File
@@ -1,5 +1,7 @@
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/IGLOU-EU/go-wildcard/v2 v2.1.0 h1:WFqyYAuIYLJ6mHZ4rp/bYXiR4E1IvXW4+zInYWdQBqI=
github.com/IGLOU-EU/go-wildcard/v2 v2.1.0/go.mod h1:/sUMQ5dk2owR0ZcjRI/4AZ+bUFF5DxGCQrDMNBXUf5o=
github.com/Microsoft/go-winio v0.4.21 h1:+6mVbXh4wPzUrl1COX9A+ZCvEpYsOBZ6/+kwDnvLyro=
github.com/Microsoft/go-winio v0.4.21/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
+16 -19
View File
@@ -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) {