support wildcards --kube-include-namespace/--kube-exclude-namespace
This commit is contained in:
parent
65a4534be9
commit
263dd00c5b
4 changed files with 19 additions and 21 deletions
|
|
@ -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
go.mod
1
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
|
||||
|
|
|
|||
BIN
go.sum
BIN
go.sum
Binary file not shown.
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue