Compare commits

..
3 Commits
Author SHA1 Message Date
Vitaliy ChefanovandClaude Opus 5.5 d6558c3d44 Makefile: build into a local registry, publish only final artifacts
werf keeps every stage in --repo, base images included; pushing
Deckhouse's builder/golang-alpine (762 MB layer) to Gitea over a home
uplink timed out. Stages now live in a local registry:2 and publish
crane-copies the app image, bundle and release, keeping digests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 21:27:31 +03:00
Vitaliy ChefanovandClaude Opus 5.5 18869e8bfc Makefile: keep only the base images this module uses
.werf/stages/base-images.yaml defines a werf image for every key of
base_images.yml, and Deckhouse's published file has ~1200 keys; a full
build started pulling and storing all of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 21:23:40 +03:00
Vitaliy ChefanovandClaude Opus 5.5 4518393ce1 Package cluster-map as a Deckhouse module
Layout, build and templates follow deckhouse/modules-template; dmt lint
passes with no findings (Go files are excluded from the Flant-only
license-header rule, see .dmtlint.yaml).

- module.yaml, openapi schemas with Russian docs, lib-helm templates:
  https modes, ingress class, publicDomainTemplate, node placement,
  priority class, PSS-restricted security context, VPA, PDB, Ingress
  plus Gateway API ListenerSet/HTTPRoute, DexAuthenticator.
- module-sdk hooks: hubble CA from d8-cni-cilium (public certificate
  only), external_auth, copy_custom_certificate.
- The app moves to images/cluster-map/src and is split into packages;
  traffic mode Continuous/OnDemand/Disabled and retention are module
  settings; graceful shutdown; Prometheus metrics and two alerts;
  frontend embedded, English and Russian, strict CSP.
- Built with werf on Deckhouse's published base images; Makefile
  publishes the registry layout modules-actions uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 21:17:52 +03:00
82 changed files with 5738 additions and 1415 deletions
+12
View File
@@ -0,0 +1,12 @@
# The license rule only accepts "Copyright <year> Flant JSC" headers. This
# module is developed outside Flant, so its Go files carry an Apache-2.0
# header with a neutral copyright line and are excluded from that one rule.
# On transfer to the Deckhouse team, rewrite the headers and drop this file;
# every other rule runs at its default severity.
linters-settings:
module:
exclude-rules:
license:
directories:
- images/cluster-map/src
- hooks/batch
+5 -2
View File
@@ -1,2 +1,5 @@
/cluster-map
*.log
base_images.yml
images_tags_werf.json
/.werf-*
*.tgz
!charts/*.tgz
+18
View File
@@ -0,0 +1,18 @@
.git/
.gitignore
.werf/
.dmtlint.yaml
base_images.yml
base_images.yml.example
crds
docs
hooks
images
openapi
Makefile
*.md
werf*.yaml
oss.yaml
module.yaml
changelog.yaml
LICENSE
+1
View File
@@ -0,0 +1 @@
d8-cluster-map
+553
View File
@@ -0,0 +1,553 @@
{{/*
Internal helpers.
*/}}
{{- define "oss_yaml_render_condition" -}}
{{- $cond := index . 0 -}}
{{- $indent := (index . 1) | default "" -}}
{{- if not $cond -}}
{{- /* nothing */ -}}
{{- else -}}
{{- /* fromYaml returns map[interface{}]interface{}; normalize to map[string]interface{} for deterministic key sorting */ -}}
{{- $condStr := dict -}}
{{- range $k, $v := $cond -}}
{{- $_ := set $condStr (printf "%v" $k) $v -}}
{{- end -}}
{{- $keys := keys $condStr | sortAlpha -}}
{{- range $keys -}}
{{- $k := . -}}
{{- $val := index $condStr $k -}}
{{- if kindIs "slice" $val -}}
{{- printf "%s%s:\n" $indent ($k | quote) -}}
{{- range $val -}}
{{- printf "%s - %s\n" $indent ((printf "%v" .) | quote) -}}
{{- end -}}
{{- else -}}
{{- printf "%s%s: %s\n" $indent ($k | quote) ((printf "%v" $val) | quote) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "oss_yaml_render_version_struct" -}}
{{- $v := index . 0 -}}
{{- $indent := (index . 1) | default "" -}}
{{- $ver := (index $v "version") | default "" -}}
{{- if eq $ver "" -}}
{{- fail "\n[ERROR] Version struct has empty .version" -}}
{{- end -}}
{{- printf "%sversion: %s\n" $indent ($ver | quote) -}}
{{- $name := (index $v "name") | default "" -}}
{{- if ne $name "" -}}
{{- printf "%sname: %s\n" $indent ($name | quote) -}}
{{- end -}}
{{- $cond := index $v "condition" -}}
{{- if $cond -}}
{{- printf "%scondition:\n" $indent -}}
{{- include "oss_yaml_render_condition" (list $cond (printf "%s " $indent)) -}}
{{- end -}}
{{- end -}}
{{/*
Public helpers.
*/}}
{{- define "get_oss_version_by_id" -}}
{{- $id := index . 0 -}}
{{- $ctx := index . 1 -}}
{{- $version := "" -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if gt (len $versions) 0 -}}
{{- if eq (len $versions) 1 -}}
{{- $version = (index (index $versions 0) "version") | default "" -}}
{{- else -}}
{{- fail (printf "\n[ERROR] Multiple versions are defined for ID '%s' in file: %s. Use helper 'get_oss_version_by_id_and_condition'." $id $ossYamlPath) -}}
{{- end -}}
{{- else -}}
{{- $version = (index $item "version") | default "" -}}
{{- end -}}
{{- if eq $version "" -}}
{{- fail (printf "\n[ERROR] Version for ID '%s' is empty or not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $version -}}
{{- end -}}
{{/*
Returns YAML of a single version structure for a given id.
*/}}
{{- define "get_oss_version_struct_by_id" -}}
{{- $id := index . 0 -}}
{{- $ctx := index . 1 -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if gt (len $versions) 0 -}}
{{- if eq (len $versions) 1 -}}
{{- include "oss_yaml_render_version_struct" (list (index $versions 0) "") | trim -}}
{{- else -}}
{{- fail (printf "\n[ERROR] Multiple versions are defined for ID '%s' in file: %s. Use helper 'get_oss_version_by_id_and_condition' or 'get_oss_versions_by_id'." $id $ossYamlPath) -}}
{{- end -}}
{{- else -}}
{{- $version := (index $item "version") | default "" -}}
{{- if eq $version "" -}}
{{- fail (printf "\n[ERROR] Version for ID '%s' is empty or not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- include "oss_yaml_render_version_struct" (list (dict "version" $version) "") | trim -}}
{{- end -}}
{{- end -}}
{{/*
Returns concrete version string for a given id and condition.
*/}}
{{- define "get_oss_version_by_id_and_condition" -}}
{{- $id := index . 0 -}}
{{- $condition := index . 1 -}}
{{- $ctx := index . 2 -}}
{{- $version := "" -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if gt (len $versions) 0 -}}
{{- range $versions -}}
{{- $vCond := index . "condition" -}}
{{- if not $vCond -}}
{{- $vCond = dict -}}
{{- end -}}
{{- $match := true -}}
{{- range $k, $qVal := $condition -}}
{{- $cVal := index $vCond $k -}}
{{- if eq $cVal nil -}}
{{- $match = false -}}
{{- break -}}
{{- end -}}
{{- $cand := list -}}
{{- if kindIs "slice" $cVal -}}
{{- range $cVal -}}
{{- $cand = append $cand (printf "%v" .) -}}
{{- end -}}
{{- else -}}
{{- $cand = append $cand (printf "%v" $cVal) -}}
{{- end -}}
{{- $query := list -}}
{{- if kindIs "slice" $qVal -}}
{{- range $qVal -}}
{{- $query = append $query (printf "%v" .) -}}
{{- end -}}
{{- else -}}
{{- $query = append $query (printf "%v" $qVal) -}}
{{- end -}}
{{- range $query -}}
{{- $q := . -}}
{{- $found := false -}}
{{- range $cand -}}
{{- if eq . $q -}}
{{- $found = true -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if not $found -}}
{{- $match = false -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if not $match -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if $match -}}
{{- $version = (index . "version") | default "" -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq $version "" -}}
{{- $available := list -}}
{{- range $versions -}}
{{- $c := index . "condition" -}}
{{- if not $c -}}
{{- $c = dict -}}
{{- end -}}
{{- $available = append $available ((toJson $c) | default "{}") -}}
{{- end -}}
{{- fail (printf "\n[ERROR] Version for ID '%s' not found for condition %s in file: %s. Available conditions: %s" $id (toJson $condition) $ossYamlPath (join "; " $available)) -}}
{{- end -}}
{{- else -}}
{{- $version = (index $item "version") | default "" -}}
{{- end -}}
{{- if eq $version "" -}}
{{- fail (printf "\n[ERROR] Version for ID '%s' is empty or not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $version -}}
{{- end -}}
{{/*
Returns YAML array of version structures for a given id.
*/}}
{{- define "get_oss_versions_by_id" -}}
{{- $id := index . 0 -}}
{{- $ctx := index . 1 -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if gt (len $versions) 0 -}}
{{- range $versions -}}
{{- $v := . -}}
{{- $ver := (index $v "version") | default "" -}}
{{- if eq $ver "" -}}
{{- fail (printf "\n[ERROR] Empty version in versions[] for ID '%s' in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- printf "- version: %s\n" ($ver | quote) -}}
{{- $name := (index $v "name") | default "" -}}
{{- if ne $name "" -}}
{{- printf " name: %s\n" ($name | quote) -}}
{{- end -}}
{{- $cond := index $v "condition" -}}
{{- if $cond -}}
{{- printf " condition:\n" -}}
{{- include "oss_yaml_render_condition" (list $cond " ") -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- $version := (index $item "version") | default "" -}}
{{- if eq $version "" -}}
{{- fail (printf "\n[ERROR] Version for ID '%s' is empty or not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- printf "- version: %s\n" ($version | quote) -}}
{{- end -}}
{{- end -}}
{{/*
Returns mapping <condition[key] value> -> <version> for a given id.
*/}}
{{- define "get_oss_version_map_by_id_and_condition_key" -}}
{{- $id := index . 0 -}}
{{- $key := index . 1 -}}
{{- $ctx := index . 2 -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if eq (len $versions) 0 -}}
{{- fail (printf "\n[ERROR] No 'versions' array is defined for ID '%s' in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $out := dict -}}
{{- range $versions -}}
{{- $cond := index . "condition" -}}
{{- if not $cond -}}
{{- $cond = dict -}}
{{- end -}}
{{- $val := index $cond $key -}}
{{- if eq $val nil -}}
{{- fail (printf "\n[ERROR] Condition key '%s' is not defined for ID '%s' in file: %s. Condition: %s" $key $id $ossYamlPath (toJson $cond)) -}}
{{- end -}}
{{- $ver := (index . "version") | default "" -}}
{{- if eq $ver "" -}}
{{- fail (printf "\n[ERROR] Empty version in versions[] for ID '%s' in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $vals := list -}}
{{- if kindIs "slice" $val -}}
{{- range $val -}}
{{- $vals = append $vals (printf "%v" .) -}}
{{- end -}}
{{- else -}}
{{- $vals = append $vals (printf "%v" $val) -}}
{{- end -}}
{{- range $vals -}}
{{- $k := . -}}
{{- if ne (index $out $k) nil -}}
{{- fail (printf "\n[ERROR] Overlapping conditions for ID '%s' and key '%s': value '%s' is defined more than once in file: %s" $id $key $k $ossYamlPath) -}}
{{- end -}}
{{- $_ := set $out $k $ver -}}
{{- end -}}
{{- end -}}
{{- $keys := keys $out | sortAlpha -}}
{{- range $i, $k := $keys -}}
{{- printf "%s: %s\n" ($k | quote) ((index $out $k) | quote) -}}
{{- end -}}
{{- end -}}
{{/*
Returns mapping <k8s_version_in_range> -> <version> by evaluating semver constraints in `condition.<key>`.
*/}}
{{- define "get_oss_version_map_by_id_and_condition_key_semver" -}}
{{- $id := index . 0 -}}
{{- $key := index . 1 -}}
{{- $rangeSpec := index . 2 -}}
{{- $ctx := index . 3 -}}
{{- $ossYamlPath := "oss.yaml" -}}
{{- if not ($ctx.Files.Exists $ossYamlPath) -}}
{{- fail (printf "\n[ERROR] OSS file not found at path: %s" $ossYamlPath) -}}
{{- end -}}
{{- if not (kindIs "slice" $rangeSpec) -}}
{{- fail (printf "\n[ERROR] rangeSpec must be a list, got: %s" (kindOf $rangeSpec)) -}}
{{- end -}}
{{- if ne (mod (len $rangeSpec) 2) 0 -}}
{{- fail (printf "\n[ERROR] rangeSpec must contain even number of elements (key/value pairs), got len=%d" (len $rangeSpec)) -}}
{{- end -}}
{{- $range := dict -}}
{{- range $i, $_ := $rangeSpec -}}
{{- if eq (mod $i 2) 0 -}}
{{- $k := printf "%v" (index $rangeSpec $i) -}}
{{- $v := printf "%v" (index $rangeSpec (add $i 1)) -}}
{{- $_ := set $range $k $v -}}
{{- end -}}
{{- end -}}
{{- $start := (index $range "start") | default "" -}}
{{- $end := (index $range "end") | default "" -}}
{{- if or (eq $start "") (eq $end "") -}}
{{- fail (printf "\n[ERROR] rangeSpec must include 'start' and 'end'. Got: %s" (toJson $range)) -}}
{{- end -}}
{{- $sParts := splitList "." $start -}}
{{- $eParts := splitList "." $end -}}
{{- if or (ne (len $sParts) 2) (ne (len $eParts) 2) -}}
{{- fail (printf "\n[ERROR] start/end must look like '<major>.<minor>' (e.g. 1.32). Got start=%s end=%s" $start $end) -}}
{{- end -}}
{{- $major := (atoi (index $sParts 0)) | int -}}
{{- $sMinor := (atoi (index $sParts 1)) | int -}}
{{- $eMajor := (atoi (index $eParts 0)) | int -}}
{{- $eMinor := (atoi (index $eParts 1)) | int -}}
{{- if ne $major $eMajor -}}
{{- fail (printf "\n[ERROR] start/end major version mismatch: start=%s end=%s" $start $end) -}}
{{- end -}}
{{- if gt $sMinor $eMinor -}}
{{- fail (printf "\n[ERROR] start minor is greater than end minor: start=%s end=%s" $start $end) -}}
{{- end -}}
{{- $raw := printf "data:\n%s" ($ctx.Files.Get $ossYamlPath) | fromYaml -}}
{{- $item := dict -}}
{{- range $raw.data -}}
{{- if eq .id $id -}}
{{- $item = . -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if eq (len $item) 0 -}}
{{- fail (printf "\n[ERROR] ID '%s' not found in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $versions := index $item "versions" -}}
{{- if not $versions -}}
{{- $versions = list -}}
{{- end -}}
{{- if eq (len $versions) 0 -}}
{{- fail (printf "\n[ERROR] No 'versions' array is defined for ID '%s' in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- range $minor := untilStep $sMinor (add $eMinor 1 | int) 1 -}}
{{- $target := printf "%d.%d" $major $minor -}}
{{- $matchedVersion := "" -}}
{{- $matchedCount := 0 -}}
{{- range $versions -}}
{{- $cond := index . "condition" -}}
{{- if not $cond -}}
{{- $cond = dict -}}
{{- end -}}
{{- $val := index $cond $key -}}
{{- if eq $val nil -}}
{{- fail (printf "\n[ERROR] Condition key '%s' is not defined for ID '%s' in file: %s. Condition: %s" $key $id $ossYamlPath (toJson $cond)) -}}
{{- end -}}
{{- $ver := (index . "version") | default "" -}}
{{- if eq $ver "" -}}
{{- fail (printf "\n[ERROR] Empty version in versions[] for ID '%s' in file: %s" $id $ossYamlPath) -}}
{{- end -}}
{{- $constraints := list -}}
{{- if kindIs "slice" $val -}}
{{- range $val -}}
{{- $constraints = append $constraints (printf "%v" .) -}}
{{- end -}}
{{- else -}}
{{- $constraints = append $constraints (printf "%v" $val) -}}
{{- end -}}
{{- $entryMatches := false -}}
{{- range $constraints -}}
{{- $c := . -}}
{{- $cNorm := $c -}}
{{- /* exact version '1.35' -> '= 1.35' */ -}}
{{- if regexMatch "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$" $cNorm -}}
{{- $cNorm = printf "= %s" $cNorm -}}
{{- else -}}
{{- /* normalize operator without whitespace: '<=1.34' -> '<= 1.34' */ -}}
{{- $cNorm = regexReplaceAll "^(<=|>=|<|>|=|!=)\\s*" $cNorm "${1} " -}}
{{- end -}}
{{- if semverCompare $cNorm $target -}}
{{- $entryMatches = true -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if $entryMatches -}}
{{- $matchedCount = add $matchedCount 1 -}}
{{- if eq $matchedCount 1 -}}
{{- $matchedVersion = $ver -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq $matchedCount 0 -}}
{{- fail (printf "\n[ERROR] No version matched for ID '%s' key '%s' at %s in file: %s" $id $key $target $ossYamlPath) -}}
{{- end -}}
{{- if gt $matchedCount 1 -}}
{{- fail (printf "\n[ERROR] Overlapping semver conditions for ID '%s' key '%s' at %s in file: %s" $id $key $target $ossYamlPath) -}}
{{- end -}}
{{- printf "%s: %s\n" ($target | quote) ($matchedVersion | quote) -}}
{{- end -}}
{{- end -}}
+18
View File
@@ -0,0 +1,18 @@
# Base Images
{{- $baseImages := .Files.Get "base_images.yml" | fromYaml }}
{{- range $k, $v := $baseImages }}
{{ $baseImagePath := (printf "%s@%s" $baseImages.REGISTRY_PATH (trimSuffix "/" $v)) }}
{{- if ne $k "REGISTRY_PATH" }}
{{- $_ := set $baseImages $k $baseImagePath }}
{{- end }}
{{- end }}
{{- $_ := unset $baseImages "REGISTRY_PATH" }}
{{- $_ := set . "Images" $baseImages }}
# base images artifacts
{{- range $k, $v := .Images }}
---
image: {{ $k }}
from: {{ $v }}
final: false
{{- end }}
+27
View File
@@ -0,0 +1,27 @@
# Golang deps image, required to download dependencies and put it to the final module image (bundle)
# Image for building batch hooks with https://github.com/deckhouse/module-sdk support
---
image: batch-hooks
fromImage: builder/golang-alpine
final: false
git:
- add: /
to: /usr/src/app
includePaths:
- hooks/batch
stageDependencies:
install:
- '**/go.mod'
- '**/go.sum'
beforeSetup:
- '**/*.go'
shell:
install:
# Build patch must contains the `hooks/` folder
- cd /usr/src/app/hooks/batch
- go mod download
beforeSetup:
- |
cd /usr/src/app/hooks/batch;
# don't use `-trimpath` flag for building go hooks. Embedded binary path is necessary to properly identify a hook name
CGO_ENABLED=0 go build -gcflags=all="-l -B" -ldflags="-w -s" -o /usr/local/bin/batchhooks *.go;
+47
View File
@@ -0,0 +1,47 @@
# Bundle image, stored in your.registry.io/modules/<module-name>:<semver>
---
image: bundle
fromImage: builder/scratch
import:
# Enrich image digest and version
# Rendering .werf/stages/images-digests.yaml is required!
- image: images-digests-and-version
add: /
to: /
includePaths:
- images_digests.json
- version.json
after: setup
# batch hooks built with batch-go.yaml werf job
- image: batch-hooks
add: /usr/local/bin/batchhooks
to: /hooks/batchhooks
after: setup
# Uncomment if you use python hooks
# - image: python-dependencies
# add: /usr/bin
# to: /hooks/venv/
# before: setup
# - image: python-dependencies
# add: /lib/python/dist
# to: /lib/python/dist
# before: setup
git:
- add: /
to: /
excludePaths:
- hooks/batch # exclude sources
- docs/internal
includePaths:
- .helmignore
- docs
- charts
- crds
- enabled
- hooks
- monitoring
- openapi
- templates
- Chart.yaml
- module.yaml
- values.yaml
+47
View File
@@ -0,0 +1,47 @@
{{- /* Find all images digests and save use them to compose a structure for the module values. */ -}}
{{- $ImagesIDList := list }}
{{- $Images := tpl (.Files.Get ".werf/stages/images.yaml") . }}
{{- range $ImageManifest := regexSplit "\n?---[ \t]*\n" $Images -1 }}
{{- $ImageManifest := $ImageManifest | fromYaml }}
{{- if $ImageManifest.image }}
{{- if ne $ImageManifest.final false }}
{{- $ImagesIDList = append $ImagesIDList $ImageManifest.image }}
{{- end }}
{{- end }}
{{- end }}
# Images Digest: a files with all image digests to be able to use them in helm templates of a module
# Version: module version
---
image: images-digests-and-version
final: false
fromImage: builder/alpine
import:
- image: jq
add: /usr/bin/jq
before: install
dependencies:
{{- range $ImageID := $ImagesIDList }}
{{- $ImageNameCamel := $ImageID | splitList "/" | last | camelcase | untitle }}
- image: {{ $ImageID }}
before: setup
imports:
- type: ImageDigest
targetEnv: MODULE_IMAGE_DIGEST_{{ $ImageNameCamel }}
{{- end }}
shell:
setup:
- |
env | grep MODULE_IMAGE_DIGEST | jq -Rn '
reduce inputs as $i (
{};
. * (
$i | ltrimstr("MODULE_IMAGE_DIGEST_") | sub("=";"_") |
split("_") as [$imageName, $digest] |
{($imageName): $digest}
)
)
' > /images_digests.json
- |
jq -n --arg version "{{ env "MODULES_MODULE_TAG" }}" '{"version": $version}' > /version.json
+16
View File
@@ -0,0 +1,16 @@
{{- $Root := . }}
{{- $ImagesBuildFiles := .Files.Glob "images/*/{Dockerfile,werf.inc.yaml}" }}
{{- range $path, $content := $ImagesBuildFiles }}
{{- $ctx := dict }}
{{- $_ := set $ctx "ImageName" ($path | split "/")._1 }}
{{- $_ := set $ctx "ModuleName" "cluster-map" }}
{{- $_ := set $ctx "ImagePath" (printf "/images/%s" $ctx.ImageName) }}
{{- $_ := set $ctx "ModuleDir" "/" }}
{{- $_ := set $ctx "ProjectName" (list $ctx.ModuleName $ctx.ImageName | join "/") }}
{{- $_ := set $ctx "Commit" $Root.Commit }}
---
{{- $_ := set $ctx "Files" $Root.Files }}
{{ tpl $content $ctx }}
{{- end }}
+22
View File
@@ -0,0 +1,22 @@
# Release image, stored in your.registry.io/modules/<module-name>/release:<semver>
---
image: release-channel-version
fromImage: builder/scratch
import:
- image: images-digests-and-version
add: /
to: /
includePaths:
- version.json
after: install
git:
- add: /
to: /
includePaths:
- changelog.yaml
- crds
- docs
- module.yaml
- openapi
excludePaths:
- docs/internal
+6
View File
@@ -0,0 +1,6 @@
name: cluster-map
version: 0.7.0
dependencies:
- name: deckhouse_lib_helm
version: 1.72.24
repository: https://deckhouse.github.io/lib-helm
-14
View File
@@ -1,14 +0,0 @@
FROM golang:1.25-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /cluster-map .
FROM alpine:3.20
RUN adduser -D -u 10001 app
COPY --from=build /cluster-map /cluster-map
COPY static /static
USER app
WORKDIR /
ENTRYPOINT ["/cluster-map"]
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright The Events Exporter authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+81
View File
@@ -0,0 +1,81 @@
# cluster-map Deckhouse module.
#
# make test unit tests of the app and the hooks
# make lint golangci-lint + dmt
# make render helm template with test values (catches template errors fast)
# make publish VERSION=v0.7.0 [CHANNEL=alpha] build, push and register the module
# make release VERSION=v0.7.0 CHANNEL=stable move a release channel
#
# The registry layout follows deckhouse/modules-actions: <SOURCE>:<module>
# registers the module, <SOURCE>/<module>:<version> is the bundle,
# <SOURCE>/<module>/release:<version|channel> is the release image.
empty :=
space := $(empty) $(empty)
MODULE ?= cluster-map
SOURCE ?= git.project-chimera.ru/fanchji/cluster-map
CHANNEL ?= alpha
BASE_IMAGES_VERSION ?= v2.1.7
CRANE ?= crane
WERF ?= werf
# Stages are built into a local registry and only the final artifacts are
# copied to SOURCE. werf keeps every stage in --repo, base images included
# (Deckhouse's builder/golang-alpine has a 762 MB layer), which a remote or
# small registry doesn't need to hold. crane copy keeps digests, so the
# images_digests.json baked into the bundle stays valid.
BUILD_REGISTRY ?= localhost:5555
BUILD_REPO ?= $(BUILD_REGISTRY)/$(MODULE)
DMT ?= dmt
API_VERSIONS ?= --api-versions autoscaling.k8s.io/v1/VerticalPodAutoscaler --api-versions monitoring.coreos.com/v1/PodMonitor
.PHONY: test lint render base-images build-registry build publish release
test:
cd images/cluster-map/src && go test -race -count=1 ./...
cd hooks/batch && go test -count=1 ./...
lint:
cd images/cluster-map/src && golangci-lint run ./...
cd hooks/batch && go vet ./...
$(DMT) lint .
render:
helm template $(MODULE) . --namespace d8-cluster-map $(API_VERSIONS) -f tests/values/default.yaml > /dev/null
helm template $(MODULE) . --namespace d8-cluster-map $(API_VERSIONS) -f tests/values/default.yaml -f tests/values/no-hubble.yaml > /dev/null
@echo render OK
# Deckhouse publishes its base image digests; the same file official modules
# build from. .werf/stages/base-images.yaml turns every key into a werf image,
# and the full file has ~1200 of them, so only the keys this module uses are kept.
BASE_IMAGE_KEYS := REGISTRY_PATH builder/golang-alpine builder/alpine builder/scratch base/distroless jq
base_images.yml:
curl -sfL "https://fox.flant.com/api/v4/projects/deckhouse%2Fcontainer-base%2Fbase-images/packages/generic/base_images/$(BASE_IMAGES_VERSION)/base_images.yml" \
| grep -E '^($(subst $(space),|,$(BASE_IMAGE_KEYS))):' > $@
@test "$$(wc -l < $@)" -eq $(words $(BASE_IMAGE_KEYS)) || (echo "base_images.yml: expected $(words $(BASE_IMAGE_KEYS)) keys"; cat $@; rm -f $@; exit 1)
base-images: base_images.yml
build-registry:
@docker inspect cluster-map-build-registry >/dev/null 2>&1 || \
docker run -d --name cluster-map-build-registry -p 127.0.0.1:5555:5000 -v cluster-map-build-registry:/var/lib/registry registry:2 >/dev/null
@until curl -sf http://$(BUILD_REGISTRY)/v2/ >/dev/null; do sleep 1; done
build: base_images.yml build-registry
@test -n "$(VERSION)" || (echo "VERSION is required, e.g. VERSION=v0.7.0" && exit 1)
MODULES_MODULE_TAG=$(VERSION) $(WERF) build --repo=$(BUILD_REPO) --insecure-registry --save-build-report --build-report-path images_tags_werf.json
# Application images first (the bundle refers to them by digest), then the
# bundle and the release, then the module registration.
publish: build
jq -r '.Images | to_entries[] | select((.key | startswith("$(MODULE)/")) and (.key | endswith("-build") | not)) | .value.DockerImageName' images_tags_werf.json \
| while read -r img; do $(CRANE) copy --insecure "$$img" "$(SOURCE)/$(MODULE):$${img##*:}"; done
$(CRANE) copy --insecure "$$(jq -r '.Images.bundle.DockerImageName' images_tags_werf.json)" "$(SOURCE)/$(MODULE):$(VERSION)"
$(CRANE) copy --insecure "$$(jq -r '.Images."release-channel-version".DockerImageName' images_tags_werf.json)" "$(SOURCE)/$(MODULE)/release:$(VERSION)"
$(CRANE) append --oci-empty-base --new_layer "" --new_tag "$(SOURCE):$(MODULE)"
$(MAKE) release VERSION=$(VERSION) CHANNEL=$(CHANNEL)
release:
@test -n "$(VERSION)" || (echo "VERSION is required" && exit 1)
$(CRANE) copy "$(SOURCE)/$(MODULE)/release:$(VERSION)" "$(SOURCE)/$(MODULE)/release:$(CHANNEL)"
+93 -62
View File
@@ -1,74 +1,105 @@
# cluster-map
Topology map of the Project Chimera Deckhouse cluster.
A Deckhouse Kubernetes Platform module: an interactive topology map of the cluster with live traffic from Cilium Hubble. User documentation is in [docs/README.md](docs/README.md) ([на русском](docs/README_RU.md)).
- **Left**: inventory tree in two views. *Namespaces* groups objects by
namespace and kind; *Ноды* shows what is scheduled on each node. Search
matches names, images and ingress hosts.
- **Centre**: the selected namespace(s) or node as compact cards inside
namespace boxes. Solid arrows come from configuration (Ingress → Service
→ workload by label selector); dashed animated arrows are real traffic
from Hubble Relay over the chosen window (5 min / 15 min / 1 h), red when
Cilium dropped some of it. Peers from other namespaces are drawn as
dashed "ghost" cards. Kubelet probes, DNS, cilium health and node-to-node
traffic are not collected (see Backend). Traffic refreshes in place every 30 s without
relayout; peers that would need new cards wait for "Обновить".
- **Right**: details for the selected object — overview, links (config and
traffic, clickable), live YAML, pod logs.
The module follows [deckhouse/modules-template](https://github.com/deckhouse/modules-template): werf build, lib-helm templates, module-sdk hooks, and it passes `dmt lint` with no findings.
Workloads under non-native controllers (kruise Advanced DaemonSet behind
ingress-nginx, database operators, bare Jobs) are included and named the
way Hubble names them, so traffic attaches to the same cards.
## Layout
## Backend
Go, `client-go` in-cluster config. The graph is built from informer caches
(watch-backed, managedFields stripped), so `/api/graph` costs milliseconds
instead of ~0.9 s of List calls.
Traffic: each Cilium agent keeps only 4095 flows in its ring buffer — at a
few hundred flows/s that is ~10 s of history, so reading the buffer on
request can't answer "last 15 minutes". A background follow stream from
`hubble-relay.d8-cni-cilium.svc:443` (TLS verified with the public part of
Deckhouse's hubble CA at `/etc/hubble-ca/ca.crt`; relay does not ask for a
client certificate) feeds per-minute buckets for the last hour. Counts are
**distinct connections** (5-tuples), not Hubble events — one connection
produces several events. `new` = opened by TCP SYN inside the window,
`dropped` = tuples with a DROPPED verdict. After a restart the collector
only knows what it has seen since; `coveredSec` says how much of the
window that is.
Infra traffic is filtered at the agents (`infraFilters` in `flows.go`):
host-originated flows (kubelet probes, hostNetwork pods), remote-node,
cilium health and DNS :53. On a 12k-event sample they were ~74% of
non-reply events, none of them attach to a workload card, and streaming
them cost hubble-relay ~400m CPU.
| Endpoint | What |
| Path | What |
|---|---|
| `/api/graph` | nodes + config edges + pod placement |
| `/api/flows?namespaces=a,b&window=300` | aggregated traffic touching those namespaces |
| `/api/resource?kind=&namespace=&name=` | live YAML (managedFields stripped) |
| `/api/pods?id=wl/<ns>/<kind>/<name>&namespace=` | pods of a workload |
| `/api/logs?namespace=&pod=&container=` | last 500 log lines |
| `/healthz` | liveness/readiness |
| `module.yaml`, `Chart.yaml`, `.helmignore`, `oss.yaml`, `changelog.yaml` | module metadata |
| `openapi/` | `config-values.yaml` (ModuleConfig settings), `doc-ru-config-values.yaml`, `values.yaml` (internal values) |
| `templates/` | Helm templates on [lib-helm](https://github.com/deckhouse/lib-helm) (`charts/deckhouse_lib_helm-*.tgz`) |
| `hooks/batch/` | Go hooks on [module-sdk](https://github.com/deckhouse/module-sdk): hubble CA, external auth, custom certificate |
| `images/cluster-map/` | the application image: `werf.inc.yaml` and the Go source in `src/` |
| `monitoring/prometheus-rules/` | alert rules |
| `docs/` | user documentation, English and Russian |
| `.werf/`, `werf.yaml`, `werf-giterminism.yaml` | build, from modules-template |
| `tests/values/` | values for `make render` |
## Frontend
### The application (`images/cluster-map/src`)
Plain JS, no build step: `static/index.html`, `app.css`, `app.js`.
Cytoscape.js draws, elkjs lays out in two passes (each box on its own with
its unconnected groups packed in rows, then the boxes against each other).
Both libraries are vendored in `static/vendor/` so the page works without a
CDN. Theme follows `prefers-color-scheme`.
| Package | What |
|---|---|
| `cmd/cluster-map` | wiring, signals, graceful shutdown |
| `internal/config` | settings from the environment (the Deployment template is the only writer) |
| `internal/kube` | informer caches, managedFields stripped |
| `internal/topology` | the graph: workloads, Services, Ingresses, nodes, and the pod-owner rules shared with traffic |
| `internal/traffic` | Hubble follow stream, per-minute buckets of distinct connections |
| `internal/server` | HTTP API, CSP headers, request metrics |
| `internal/metrics` | Prometheus metrics |
| `web/` | the frontend, embedded into the binary: plain JS, Cytoscape.js, elkjs, English and Russian |
## Build and deploy
API: `/api/graph`, `/api/flows?namespaces=a,b&window=<seconds>`, `/api/resource?kind=&namespace=&name=`, `/api/pods?id=&namespace=`, `/api/logs?namespace=&pod=&container=`, `/healthz`, `/readyz`; metrics on `:9090/metrics`.
```
R=git.project-chimera.ru/fanchji/cluster-map/cluster-map-app
docker build -t $R:vX . && docker push $R:vX
docker inspect --format '{{index .RepoDigests 0}}' $R:vX
## Development
```shell
make test # go test -race for the app, hook tests on the module-sdk framework
make lint # golangci-lint and dmt
make render # helm template with tests/values/*.yaml
```
The Deployment pins the image by digest. Anonymous pull works (public Gitea
user), no imagePullSecret. Manifests: `03-kubernetes/apps/cluster-map/` in
`project-chimera`, mirrored to `k8s-manifests` for Argo.
`dmt` is built from [deckhouse/dmt](https://github.com/deckhouse/dmt); `crane` from go-containerregistry.
## Build and publish
Base images come from the `base_images.yml` Deckhouse publishes for its own modules (`make base-images`; the file is not committed, as in the template).
```shell
docker login git.project-chimera.ru
make publish VERSION=v0.7.0 # build, push bundle and release, register, channel alpha
make release VERSION=v0.7.0 CHANNEL=stable
```
The registry layout matches [deckhouse/modules-actions](https://github.com/deckhouse/modules-actions):
```text
<SOURCE>:cluster-map module registration (empty image)
<SOURCE>/cluster-map:v0.7.0 bundle
<SOURCE>/cluster-map:<content-tag> application image
<SOURCE>/cluster-map/release:v0.7.0 release
<SOURCE>/cluster-map/release:<channel> alpha | beta | early-access | stable | rock-solid
```
## Install
```yaml
apiVersion: deckhouse.io/v1alpha1
kind: ModuleSource
metadata:
name: cluster-map
spec:
registry:
repo: git.project-chimera.ru/fanchji/cluster-map
scheme: HTTPS
---
apiVersion: deckhouse.io/v1alpha2
kind: ModuleUpdatePolicy
metadata:
name: cluster-map
spec:
releaseChannel: Alpha
update:
mode: Auto
---
apiVersion: deckhouse.io/v1alpha1
kind: ModuleConfig
metadata:
name: cluster-map
spec:
enabled: true
version: 1
updatePolicy: cluster-map
source: cluster-map
settings:
auth:
allowedUserGroups: [admins]
```
The module is `Experimental`: enable `allowExperimentalModules` in the `deckhouse` ModuleConfig first.
## License
Apache 2.0, see [LICENSE](LICENSE). Go files carry an Apache-2.0 header with a neutral copyright line; DMT's license rule expects `Copyright <year> Flant JSC`, so `.dmtlint.yaml` excludes the two Go directories from that rule until the headers are changed on transfer.
+7
View File
@@ -0,0 +1,7 @@
# REGISTRY_PATH is a special key which is concatenated with other base images
REGISTRY_PATH: registry.organization.ru/base_images
tools/yq: "sha256:example"
tools/jq: "sha256:example"
builder/golang-alpine: "sha256:example"
builder/alpine: "sha256:example"
builder/scratch: "sha256:example"
+12
View File
@@ -0,0 +1,12 @@
v0.7.0:
features:
- First release as a Deckhouse module (ModuleSource, release channels, lib-helm templates).
- "Traffic collection modes: Continuous, OnDemand, Disabled; retention configurable up to 24h."
- Hubble CA is read by a module hook from d8-cni-cilium; no manual copy of the certificate.
- Authentication through user-authn (DexAuthenticator) or any external auth, as in cilium-hubble.
- English and Russian UI.
- Prometheus metrics and alerts for the Hubble stream.
fixes:
- Traffic windows now cover the requested time instead of the agent ring buffer (about 10 seconds).
- Counts are distinct connections, not Hubble events.
- Pod exits cleanly on SIGTERM.
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
---
title: "The cluster-map module: configuration"
---
<!-- SCHEMA -->
+5
View File
@@ -0,0 +1,5 @@
---
title: "Модуль cluster-map: настройки"
---
<!-- SCHEMA -->
+42
View File
@@ -0,0 +1,42 @@
---
title: "The cluster-map module: examples"
---
## Enable the module for administrators
```yaml
apiVersion: deckhouse.io/v1alpha1
kind: ModuleConfig
metadata:
name: cluster-map
spec:
enabled: true
version: 1
settings:
auth:
allowedUserGroups:
- admins
```
The web interface opens at `cluster-map.<publicDomainTemplate>`.
## Collect traffic only while the map is in use
```yaml
spec:
settings:
traffic:
mode: OnDemand
onDemandIdleMinutes: 15
```
## Keep a day of traffic
```yaml
spec:
settings:
traffic:
retentionMinutes: 1440
```
Memory grows with retention; watch `cluster_map_traffic_tracked_tuples` and the `ClusterMapTrackedTuplesHigh` alert.
+42
View File
@@ -0,0 +1,42 @@
---
title: "Модуль cluster-map: примеры"
---
## Включить модуль для администраторов
```yaml
apiVersion: deckhouse.io/v1alpha1
kind: ModuleConfig
metadata:
name: cluster-map
spec:
enabled: true
version: 1
settings:
auth:
allowedUserGroups:
- admins
```
Веб-интерфейс открывается по адресу `cluster-map.<publicDomainTemplate>`.
## Собирать трафик только во время работы с картой
```yaml
spec:
settings:
traffic:
mode: OnDemand
onDemandIdleMinutes: 15
```
## Хранить трафик за сутки
```yaml
spec:
settings:
traffic:
retentionMinutes: 1440
```
Память растёт вместе с глубиной хранения — следите за `cluster_map_traffic_tracked_tuples` и алертом `ClusterMapTrackedTuplesHigh`.
+66
View File
@@ -0,0 +1,66 @@
---
title: "The cluster-map module"
description: "Interactive topology map of the cluster with live traffic from Cilium Hubble."
webIfaces:
- name: cluster-map
---
The `cluster-map` module answers "where does this service live and what does it talk to" without a trip through `kubectl`. It shows the cluster as an inventory tree and a topology map: namespaces, workloads with their Services and Ingresses, the nodes they run on, real traffic between them, and the YAML and logs of each object.
## What is on the screen
- **Inventory tree** (left). Two views: *Namespaces* — namespace → object kind → objects; *Nodes* — node → namespace → workloads. Search matches names, images and Ingress hosts. The tree is keyboard-navigable.
- **Map** (centre). Only what is selected in the tree: one or several namespaces (Ctrl+click) or one node. Objects are compact cards inside namespace boxes, laid out left to right: Ingress → Service → workload.
- Solid arrows are configuration links: Ingress backends and Service selectors.
- Dashed animated arrows are real connections from Hubble over the chosen window (5 minutes, 15 minutes, 1 hour); red when Cilium dropped some of them. Peers from other namespaces appear as dashed cards in their own boxes.
- With more than 30 traffic directions on screen, lines stay faint until a card is hovered or selected.
- **Details** (right). Overview, Links (configuration and traffic, clickable), live YAML, and container logs.
Workloads managed by non-native controllers are included: Advanced DaemonSets of OpenKruise, database operator clusters, static pods, standalone Jobs. They are named the way Hubble names workloads, so their traffic attaches to the same cards.
## How traffic is collected
Every Cilium agent keeps only a ring buffer of flows (4095 by default); at a few hundred flows per second this is about ten seconds of history. A one-off query "for the last 15 minutes" would silently return the last few seconds. The module therefore keeps a follow stream from Hubble Relay and aggregates it into per-minute buckets for the configured retention.
Counts are **distinct connections** (source and destination address and port), not Hubble events: one connection produces several events. For each direction the module also reports how many connections were opened (TCP SYN) inside the window and how many had a `DROPPED` verdict.
Kubelet probes and other traffic originating from node hosts, node-to-node traffic, Cilium health checks and DNS are filtered at the agents and never reach the module. On a typical cluster this is about three quarters of all flows and none of it maps to a workload. Set `traffic.collectInfraTraffic` to collect it anyway.
The collector runs in one of three modes, see `traffic.mode`:
| Mode | Cost | Traffic windows |
|---|---|---|
| `Continuous` | stream always open; about 100–150m CPU on hubble-relay on a busy cluster | full as soon as the map is opened |
| `OnDemand` | stream only while someone uses the map | fill from the moment the map is opened |
| `Disabled` | none | configuration links only |
History is kept in memory: after a pod restart the windows fill again. The status line says how much of the window has actually been seen.
## Requirements
- Deckhouse Kubernetes Platform 1.72 or newer.
- For traffic: the `cni-cilium` and `cilium-hubble` modules. Without `cilium-hubble` the module works and shows configuration links only.
- For access control: the `user-authn` module, or any external authentication (`auth.externalAuthentication`).
## Security
The web interface reads the cluster through the module's own service account (`d8:cluster-map` ClusterRole): `get`, `list`, `watch` on namespaces, pods, services, nodes, deployments, statefulsets, daemonsets, cronjobs and ingresses, and `get` on `pods/log`. It never reads Secrets or ConfigMaps and has no write verbs.
This means **anyone admitted to the web interface sees every namespace and can read container logs**, whatever their own RBAC permissions are. Restrict access with `auth.allowedUserGroups` (and optionally `auth.allowedUserEmails` and `auth.whitelistSourceRanges`).
The frontend is served with a strict Content Security Policy: only its own scripts, styles and API, no inline code, no framing.
To verify the Hubble Relay certificate the module needs the public certificate of the hubble CA. A module hook reads it from the `hubble-ca-secret` Secret in `d8-cni-cilium`; the jq filter keeps only `ca.crt`, the CA key never reaches the module values.
## Metrics and alerts
The pod exposes Prometheus metrics on port `9090` (`cluster_map_*`: Hubble stream state, flows processed, tracked connections, API latency) and ships two alerts:
- `ClusterMapHubbleDisconnected` — no flows from Hubble Relay for 15 minutes while the collector is supposed to be running.
- `ClusterMapTrackedTuplesHigh` — the collector holds more than 2 million connections; lower the retention or switch to `OnDemand`.
## Limitations
- One replica: traffic history lives in the process. A second replica would keep its own history and double the load on hubble-relay.
- Access is all-or-nothing, as described in [Security](#security). Showing each user only what their RBAC allows is planned.
- Traffic is L3/L4. HTTP-level details (paths, status codes) need Cilium L7 visibility and are not shown yet.
+66
View File
@@ -0,0 +1,66 @@
---
title: "Модуль cluster-map"
description: "Интерактивная карта кластера с живым трафиком из Cilium Hubble."
webIfaces:
- name: cluster-map
---
Модуль `cluster-map` отвечает на вопрос «где живёт этот сервис и с кем он общается» без похода в `kubectl`. Он показывает кластер деревом инвентаря и картой: namespace, workload'ы с их Service и Ingress, ноды, на которых они работают, реальный трафик между ними, YAML и логи каждого объекта.
## Что на экране
- **Дерево инвентаря** (слева). Два вида: *Namespaces* — namespace → тип объекта → объекты; *Ноды* — нода → namespace → workload'ы. Поиск ищет по имени, образу и хосту Ingress. Дерево управляется с клавиатуры.
- **Карта** (в центре). Только то, что выбрано в дереве: один или несколько namespace (Ctrl+клик) или одна нода. Объекты — компактные карточки в рамках namespace, слева направо: Ingress → Service → workload.
- Сплошные стрелки — связи по конфигурации: backend Ingress и селектор Service.
- Пунктир с анимацией — реальные соединения из Hubble за выбранное окно (5 минут, 15 минут, час); красный, если Cilium часть из них отбросил. Пиры из других namespace — пунктирные карточки в своих рамках.
- Если на экране больше 30 направлений трафика, линии бледные, пока не наведёшь курсор на карточку или не выберешь её.
- **Детали** (справа). Обзор, Связи (по конфигурации и по трафику, с переходом), живой YAML и логи контейнеров.
Workload'ы под нестандартными контроллерами тоже на карте: Advanced DaemonSet из OpenKruise, кластеры операторов баз данных, статические поды, одиночные Job. Они названы так же, как их называет Hubble, поэтому трафик привязывается к тем же карточкам.
## Как собирается трафик
Каждый агент Cilium хранит только кольцевой буфер потоков (по умолчанию 4095); при нескольких сотнях потоков в секунду это около десяти секунд истории. Разовый запрос «за последние 15 минут» молча вернул бы последние секунды. Поэтому модуль держит постоянный поток из Hubble Relay и раскладывает его по минутным корзинам на заданную глубину.
Считаются **различные соединения** (адрес и порт источника и получателя), а не события Hubble: одно соединение даёт несколько событий. Для каждого направления модуль отдельно показывает, сколько соединений открыто внутри окна (TCP SYN) и сколько получили вердикт `DROPPED`.
Пробы kubelet и прочий трафик с хостов нод, трафик между нодами, проверки Cilium health и DNS отсекаются на агентах и до модуля не доходят. На обычном кластере это около трёх четвертей всех потоков, и ни один из них не привязан к workload'у. Чтобы всё же собирать их, включите `traffic.collectInfraTraffic`.
Режимы сбора — параметр `traffic.mode`:
| Режим | Цена | Окна трафика |
|---|---|---|
| `Continuous` | поток открыт всегда; около 100–150m CPU на hubble-relay на нагруженном кластере | заполнены сразу при открытии карты |
| `OnDemand` | поток открыт, только пока с картой работают | заполняются с момента открытия карты |
| `Disabled` | нет | только связи по конфигурации |
История хранится в памяти: после рестарта пода окна заполняются заново. Строка статуса пишет, сколько из окна реально видно.
## Требования
- Deckhouse Kubernetes Platform 1.72 или новее.
- Для трафика — модули `cni-cilium` и `cilium-hubble`. Без `cilium-hubble` модуль работает и показывает только связи по конфигурации.
- Для разграничения доступа — модуль `user-authn` или любая внешняя аутентификация (`auth.externalAuthentication`).
## Безопасность
Веб-интерфейс читает кластер через собственную учётку модуля (ClusterRole `d8:cluster-map`): `get`, `list`, `watch` на namespaces, pods, services, nodes, deployments, statefulsets, daemonsets, cronjobs и ingresses и `get` на `pods/log`. Secret и ConfigMap он не читает, прав на запись нет.
Отсюда следует: **любой, кого пустили в веб-интерфейс, видит все namespace и может читать логи контейнеров** — независимо от собственных прав RBAC. Ограничивайте доступ через `auth.allowedUserGroups` (а также `auth.allowedUserEmails` и `auth.whitelistSourceRanges`).
Фронтенд отдаётся со строгой Content Security Policy: только собственные скрипты, стили и API, без inline-кода, без встраивания во фреймы.
Чтобы проверять сертификат Hubble Relay, модулю нужен публичный сертификат hubble CA. Хук модуля читает его из Secret `hubble-ca-secret` в `d8-cni-cilium`; jq-фильтр оставляет только `ca.crt`, ключ CA в значения модуля не попадает.
## Метрики и алерты
Под отдаёт метрики Prometheus на порту `9090` (`cluster_map_*`: состояние потока из Hubble, обработанные потоки, число отслеживаемых соединений, задержки API) и приносит два алерта:
- `ClusterMapHubbleDisconnected` — 15 минут нет потоков из Hubble Relay, хотя сбор должен идти.
- `ClusterMapTrackedTuplesHigh` — коллектор держит больше 2 миллионов соединений; уменьшите глубину хранения или переключите режим на `OnDemand`.
## Ограничения
- Одна реплика: история трафика живёт в процессе. Вторая реплика держала бы свою историю и удвоила бы нагрузку на hubble-relay.
- Доступ по принципу «всё или ничего», см. раздел [Безопасность](#безопасность). Показ каждому пользователю только того, что разрешает его RBAC, — в планах.
- Трафик на уровне L3/L4. Подробности HTTP (пути, коды ответа) требуют L7-видимости Cilium и пока не показываются.
-437
View File
@@ -1,437 +0,0 @@
package main
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"hash/fnv"
"log"
"net/http"
"os"
"sort"
"strconv"
"strings"
"sync"
"time"
flowpb "github.com/cilium/cilium/api/v1/flow"
observerpb "github.com/cilium/cilium/api/v1/observer"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// Relay serves a *.hubble-relay.cilium.io certificate signed by Deckhouse's
// hubble CA and does not ask for a client certificate, so plain TLS with
// that CA is enough. The CA is mounted from a ConfigMap (public part only).
const hubbleServerName = "cluster-map.hubble-relay.cilium.io"
// Each agent keeps only 4095 flows in its ring buffer, which at a few
// hundred flows/s is ~10 s of history. So traffic is collected continuously
// from a follow stream into per-minute buckets covering the last hour.
const (
bucketCount = 60
maxTuplesPerKey = 20000 // per edge per minute; beyond it counts stop growing
)
type FlowEndpoint struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"` // lowercased controller kind, "pod", or "external"
Namespace string `json:"namespace,omitempty"`
}
type FlowEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Port string `json:"port"` // "443/TCP"
Connections int `json:"connections"` // distinct 5-tuples seen in the window
New int `json:"new"` // of those, opened (TCP SYN) in the window
Dropped int `json:"dropped"` // distinct 5-tuples with a DROPPED verdict
Last string `json:"last"`
}
type FlowsResult struct {
WindowSec int `json:"windowSec"`
CoveredSec int `json:"coveredSec"` // how much of the window the collector has actually seen
Connected bool `json:"connected"`
Error string `json:"error,omitempty"`
Endpoints []FlowEndpoint `json:"endpoints"`
Edges []FlowEdge `json:"edges"`
}
type edgeKey struct{ src, dst, port string }
const (
tupleSYN uint8 = 1
tupleDrop uint8 = 2
)
type bucketEdge struct {
tuples map[uint64]uint8
last int64
}
type bucket struct {
minute int64
edges map[edgeKey]*bucketEdge
}
type collector struct {
mu sync.Mutex
buckets [bucketCount]*bucket
endpoints map[string]FlowEndpoint
startedAt time.Time
connected bool
lastErr string
flows uint64
}
var flowsCollector = &collector{endpoints: map[string]FlowEndpoint{}}
func startHubble() {
caPEM, err := os.ReadFile(envOr("HUBBLE_CA_FILE", "/etc/hubble-ca/ca.crt"))
if err != nil {
flowsCollector.setErr(fmt.Errorf("hubble CA: %w", err))
return
}
pool := x509.NewCertPool()
if !pool.AppendCertsFromPEM(caPEM) {
flowsCollector.setErr(errors.New("hubble CA: no certificate in file"))
return
}
creds := credentials.NewTLS(&tls.Config{RootCAs: pool, ServerName: hubbleServerName, MinVersion: tls.VersionTLS12})
conn, err := grpc.NewClient(envOr("HUBBLE_RELAY_ADDR", "hubble-relay.d8-cni-cilium.svc:443"), grpc.WithTransportCredentials(creds))
if err != nil {
flowsCollector.setErr(err)
return
}
go flowsCollector.run(observerpb.NewObserverClient(conn))
}
func envOr(k, def string) string {
if v := os.Getenv(k); v != "" {
return v
}
return def
}
func (c *collector) setErr(err error) {
c.mu.Lock()
defer c.mu.Unlock()
c.connected = false
c.lastErr = err.Error()
log.Printf("hubble: %v", err)
}
// Filtered at the agents, so the relay never serialises them. Measured on a
// 12k-event sample: host-originated traffic (kubelet probes, hostNetwork
// pods) 43% of non-reply events, DNS :53 19%, remote-node 11%, cilium
// health 1%. None of it attaches to a workload card, and the relay spent
// ~400m CPU streaming it all.
var infraFilters = []*flowpb.FlowFilter{
{SourceLabel: []string{"reserved:host"}},
{SourceLabel: []string{"reserved:remote-node"}},
{SourceLabel: []string{"reserved:health"}},
{DestinationLabel: []string{"reserved:health"}},
{DestinationPort: []string{"53"}},
}
var flowFields = []string{"time", "verdict", "IP", "l4", "source", "destination", "source_names", "destination_names", "node_name"}
func (c *collector) run(obs observerpb.ObserverClient) {
c.mu.Lock()
c.startedAt = time.Now()
c.mu.Unlock()
useMask := true
backoff := time.Second
for {
req := &observerpb.GetFlowsRequest{
Follow: true,
// backfill whatever the ring buffers still hold; duplicate
// tuples after a reconnect collapse in the per-minute sets
Since: timestamppb.New(time.Now().Add(-time.Minute)),
Whitelist: []*flowpb.FlowFilter{{Reply: []bool{false}}},
Blacklist: infraFilters,
}
if useMask {
req.FieldMask = &fieldmaskpb.FieldMask{Paths: flowFields}
}
before := c.flowsSeen()
err := c.stream(obs, req)
if status.Code(err) == codes.InvalidArgument && useMask {
useMask = false
log.Printf("hubble: relay rejected field mask, retrying without it: %v", err)
continue
}
c.setErr(err)
if c.flowsSeen() > before {
backoff = time.Second // the stream worked for a while; reconnect quickly
}
time.Sleep(backoff)
backoff = min(backoff*2, 30*time.Second)
}
}
func (c *collector) flowsSeen() uint64 {
c.mu.Lock()
defer c.mu.Unlock()
return c.flows
}
func (c *collector) stream(obs observerpb.ObserverClient, req *observerpb.GetFlowsRequest) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s, err := obs.GetFlows(ctx, req)
if err != nil {
return err
}
for {
resp, err := s.Recv()
if err != nil {
return err
}
if f := resp.GetFlow(); f != nil {
c.add(f)
}
}
}
func (c *collector) add(f *flowpb.Flow) {
src := flowEndpoint(f.GetSource(), f.GetSourceNames(), f.GetNodeName())
dst := flowEndpoint(f.GetDestination(), f.GetDestinationNames(), f.GetNodeName())
if src.ID == dst.ID {
return
}
port, tuple, syn := l4Info(f)
ts := time.Now()
if t := f.GetTime(); t != nil {
ts = t.AsTime()
}
minute := ts.Unix() / 60
c.mu.Lock()
defer c.mu.Unlock()
if !c.connected {
c.connected, c.lastErr = true, ""
}
c.flows++
b := c.buckets[minute%bucketCount]
if b == nil || b.minute != minute {
if b != nil && b.minute > minute {
return // older than the retained hour
}
b = &bucket{minute: minute, edges: map[edgeKey]*bucketEdge{}}
c.buckets[minute%bucketCount] = b
c.pruneEndpoints()
}
c.endpoints[src.ID] = src
c.endpoints[dst.ID] = dst
k := edgeKey{src.ID, dst.ID, port}
e := b.edges[k]
if e == nil {
e = &bucketEdge{tuples: map[uint64]uint8{}}
b.edges[k] = e
}
h := hashTuple(f.GetIP().GetSource(), f.GetIP().GetDestination(), tuple)
flags, seen := e.tuples[h]
if !seen && len(e.tuples) >= maxTuplesPerKey {
return
}
if syn {
flags |= tupleSYN
}
if f.GetVerdict() == flowpb.Verdict_DROPPED {
flags |= tupleDrop
}
e.tuples[h] = flags
e.last = max(e.last, ts.Unix())
}
// pruneEndpoints drops metadata for endpoints no retained bucket mentions.
func (c *collector) pruneEndpoints() {
used := map[string]bool{}
for _, b := range c.buckets {
if b == nil {
continue
}
for k := range b.edges {
used[k.src], used[k.dst] = true, true
}
}
for id := range c.endpoints {
if !used[id] {
delete(c.endpoints, id)
}
}
}
func hashTuple(srcIP, dstIP, rest string) uint64 {
h := fnv.New64a()
h.Write([]byte(srcIP))
h.Write([]byte{0})
h.Write([]byte(dstIP))
h.Write([]byte{0})
h.Write([]byte(rest))
return h.Sum64()
}
// l4Info returns the display port ("443/TCP"), the port part of the
// connection tuple, and whether this event opens a TCP connection.
func l4Info(f *flowpb.Flow) (port, tuple string, syn bool) {
l4 := f.GetL4()
switch {
case l4.GetTCP() != nil:
t := l4.GetTCP()
fl := t.GetFlags()
return strconv.Itoa(int(t.GetDestinationPort())) + "/TCP",
"tcp:" + strconv.Itoa(int(t.GetSourcePort())) + ":" + strconv.Itoa(int(t.GetDestinationPort())),
fl.GetSYN() && !fl.GetACK()
case l4.GetUDP() != nil:
u := l4.GetUDP()
return strconv.Itoa(int(u.GetDestinationPort())) + "/UDP",
"udp:" + strconv.Itoa(int(u.GetSourcePort())) + ":" + strconv.Itoa(int(u.GetDestinationPort())), false
case l4.GetSCTP() != nil:
s := l4.GetSCTP()
return strconv.Itoa(int(s.GetDestinationPort())) + "/SCTP",
"sctp:" + strconv.Itoa(int(s.GetSourcePort())) + ":" + strconv.Itoa(int(s.GetDestinationPort())), false
case l4.GetICMPv4() != nil || l4.GetICMPv6() != nil:
return "ICMP", "icmp", false
}
return "?", "?", false
}
func (c *collector) query(namespaces map[string]bool, window int) FlowsResult {
now := time.Now()
fromMinute := now.Add(-time.Duration(window)*time.Second).Unix() / 60
c.mu.Lock()
defer c.mu.Unlock()
res := FlowsResult{WindowSec: window, Connected: c.connected, Error: c.lastErr}
if !c.startedAt.IsZero() {
res.CoveredSec = min(window, int(now.Sub(c.startedAt).Seconds()))
}
touches := func(id string) bool { return namespaces[c.endpoints[id].Namespace] }
type acc struct {
tuples map[uint64]uint8
last int64
}
merged := map[edgeKey]*acc{}
for _, b := range c.buckets {
if b == nil || b.minute < fromMinute {
continue
}
for k, e := range b.edges {
if !touches(k.src) && !touches(k.dst) {
continue
}
a := merged[k]
if a == nil {
a = &acc{tuples: make(map[uint64]uint8, len(e.tuples))}
merged[k] = a
}
for h, fl := range e.tuples {
a.tuples[h] |= fl
}
a.last = max(a.last, e.last)
}
}
eps := map[string]bool{}
for k, a := range merged {
fe := FlowEdge{Source: k.src, Target: k.dst, Port: k.port, Connections: len(a.tuples), Last: time.Unix(a.last, 0).UTC().Format(time.RFC3339)}
for _, fl := range a.tuples {
if fl&tupleSYN != 0 {
fe.New++
}
if fl&tupleDrop != 0 {
fe.Dropped++
}
}
res.Edges = append(res.Edges, fe)
eps[k.src], eps[k.dst] = true, true
}
for id := range eps {
res.Endpoints = append(res.Endpoints, c.endpoints[id])
}
sort.Slice(res.Endpoints, func(i, j int) bool { return res.Endpoints[i].ID < res.Endpoints[j].ID })
sort.Slice(res.Edges, func(i, j int) bool { return res.Edges[i].Connections > res.Edges[j].Connections })
return res
}
func handleFlows(w http.ResponseWriter, r *http.Request) {
namespaces := map[string]bool{}
for _, ns := range strings.Split(r.URL.Query().Get("namespaces"), ",") {
if ns = strings.TrimSpace(ns); ns != "" {
namespaces[ns] = true
}
}
if len(namespaces) == 0 || len(namespaces) > 100 {
http.Error(w, "namespaces: от 1 до 100 через запятую", http.StatusBadRequest)
return
}
window, _ := strconv.Atoi(r.URL.Query().Get("window"))
if window <= 0 {
window = 300
}
window = min(window, bucketCount*60)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(flowsCollector.query(namespaces, window))
}
// flowEndpoint maps a Hubble endpoint to an ID that matches a graph node
// when the peer is one of our workloads. Hubble leaves Endpoint.Workloads
// empty on some flows (typically the half observed on the peer's node), so
// pods are resolved through the informer cache with the graph's own rules,
// and Hubble's workload name is only a fallback for pods already gone.
func flowEndpoint(e *flowpb.Endpoint, names []string, nodeName string) FlowEndpoint {
if e.GetPodName() != "" {
ns := e.GetNamespace()
if p, err := podLister.Pods(ns).Get(e.GetPodName()); err == nil {
if kind, name, _ := podOwner(*p); kind != "" {
return FlowEndpoint{ID: workloadID(ns, kind, name), Label: name, Kind: kind, Namespace: ns}
}
}
for _, wl := range e.GetWorkloads() {
kind, name := strings.ToLower(wl.GetKind()), wl.GetName()
if kind == "job" {
if i := strings.LastIndex(name, "-"); i > 0 && allDigits(name[i+1:]) {
kind, name = "cronjob", name[:i]
}
}
if kind != "" && name != "" {
return FlowEndpoint{ID: workloadID(ns, kind, name), Label: name, Kind: kind, Namespace: ns}
}
}
return FlowEndpoint{ID: "pod/" + ns + "/" + e.GetPodName(), Label: e.GetPodName(), Kind: "pod", Namespace: ns}
}
labels := e.GetLabels()
has := func(l string) bool {
for _, x := range labels {
if x == l {
return true
}
}
return false
}
switch {
case has("reserved:host"):
return FlowEndpoint{ID: "ext/host/" + nodeName, Label: "host " + nodeName, Kind: "external"}
case has("reserved:remote-node"):
return FlowEndpoint{ID: "ext/remote-node", Label: "другие ноды", Kind: "external"}
case has("reserved:kube-apiserver"):
return FlowEndpoint{ID: "ext/kube-apiserver", Label: "kube-apiserver", Kind: "external"}
case has("reserved:health"):
return FlowEndpoint{ID: "ext/health", Label: "cilium health", Kind: "external"}
}
if len(names) > 0 {
return FlowEndpoint{ID: "ext/dns/" + names[0], Label: names[0], Kind: "external"}
}
return FlowEndpoint{ID: "ext/world", Label: "интернет", Kind: "external"}
}
+33
View File
@@ -0,0 +1,33 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
extauth "github.com/deckhouse/module-sdk/common-hooks/external_auth"
)
// With user-authn enabled and no externalAuthentication in the ModuleConfig,
// the module deploys its own DexAuthenticator and points the Ingress at it.
// Anything the user sets explicitly wins.
var _ = extauth.RegisterHook(extauth.Settings{
ExternalAuthPath: "clusterMap.auth.externalAuthentication",
DexAuthenticatorEnabledPath: "clusterMap.internal.deployDexAuthenticator",
DexExternalAuth: extauth.ExternalAuth{
AuthURL: "https://cluster-map-dex-authenticator.d8-cluster-map.svc.%CLUSTER_DOMAIN%/dex-authenticator/auth",
AuthSignInURL: "https://$host/dex-authenticator/sign_in",
},
})
+109
View File
@@ -0,0 +1,109 @@
module hook
go 1.25.8
require (
github.com/deckhouse/module-sdk v0.12.5
github.com/stretchr/testify v1.12.1
)
require (
github.com/DataDog/gostackparse v0.7.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/caarlos0/env/v11 v11.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudflare/cfssl v1.6.5 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.18.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckhouse/deckhouse/pkg/log v0.2.0 // indirect
github.com/docker/cli v29.4.0+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.3 // indirect
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
github.com/ettle/strcase v0.2.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.23.1 // indirect
github.com/go-openapi/jsonreference v0.21.6 // indirect
github.com/go-openapi/swag v0.25.5 // indirect
github.com/go-openapi/swag/cmdutils v0.25.5 // indirect
github.com/go-openapi/swag/conv v0.25.5 // indirect
github.com/go-openapi/swag/fileutils v0.25.5 // indirect
github.com/go-openapi/swag/jsonname v0.26.0 // indirect
github.com/go-openapi/swag/jsonutils v0.25.5 // indirect
github.com/go-openapi/swag/loading v0.25.5 // indirect
github.com/go-openapi/swag/mangling v0.25.5 // indirect
github.com/go-openapi/swag/netutils v0.25.5 // indirect
github.com/go-openapi/swag/stringutils v0.25.5 // indirect
github.com/go-openapi/swag/typeutils v0.25.5 // indirect
github.com/go-openapi/swag/yamlutils v0.25.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gojuno/minimock/v3 v3.4.7 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/certificate-transparency-go v1.3.2 // indirect
github.com/google/gnostic-models v0.7.1 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-containerregistry v0.21.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/gojq v0.12.17 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.5 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.4 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/sylabs/oci-tools v0.19.0 // indirect
github.com/tidwall/gjson v1.19.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/vbatts/tar-split v0.12.2 // indirect
github.com/weppos/publicsuffix-go v0.30.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300 // indirect
github.com/zmap/zlint/v3 v3.5.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/net v0.58.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/term v0.45.0 // indirect
golang.org/x/text v0.41.0 // indirect
golang.org/x/time v0.11.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.34.8 // indirect
k8s.io/apiextensions-apiserver v0.34.8 // indirect
k8s.io/apimachinery v0.34.8 // indirect
k8s.io/client-go v0.34.8 // indirect
k8s.io/klog/v2 v2.140.0 // indirect
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25 // indirect
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 // indirect
sigs.k8s.io/controller-runtime v0.22.5 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
+363
View File
@@ -0,0 +1,363 @@
github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/IGQh4=
github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/caarlos0/env/v11 v11.4.1 h1:fYwH0sWEsBSMPG7t4e/PEfTFzrWrpjyygXyUnWiSwEw=
github.com/caarlos0/env/v11 v11.4.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/cfssl v1.6.5 h1:46zpNkm6dlNkMZH/wMW22ejih6gIaJbzL2du6vD7ZeI=
github.com/cloudflare/cfssl v1.6.5/go.mod h1:Bk1si7sq8h2+yVEDrFJiz3d7Aw+pfjjJSZVaD+Taky4=
github.com/containerd/stargz-snapshotter/estargz v0.18.2 h1:yXkZFYIzz3eoLwlTUZKz2iQ4MrckBxJjkmD16ynUTrw=
github.com/containerd/stargz-snapshotter/estargz v0.18.2/go.mod h1:XyVU5tcJ3PRpkA9XS2T5us6Eg35yM0214Y+wvrZTBrY=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckhouse/deckhouse/pkg/log v0.2.0 h1:6tmZQLwNb1o/hP1gzJQBjcwfA/bubbgObovXzxq+Exo=
github.com/deckhouse/deckhouse/pkg/log v0.2.0/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw=
github.com/deckhouse/module-sdk v0.12.5 h1:701OR/GXVDMkJ/85mGdcDS5o3RY2D1l22bJGUCKbEL0=
github.com/deckhouse/module-sdk v0.12.5/go.mod h1:X+o+eFGsfApWJ3n6SqaAw/9Oifrhy2djeG4Inq8umaw=
github.com/docker/cli v29.4.0+incompatible h1:+IjXULMetlvWJiuSI0Nbor36lcJ5BTcVpUmB21KBoVM=
github.com/docker/cli v29.4.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8=
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes=
github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls=
github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78=
github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
github.com/go-openapi/jsonpointer v0.23.1 h1:1HBACs7XIwR2RcmItfdSFlALhGbe6S92p0ry4d1GWg4=
github.com/go-openapi/jsonpointer v0.23.1/go.mod h1:iWRmZTrGn7XwYhtPt/fvdSFj1OfNBngqRT2UG3BxSqY=
github.com/go-openapi/jsonreference v0.21.6 h1:NZ5nGfnaM1n4I43Xjm1e5/M2GjOwQwndQz22uhxwD+Y=
github.com/go-openapi/jsonreference v0.21.6/go.mod h1:xzbgtQ3ZbWxvET3AxdzCJlJt6vkovbf+IfSPJjD0tUY=
github.com/go-openapi/swag v0.25.5 h1:pNkwbUEeGwMtcgxDr+2GBPAk4kT+kJ+AaB+TMKAg+TU=
github.com/go-openapi/swag v0.25.5/go.mod h1:B3RT6l8q7X803JRxa2e59tHOiZlX1t8viplOcs9CwTA=
github.com/go-openapi/swag/cmdutils v0.25.5 h1:yh5hHrpgsw4NwM9KAEtaDTXILYzdXh/I8Whhx9hKj7c=
github.com/go-openapi/swag/cmdutils v0.25.5/go.mod h1:pdae/AFo6WxLl5L0rq87eRzVPm/XRHM3MoYgRMvG4A0=
github.com/go-openapi/swag/conv v0.25.5 h1:wAXBYEXJjoKwE5+vc9YHhpQOFj2JYBMF2DUi+tGu97g=
github.com/go-openapi/swag/conv v0.25.5/go.mod h1:CuJ1eWvh1c4ORKx7unQnFGyvBbNlRKbnRyAvDvzWA4k=
github.com/go-openapi/swag/fileutils v0.25.5 h1:B6JTdOcs2c0dBIs9HnkyTW+5gC+8NIhVBUwERkFhMWk=
github.com/go-openapi/swag/fileutils v0.25.5/go.mod h1:V3cT9UdMQIaH4WiTrUc9EPtVA4txS0TOmRURmhGF4kc=
github.com/go-openapi/swag/jsonname v0.26.0 h1:gV1NFX9M8avo0YSpmWogqfQISigCmpaiNci8cGECU5w=
github.com/go-openapi/swag/jsonname v0.26.0/go.mod h1:urBBR8bZNoDYGr653ynhIx+gTeIz0ARZxHkAPktJK2M=
github.com/go-openapi/swag/jsonutils v0.25.5 h1:XUZF8awQr75MXeC+/iaw5usY/iM7nXPDwdG3Jbl9vYo=
github.com/go-openapi/swag/jsonutils v0.25.5/go.mod h1:48FXUaz8YsDAA9s5AnaUvAmry1UcLcNVWUjY42XkrN4=
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.5 h1:SX6sE4FrGb4sEnnxbFL/25yZBb5Hcg1inLeErd86Y1U=
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.5/go.mod h1:/2KvOTrKWjVA5Xli3DZWdMCZDzz3uV/T7bXwrKWPquo=
github.com/go-openapi/swag/loading v0.25.5 h1:odQ/umlIZ1ZVRteI6ckSrvP6e2w9UTF5qgNdemJHjuU=
github.com/go-openapi/swag/loading v0.25.5/go.mod h1:I8A8RaaQ4DApxhPSWLNYWh9NvmX2YKMoB9nwvv6oW6g=
github.com/go-openapi/swag/mangling v0.25.5 h1:hyrnvbQRS7vKePQPHHDso+k6CGn5ZBs5232UqWZmJZw=
github.com/go-openapi/swag/mangling v0.25.5/go.mod h1:6hadXM/o312N/h98RwByLg088U61TPGiltQn71Iw0NY=
github.com/go-openapi/swag/netutils v0.25.5 h1:LZq2Xc2QI8+7838elRAaPCeqJnHODfSyOa7ZGfxDKlU=
github.com/go-openapi/swag/netutils v0.25.5/go.mod h1:lHbtmj4m57APG/8H7ZcMMSWzNqIQcu0RFiXrPUara14=
github.com/go-openapi/swag/stringutils v0.25.5 h1:NVkoDOA8YBgtAR/zvCx5rhJKtZF3IzXcDdwOsYzrB6M=
github.com/go-openapi/swag/stringutils v0.25.5/go.mod h1:PKK8EZdu4QJq8iezt17HM8RXnLAzY7gW0O1KKarrZII=
github.com/go-openapi/swag/typeutils v0.25.5 h1:EFJ+PCga2HfHGdo8s8VJXEVbeXRCYwzzr9u4rJk7L7E=
github.com/go-openapi/swag/typeutils v0.25.5/go.mod h1:itmFmScAYE1bSD8C4rS0W+0InZUBrB2xSPbWt6DLGuc=
github.com/go-openapi/swag/yamlutils v0.25.5 h1:kASCIS+oIeoc55j28T4o8KwlV2S4ZLPT6G0iq2SSbVQ=
github.com/go-openapi/swag/yamlutils v0.25.5/go.mod h1:Gek1/SjjfbYvM+Iq4QGwa/2lEXde9n2j4a3wI3pNuOQ=
github.com/go-openapi/testify/enable/yaml/v2 v2.4.0 h1:7SgOMTvJkM8yWrQlU8Jm18VeDPuAvB/xWrdxFJkoFag=
github.com/go-openapi/testify/enable/yaml/v2 v2.4.0/go.mod h1:14iV8jyyQlinc9StD7w1xVPW3CO3q1Gj04Jy//Kw4VM=
github.com/go-openapi/testify/v2 v2.5.1 h1:TMdhCaw8fUNraVSf3Omoob1dO/AzBfhtFAPW0an6sBo=
github.com/go-openapi/testify/v2 v2.5.1/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/gojuno/minimock/v3 v3.4.7 h1:vhE5zpniyPDRT0DXd5s3DbtZJVlcbmC5k80izYtj9lY=
github.com/gojuno/minimock/v3 v3.4.7/go.mod h1:QxJk4mdPrVyYUmEZGc2yD2NONpqM/j4dWhsy9twjFHg=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/google/certificate-transparency-go v1.3.2 h1:9ahSNZF2o7SYMaKaXhAumVEzXB2QaayzII9C8rv7v+A=
github.com/google/certificate-transparency-go v1.3.2/go.mod h1:H5FpMUaGa5Ab2+KCYsxg6sELw3Flkl7pGZzWdBoYLXs=
github.com/google/gnostic-models v0.7.1 h1:SisTfuFKJSKM5CPZkffwi6coztzzeYUhc3v4yxLWH8c=
github.com/google/gnostic-models v0.7.1/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-containerregistry v0.21.3 h1:Xr+yt3VvwOOn/5nJzd7UoOhwPGiPkYW0zWDLLUXqAi4=
github.com/google/go-containerregistry v0.21.3/go.mod h1:D5ZrJF1e6dMzvInpBPuMCX0FxURz7GLq2rV3Us9aPkc=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo=
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/itchyny/gojq v0.12.17 h1:8av8eGduDb5+rvEdaOO+zQUjA04MS0m3Ps8HiD+fceg=
github.com/itchyny/gojq v0.12.17/go.mod h1:WBrEMkgAfAGO1LUcGOckBl5O726KPp+OlkKug0I/FEY=
github.com/itchyny/timefmt-go v0.1.6 h1:ia3s54iciXDdzWzwaVKXZPbiXzxxnv1SPGFfM/myJ5Q=
github.com/itchyny/timefmt-go v0.1.6/go.mod h1:RRDZYC5s9ErkjQvTvvU7keJjxUYzIISJGxm9/mAERQg=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=
github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8=
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474/go.mod h1:OQA4XLvDbMgS8P0CevmM4m9Q3Jq4phKUzcocxuGJ5m8=
github.com/mreiferson/go-httpclient v0.0.0-20201222173833-5e475fde3a4d/go.mod h1:OQA4XLvDbMgS8P0CevmM4m9Q3Jq4phKUzcocxuGJ5m8=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg=
github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw=
github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sebdah/goldie/v2 v2.8.0 h1:dZb9wR8q5++oplmEiJT+U/5KyotVD+HNGCAc5gNr8rc=
github.com/sebdah/goldie/v2 v2.8.0/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/sylabs/oci-tools v0.19.0 h1:7Dr+CjL2Xl/VzILxdPBhLQif84+W4QJ7XHltyyOf24E=
github.com/sylabs/oci-tools v0.19.0/go.mod h1:ZiYPGZHUshGkzXtE3pEuWSUqBLJNH4Q2eDxE/1OhMyc=
github.com/sylabs/sif/v2 v2.23.0 h1:VWJC7iryINdIgyIK8EdxMCJkx8EDPVlvFaskgY+ruFk=
github.com/sylabs/sif/v2 v2.23.0/go.mod h1:0UJk7MMSQS2n/95yYd+CvAfK7K2mE0aWHRYYybd+ouw=
github.com/tidwall/gjson v1.19.0 h1:xwxm7n691Uf3u5OFjzngavjGTh55KX5q/9w9xHW88JU=
github.com/tidwall/gjson v1.19.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4=
github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA=
github.com/weppos/publicsuffix-go v0.12.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/weppos/publicsuffix-go v0.13.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/weppos/publicsuffix-go v0.30.0 h1:QHPZ2GRu/YE7cvejH9iyavPOkVCB4dNxp2ZvtT+vQLY=
github.com/weppos/publicsuffix-go v0.30.0/go.mod h1:kBi8zwYnR0zrbm8RcuN1o9Fzgpnnn+btVN8uWPMyXAY=
github.com/weppos/publicsuffix-go/publicsuffix/generator v0.0.0-20220927085643-dc0d00c92642/go.mod h1:GHfoeIdZLdZmLjMlzBftbTDntahTttUMWjxZwQJhULE=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zmap/rc2 v0.0.0-20131011165748-24b9757f5521/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE=
github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248/go.mod h1:3YZ9o3WnatTIZhuOtot4IcUfzoKVjUHqu6WALIyI0nE=
github.com/zmap/zcertificate v0.0.0-20180516150559-0e3d58b1bac4/go.mod h1:5iU54tB79AMBcySS0R2XIyZBAVmeHranShAFELYx7is=
github.com/zmap/zcertificate v0.0.1/go.mod h1:q0dlN54Jm4NVSSuzisusQY0hqDWvu92C+TWveAxiVWk=
github.com/zmap/zcrypto v0.0.0-20201128221613-3719af1573cf/go.mod h1:aPM7r+JOkfL+9qSB4KbYjtoEzJqUK50EXkkJabeNJDQ=
github.com/zmap/zcrypto v0.0.0-20201211161100-e54a5822fb7e/go.mod h1:aPM7r+JOkfL+9qSB4KbYjtoEzJqUK50EXkkJabeNJDQ=
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300 h1:DZH5n7L3L8RxKdSyJHZt7WePgwdhHnPhQFdQSJaHF+o=
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300/go.mod h1:mOd4yUMgn2fe2nV9KXsa9AyQBFZGzygVPovsZR+Rl5w=
github.com/zmap/zlint/v3 v3.0.0/go.mod h1:paGwFySdHIBEMJ61YjoqT4h7Ge+fdYG4sUQhnTb1lJ8=
github.com/zmap/zlint/v3 v3.5.0 h1:Eh2B5t6VKgVH0DFmTwOqE50POvyDhUaU9T2mJOe1vfQ=
github.com/zmap/zlint/v3 v3.5.0/go.mod h1:JkNSrsDJ8F4VRtBZcYUQSvnWFL7utcjDIn+FE64mlBI=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0=
golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
k8s.io/api v0.34.8 h1:PATray7Ixf5fzuvW6WTrLGqWpaeSUlV3NqygBu10YC0=
k8s.io/api v0.34.8/go.mod h1:kkv5KLONEBxemk51GDsqR0TaBig60bVriYyDj9v3gg8=
k8s.io/apiextensions-apiserver v0.34.8 h1:iovXsJk6GKQdgEQFpeTJcFHGVGx576gyAA3StSkwNk0=
k8s.io/apiextensions-apiserver v0.34.8/go.mod h1:hmkveoSZ3WH4HBMc/FcraqfPbASAZ/TbAfaHFfiEvlY=
k8s.io/apimachinery v0.34.8 h1:Vjyd/TdakksL0g7ikxyaAk3s3qgqRRYz9vj0AudwNzc=
k8s.io/apimachinery v0.34.8/go.mod h1:z7dd12Xd400CXIycE8nmn32xZhApV9zskHs0A5xeU/Q=
k8s.io/client-go v0.34.8 h1:/4Ar6TX6V/vwhFQDeTMySO0+OBbslk7inkEdOQdR66A=
k8s.io/client-go v0.34.8/go.mod h1:VVLUD4GP16X+ePPZ3YpCyxn1rhaf1lczr/HCI0e40h8=
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25 h1:mPMaPMpBij2V1Wv/fR+HW124vVGXXvOSS9ver/9yjWs=
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25/go.mod h1:V/QaCUYDa+0QpcHhVVc5l99Uz56wEMEXBSj9oCDkNDY=
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 h1:wU4tMEhLGgIbLvXQb1cfN+EcM0wf7zC6CPF+C79jroc=
k8s.io/utils v0.0.0-20260507154919-ff6756f316d2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
sigs.k8s.io/controller-runtime v0.22.5 h1:v3nfSUMowX/2WMp27J9slwGFyAt7IV0YwBxAkrUr0GE=
sigs.k8s.io/controller-runtime v0.22.5/go.mod h1:pc5SoYWnWI6I+cBHYYdZ7B6YHZVY5xNfll88JB+vniI=
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 h1:kwVWMx5yS1CrnFWA/2QHyRVJ8jM6dBA80uLmm0wJkk8=
sigs.k8s.io/structured-merge-diff/v6 v6.3.2/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
@@ -0,0 +1,25 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package https registers the common hook that copies a CustomCertificate
// secret from d8-system into the module values.
package https
import (
copycustomcertificate "github.com/deckhouse/module-sdk/common-hooks/copy-custom-certificate"
)
var _ = copycustomcertificate.RegisterHook("clusterMap")
+72
View File
@@ -0,0 +1,72 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
"encoding/base64"
"fmt"
"github.com/deckhouse/module-sdk/pkg"
objectpatch "github.com/deckhouse/module-sdk/pkg/object-patch"
"github.com/deckhouse/module-sdk/pkg/registry"
)
const (
hubbleCASnapshot = "hubble_ca"
hubbleCAValuePath = "clusterMap.internal.hubbleCA"
)
// hubbleCAConfig watches the hubble CA secret of the cilium-hubble module.
// The jq filter keeps only the public certificate: the CA key never
// reaches the module's values.
var hubbleCAConfig = &pkg.HookConfig{
OnBeforeHelm: &pkg.OrderedConfig{Order: 10},
Kubernetes: []pkg.KubernetesConfig{{
Name: hubbleCASnapshot,
APIVersion: "v1",
Kind: "Secret",
NameSelector: &pkg.NameSelector{
MatchNames: []string{"hubble-ca-secret"},
},
NamespaceSelector: &pkg.NamespaceSelector{
NameSelector: &pkg.NameSelector{MatchNames: []string{"d8-cni-cilium"}},
},
JqFilter: `.data."ca.crt" // ""`,
}},
}
var _ = registry.RegisterFunc(hubbleCAConfig, handleHubbleCA)
// handleHubbleCA publishes the CA for the Deployment, or an empty string
// when cilium-hubble is not installed, which turns traffic off.
func handleHubbleCA(_ context.Context, input *pkg.HookInput) error {
certs, err := objectpatch.UnmarshalToStruct[string](input.Snapshots, hubbleCASnapshot)
if err != nil {
return fmt.Errorf("read %s snapshot: %w", hubbleCASnapshot, err)
}
if len(certs) == 0 || certs[0] == "" {
input.Values.Set(hubbleCAValuePath, "")
return nil
}
pem, err := base64.StdEncoding.DecodeString(certs[0])
if err != nil {
return fmt.Errorf("decode hubble CA: %w", err)
}
input.Values.Set(hubbleCAValuePath, string(pem))
return nil
}
+55
View File
@@ -0,0 +1,55 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/deckhouse/module-sdk/testing/framework"
)
const initValues = `{"clusterMap": {"internal": {}}}`
func TestHubbleCAIsCopiedWithoutKey(t *testing.T) {
hec := framework.HookExecutionConfigInit(t, hubbleCAConfig, handleHubbleCA, initValues, `{}`)
hec.KubeStateSet(`
---
apiVersion: v1
kind: Secret
metadata:
name: hubble-ca-secret
namespace: d8-cni-cilium
data:
ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCg==
ca.key: bm90LWZvci11cw==
`)
hec.RunHook()
require.NoError(t, hec.HookError())
require.Equal(t, "-----BEGIN CERTIFICATE-----\n", hec.ValuesGet("clusterMap.internal.hubbleCA").String())
require.NotContains(t, hec.ValuesGet("clusterMap").Raw, "not-for-us")
}
func TestNoHubbleMeansEmptyCA(t *testing.T) {
hec := framework.HookExecutionConfigInit(t, hubbleCAConfig, handleHubbleCA, initValues, `{}`)
hec.KubeStateSet(``)
hec.RunHook()
require.NoError(t, hec.HookError())
require.True(t, hec.ValuesGet("clusterMap.internal.hubbleCA").Exists())
require.Equal(t, "", hec.ValuesGet("clusterMap.internal.hubbleCA").String())
}
+28
View File
@@ -0,0 +1,28 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Command batchhooks is the cluster-map module's hook binary (module-sdk).
package main
import (
_ "hook/https"
"github.com/deckhouse/module-sdk/pkg/app"
)
func main() {
app.Run()
}
+23
View File
@@ -0,0 +1,23 @@
version: "2"
linters:
default: standard
enable:
- bodyclose
- errorlint
- gocritic
- gosec
- misspell
- nilerr
- revive
- unconvert
settings:
gosec:
excludes:
- G104 # unchecked errors on http.ResponseWriter writes: nothing useful to do with them
exclusions:
presets:
- std-error-handling
formatters:
enable:
- gofmt
- goimports
@@ -0,0 +1,148 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Command cluster-map serves a topology map of a Kubernetes cluster with
// live traffic from Cilium Hubble.
package main
import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"
observerpb "github.com/cilium/cilium/api/v1/observer"
"github.com/prometheus/client_golang/prometheus/promhttp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"git.project-chimera.ru/fanchji/cluster-map/internal/config"
"git.project-chimera.ru/fanchji/cluster-map/internal/kube"
"git.project-chimera.ru/fanchji/cluster-map/internal/metrics"
"git.project-chimera.ru/fanchji/cluster-map/internal/server"
"git.project-chimera.ru/fanchji/cluster-map/internal/topology"
"git.project-chimera.ru/fanchji/cluster-map/internal/traffic"
"git.project-chimera.ru/fanchji/cluster-map/web"
)
func main() {
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil)))
if err := run(); err != nil {
slog.Error("exiting", "err", err)
os.Exit(1)
}
}
func run() error {
cfg, err := config.Load()
if err != nil {
return err
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer stop()
srv := server.New(cfg, web.Static())
api := &http.Server{Addr: cfg.ListenAddr, Handler: srv.Handler(), ReadHeaderTimeout: 10 * time.Second}
metricsSrv := &http.Server{Addr: cfg.MetricsAddr, Handler: promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{}), ReadHeaderTimeout: 10 * time.Second}
errc := make(chan error, 2)
for _, s := range []*http.Server{api, metricsSrv} {
go func() {
if err := s.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
errc <- err
}
}()
}
slog.Info("listening", "api", cfg.ListenAddr, "metrics", cfg.MetricsAddr, "traffic", cfg.TrafficMode)
restCfg, err := rest.InClusterConfig()
if err != nil {
return fmt.Errorf("in-cluster config: %w", err)
}
client, err := kubernetes.NewForConfig(restCfg)
if err != nil {
return err
}
cache, err := kube.Start(ctx, client, 2*time.Minute)
if err != nil {
return err
}
metrics.CacheSynced.Set(1)
obs, err := hubbleClient(cfg)
if err != nil && cfg.TrafficMode != config.TrafficDisabled {
slog.Error("traffic disabled: cannot set up the Hubble client", "err", err)
}
collector := traffic.NewCollector(cfg, obs, podResolver(cache))
go collector.Run(ctx)
srv.SetReady(cache, collector)
slog.Info("ready")
select {
case <-ctx.Done():
case err := <-errc:
return err
}
slog.Info("shutting down")
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
return errors.Join(api.Shutdown(shutdownCtx), metricsSrv.Shutdown(shutdownCtx))
}
// hubbleClient connects to Hubble Relay over TLS. Relay presents a
// *.hubble-relay.cilium.io certificate signed by the cluster's hubble CA
// and does not ask for a client certificate, so only the CA is needed.
func hubbleClient(cfg config.Config) (observerpb.ObserverClient, error) {
if cfg.TrafficMode == config.TrafficDisabled {
return nil, nil
}
caPEM, err := os.ReadFile(cfg.HubbleCAFile)
if err != nil {
return nil, fmt.Errorf("hubble CA: %w", err)
}
pool := x509.NewCertPool()
if !pool.AppendCertsFromPEM(caPEM) {
return nil, errors.New("hubble CA: no certificate in " + cfg.HubbleCAFile)
}
creds := credentials.NewTLS(&tls.Config{RootCAs: pool, ServerName: cfg.HubbleServerName, MinVersion: tls.VersionTLS12})
conn, err := grpc.NewClient(cfg.HubbleRelayAddr, grpc.WithTransportCredentials(creds))
if err != nil {
return nil, err
}
return observerpb.NewObserverClient(conn), nil
}
func podResolver(c *kube.Cache) traffic.PodResolver {
return func(ns, name string) (traffic.Endpoint, bool) {
p, err := c.Pods.Pods(ns).Get(name)
if err != nil {
return traffic.Endpoint{}, false
}
kind, owner, _ := topology.PodOwner(*p)
if kind == "" {
return traffic.Endpoint{}, false
}
return traffic.Endpoint{ID: topology.WorkloadID(ns, kind, owner), Label: owner, Kind: kind, Namespace: ns}, true
}
}
+6
View File
@@ -4,6 +4,7 @@ go 1.25.0
require (
github.com/cilium/cilium v1.17.4
github.com/prometheus/client_golang v1.24.1
google.golang.org/grpc v1.84.0
google.golang.org/protobuf v1.36.11
k8s.io/api v0.32.0
@@ -13,6 +14,8 @@ require (
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
@@ -33,6 +36,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.70.1 // indirect
github.com/prometheus/procfs v0.21.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
+22 -2
View File
@@ -1,3 +1,7 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cilium/cilium v1.17.4 h1:fO1VBbBLU69wbhN2csULVLPs7gR3qr0IrnYmI2SwU40=
github.com/cilium/cilium v1.17.4/go.mod h1:wVAXueJW11HUvZo0c+szVo7zeCLZ5yOCgNHP0lwiS8g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -40,10 +44,14 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -63,18 +71,30 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU=
github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.70.1 h1:1HvjP4D5oL3t8RsPlwxA9onvvStjtIHYE5XuuwOi/PY=
github.com/prometheus/common v0.70.1/go.mod h1:VdFUQDMZK3VLkurFUVhia6uys/0suUp86TJz5qbJRhc=
github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI=
github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -0,0 +1,132 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package config reads cluster-map settings from the environment. The
// module's Helm templates are the only intended writer of these variables.
package config
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
// TrafficMode selects when cluster-map reads flows from Hubble.
type TrafficMode string
const (
// TrafficContinuous keeps a Hubble follow stream open all the time, so
// every traffic window is full as soon as someone opens the map.
TrafficContinuous TrafficMode = "Continuous"
// TrafficOnDemand opens the stream on the first traffic request and
// closes it after OnDemandIdle without requests: near-zero cost when
// nobody looks, but windows only fill while the map is in use.
TrafficOnDemand TrafficMode = "OnDemand"
// TrafficDisabled never talks to Hubble; the map shows configuration only.
TrafficDisabled TrafficMode = "Disabled"
)
// Config is the full runtime configuration.
type Config struct {
ListenAddr string
MetricsAddr string
TrafficMode TrafficMode
Retention time.Duration // how far back traffic windows can reach
OnDemandIdle time.Duration
CollectInfra bool // keep kubelet probes, DNS, health, node-to-node
HubbleRelayAddr string
HubbleCAFile string
HubbleServerName string
// Namespaces matching these prefixes/names are grouped as "system".
SystemNamespacePrefixes []string
LogTailLines int64
}
// Load reads and validates the configuration from the environment.
func Load() (Config, error) {
c := Config{
ListenAddr: env("LISTEN_ADDR", ":8080"),
MetricsAddr: env("METRICS_ADDR", ":9090"),
TrafficMode: TrafficMode(env("TRAFFIC_MODE", string(TrafficContinuous))),
HubbleRelayAddr: env("HUBBLE_RELAY_ADDR", "hubble-relay.d8-cni-cilium.svc:443"),
HubbleCAFile: env("HUBBLE_CA_FILE", "/etc/hubble-ca/ca.crt"),
HubbleServerName: env("HUBBLE_SERVER_NAME", "cluster-map.hubble-relay.cilium.io"),
SystemNamespacePrefixes: split(env("SYSTEM_NAMESPACE_PREFIXES", "d8-,kube-")),
}
var err error
if c.Retention, err = duration("TRAFFIC_RETENTION", "60m"); err != nil {
return c, err
}
if c.OnDemandIdle, err = duration("TRAFFIC_ON_DEMAND_IDLE", "10m"); err != nil {
return c, err
}
if c.CollectInfra, err = strconv.ParseBool(env("TRAFFIC_COLLECT_INFRA", "false")); err != nil {
return c, fmt.Errorf("TRAFFIC_COLLECT_INFRA: %w", err)
}
if c.LogTailLines, err = strconv.ParseInt(env("LOG_TAIL_LINES", "500"), 10, 64); err != nil {
return c, fmt.Errorf("LOG_TAIL_LINES: %w", err)
}
switch c.TrafficMode {
case TrafficContinuous, TrafficOnDemand, TrafficDisabled:
default:
return c, fmt.Errorf("TRAFFIC_MODE: %q is not one of Continuous, OnDemand, Disabled", c.TrafficMode)
}
if c.Retention < time.Minute || c.Retention > 24*time.Hour {
return c, fmt.Errorf("TRAFFIC_RETENTION: %s is outside 1m..24h", c.Retention)
}
return c, nil
}
// IsSystemNamespace reports whether ns is platform-owned rather than an
// application namespace. A prefix ending in "-" matches by prefix, anything
// else matches the whole name.
func (c Config) IsSystemNamespace(ns string) bool {
for _, p := range c.SystemNamespacePrefixes {
if (strings.HasSuffix(p, "-") && strings.HasPrefix(ns, p)) || ns == p {
return true
}
}
return false
}
func env(k, def string) string {
if v, ok := os.LookupEnv(k); ok && v != "" {
return v
}
return def
}
func duration(k, def string) (time.Duration, error) {
d, err := time.ParseDuration(env(k, def))
if err != nil {
return 0, fmt.Errorf("%s: %w", k, err)
}
return d, nil
}
func split(s string) []string {
var out []string
for _, p := range strings.Split(s, ",") {
if p = strings.TrimSpace(p); p != "" {
out = append(out, p)
}
}
return out
}
@@ -0,0 +1,59 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"testing"
"time"
)
func TestDefaults(t *testing.T) {
c, err := Load()
if err != nil {
t.Fatal(err)
}
if c.TrafficMode != TrafficContinuous || c.Retention != time.Hour || c.CollectInfra {
t.Errorf("defaults: %+v", c)
}
}
func TestValidation(t *testing.T) {
for k, v := range map[string]string{
"TRAFFIC_MODE": "Sometimes",
"TRAFFIC_RETENTION": "30s",
"TRAFFIC_COLLECT_INFRA": "maybe",
} {
t.Run(k, func(t *testing.T) {
t.Setenv(k, v)
if _, err := Load(); err == nil {
t.Errorf("%s=%s should be rejected", k, v)
}
})
}
}
func TestIsSystemNamespace(t *testing.T) {
c := Config{SystemNamespacePrefixes: []string{"d8-", "kube-", "monitoring"}}
for ns, want := range map[string]bool{
"d8-system": true, "kube-system": true, "monitoring": true,
"monitoring-extra": false, "shop": false, "d8": false,
} {
if got := c.IsSystemNamespace(ns); got != want {
t.Errorf("%s: got %v want %v", ns, got, want)
}
}
}
@@ -0,0 +1,100 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package kube holds the informer-backed read-only view of the cluster
// that the graph and the traffic resolver read from.
package kube
import (
"context"
"fmt"
"time"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
appslisters "k8s.io/client-go/listers/apps/v1"
batchlisters "k8s.io/client-go/listers/batch/v1"
corelisters "k8s.io/client-go/listers/core/v1"
netlisters "k8s.io/client-go/listers/networking/v1"
)
// Cache holds synced listers plus a client for reads that must be live
// (YAML view, logs).
type Cache struct {
Client kubernetes.Interface
Namespaces corelisters.NamespaceLister
Pods corelisters.PodLister
Services corelisters.ServiceLister
Nodes corelisters.NodeLister
Deployments appslisters.DeploymentLister
StatefulSets appslisters.StatefulSetLister
DaemonSets appslisters.DaemonSetLister
CronJobs batchlisters.CronJobLister
Ingresses netlisters.IngressLister
}
// Start runs the informers and blocks until every cache has synced or ctx
// is done.
func Start(ctx context.Context, client kubernetes.Interface, syncTimeout time.Duration) (*Cache, error) {
f := informers.NewSharedInformerFactoryWithOptions(client, 0,
// managedFields is most of a cached object's size and nothing here reads it
informers.WithTransform(func(obj any) (any, error) {
if a, err := meta.Accessor(obj); err == nil {
a.SetManagedFields(nil)
}
return obj, nil
}))
c := &Cache{
Client: client,
Namespaces: f.Core().V1().Namespaces().Lister(),
Pods: f.Core().V1().Pods().Lister(),
Services: f.Core().V1().Services().Lister(),
Nodes: f.Core().V1().Nodes().Lister(),
Deployments: f.Apps().V1().Deployments().Lister(),
StatefulSets: f.Apps().V1().StatefulSets().Lister(),
DaemonSets: f.Apps().V1().DaemonSets().Lister(),
CronJobs: f.Batch().V1().CronJobs().Lister(),
Ingresses: f.Networking().V1().Ingresses().Lister(),
}
f.Start(ctx.Done())
syncCtx, cancel := context.WithTimeout(ctx, syncTimeout)
defer cancel()
for t, ok := range f.WaitForCacheSync(syncCtx.Done()) {
if !ok {
return nil, fmt.Errorf("cache for %v did not sync within %s", t, syncTimeout)
}
}
return c, nil
}
// List reads a lister as values. Callers must not mutate cached objects,
// and copying the top-level struct is cheap.
func List[T any](l interface {
List(labels.Selector) ([]*T, error)
}) ([]T, error) {
ptrs, err := l.List(labels.Everything())
if err != nil {
return nil, err
}
out := make([]T, len(ptrs))
for i, p := range ptrs {
out[i] = *p
}
return out, nil
}
@@ -0,0 +1,61 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package metrics exposes cluster-map's own Prometheus metrics.
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
)
// Registry holds only cluster-map's metrics plus the Go and process ones.
var Registry = prometheus.NewRegistry()
// Metrics exported on /metrics.
var (
HubbleStreamActive = gauge("cluster_map_hubble_stream_active", "1 while a Hubble follow stream is supposed to be open (always in Continuous mode, while viewed in OnDemand).")
HubbleConnected = gauge("cluster_map_hubble_connected", "1 while flows are arriving from Hubble Relay.")
HubbleReconnects = counter("cluster_map_hubble_reconnects_total", "Hubble streams that ended and were reopened.")
FlowsProcessed = counter("cluster_map_flows_processed_total", "Hubble flows received and aggregated.")
TrackedTuples = gauge("cluster_map_traffic_tracked_tuples", "Distinct connection tuples held across all retained minute buckets.")
CacheSynced = gauge("cluster_map_cache_synced", "1 once the Kubernetes informer caches have synced.")
HTTPRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "cluster_map_http_requests_total", Help: "HTTP API requests by handler and status code.",
}, []string{"handler", "code"})
HTTPDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "cluster_map_http_request_duration_seconds", Help: "HTTP API latency by handler.",
Buckets: []float64{.001, .005, .01, .05, .1, .5, 1, 5},
}, []string{"handler"})
)
func init() {
Registry.MustRegister(
collectors.NewGoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
HubbleStreamActive, HubbleConnected, HubbleReconnects, FlowsProcessed, TrackedTuples, CacheSynced,
HTTPRequests, HTTPDuration,
)
}
func gauge(name, help string) prometheus.Gauge {
return prometheus.NewGauge(prometheus.GaugeOpts{Name: name, Help: help})
}
func counter(name, help string) prometheus.Counter {
return prometheus.NewCounter(prometheus.CounterOpts{Name: name, Help: help})
}
@@ -0,0 +1,271 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package server is the HTTP API and static frontend.
package server
import (
"encoding/json"
"errors"
"io"
"io/fs"
"log/slog"
"net/http"
"sort"
"strconv"
"strings"
"sync/atomic"
"time"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
"git.project-chimera.ru/fanchji/cluster-map/internal/config"
"git.project-chimera.ru/fanchji/cluster-map/internal/kube"
"git.project-chimera.ru/fanchji/cluster-map/internal/metrics"
"git.project-chimera.ru/fanchji/cluster-map/internal/topology"
"git.project-chimera.ru/fanchji/cluster-map/internal/traffic"
)
// Server serves the JSON API and the embedded frontend.
type Server struct {
cfg config.Config
cache *kube.Cache
traffic *traffic.Collector
static fs.FS
ready atomic.Bool
}
// New returns a server that answers 503 on the API until SetReady.
func New(cfg config.Config, static fs.FS) *Server {
return &Server{cfg: cfg, static: static}
}
// SetReady is called once the caches have synced; until then API calls
// and the readiness probe answer 503.
func (s *Server) SetReady(cache *kube.Cache, collector *traffic.Collector) {
s.cache, s.traffic = cache, collector
s.ready.Store(true)
}
// Handler returns the routes wrapped in security headers.
func (s *Server) Handler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) { _, _ = io.WriteString(w, "ok") })
mux.HandleFunc("GET /readyz", func(w http.ResponseWriter, _ *http.Request) {
if !s.ready.Load() {
http.Error(w, "caches not synced", http.StatusServiceUnavailable)
return
}
_, _ = io.WriteString(w, "ok")
})
mux.Handle("GET /api/graph", s.api("graph", s.handleGraph))
mux.Handle("GET /api/flows", s.api("flows", s.handleFlows))
mux.Handle("GET /api/resource", s.api("resource", s.handleResource))
mux.Handle("GET /api/pods", s.api("pods", s.handlePods))
mux.Handle("GET /api/logs", s.api("logs", s.handleLogs))
mux.Handle("GET /", http.FileServerFS(s.static))
return securityHeaders(mux)
}
type statusWriter struct {
http.ResponseWriter
code int
}
func (w *statusWriter) WriteHeader(code int) { w.code = code; w.ResponseWriter.WriteHeader(code) }
// api wraps an API handler with readiness gating and request metrics.
func (s *Server) api(name string, h http.HandlerFunc) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
sw := &statusWriter{ResponseWriter: w, code: http.StatusOK}
if !s.ready.Load() {
http.Error(sw, "caches not synced yet", http.StatusServiceUnavailable)
} else {
h(sw, r)
}
metrics.HTTPRequests.WithLabelValues(name, strconv.Itoa(sw.code)).Inc()
metrics.HTTPDuration.WithLabelValues(name).Observe(time.Since(start).Seconds())
})
}
// securityHeaders: the page loads only its own scripts, styles and images
// (card images are data: SVGs), talks only to its own API, and can't be
// framed.
func securityHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h := w.Header()
h.Set("Content-Security-Policy", "default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; connect-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'")
h.Set("X-Content-Type-Options", "nosniff")
h.Set("Referrer-Policy", "no-referrer")
h.Set("Cache-Control", "no-store")
next.ServeHTTP(w, r)
})
}
func writeJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(v); err != nil {
slog.Debug("writing response", "err", err) // client went away
}
}
func (s *Server) handleGraph(w http.ResponseWriter, _ *http.Request) {
g, err := topology.Build(s.cache, s.cfg.IsSystemNamespace)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
writeJSON(w, g)
}
func (s *Server) handleFlows(w http.ResponseWriter, r *http.Request) {
if s.cfg.TrafficMode == config.TrafficDisabled {
writeJSON(w, traffic.Result{Mode: config.TrafficDisabled})
return
}
namespaces := map[string]bool{}
for _, ns := range strings.Split(r.URL.Query().Get("namespaces"), ",") {
if ns = strings.TrimSpace(ns); ns != "" {
namespaces[ns] = true
}
}
if len(namespaces) == 0 || len(namespaces) > 200 {
http.Error(w, "namespaces: 1 to 200, comma-separated", http.StatusBadRequest)
return
}
window, err := time.ParseDuration(r.URL.Query().Get("window") + "s")
if err != nil || window <= 0 {
window = 5 * time.Minute
}
writeJSON(w, s.traffic.Query(namespaces, window))
}
// handleResource returns the live object as YAML. It reads through the API
// rather than the cache so the view is exactly what the API server holds.
func (s *Server) handleResource(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
kind, ns, name := q.Get("kind"), q.Get("namespace"), q.Get("name")
ctx := r.Context()
c := s.cache.Client
var obj metav1.Object
var err error
switch kind {
case "namespace":
obj, err = c.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
case "deployment":
obj, err = c.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{})
case "statefulset":
obj, err = c.AppsV1().StatefulSets(ns).Get(ctx, name, metav1.GetOptions{})
case "daemonset":
obj, err = c.AppsV1().DaemonSets(ns).Get(ctx, name, metav1.GetOptions{})
case "cronjob":
obj, err = c.BatchV1().CronJobs(ns).Get(ctx, name, metav1.GetOptions{})
case "service":
obj, err = c.CoreV1().Services(ns).Get(ctx, name, metav1.GetOptions{})
case "ingress":
obj, err = c.NetworkingV1().Ingresses(ns).Get(ctx, name, metav1.GetOptions{})
case "node":
obj, err = c.CoreV1().Nodes().Get(ctx, name, metav1.GetOptions{})
case "pod":
obj, err = c.CoreV1().Pods(ns).Get(ctx, name, metav1.GetOptions{})
default:
http.Error(w, "unknown kind", http.StatusBadRequest)
return
}
if err != nil {
http.Error(w, err.Error(), apiStatus(err))
return
}
obj.SetManagedFields(nil)
out, err := yaml.Marshal(obj)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
_, _ = w.Write(out)
}
func apiStatus(err error) int {
var st apierrors.APIStatus
if errors.As(err, &st) && st.Status().Code != 0 {
return int(st.Status().Code)
}
return http.StatusInternalServerError
}
// PodInfo is one pod behind a workload, for the log picker.
type PodInfo struct {
Name string `json:"name"`
NodeName string `json:"nodeName"`
Phase string `json:"phase"`
Containers []string `json:"containers"`
}
// handlePods lists the live pods behind a workload ID, resolved with the
// same owner rules the graph uses.
func (s *Server) handlePods(w http.ResponseWriter, r *http.Request) {
id, ns := r.URL.Query().Get("id"), r.URL.Query().Get("namespace")
if ns == "" || !strings.HasPrefix(id, "wl/"+ns+"/") {
http.Error(w, "namespace and a workload id (wl/<ns>/<kind>/<name>) are required", http.StatusBadRequest)
return
}
pods, err := kube.List[corev1.Pod](s.cache.Pods.Pods(ns))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
out := []PodInfo{}
for _, p := range pods {
if topology.OwnerWorkloadID(p) != id {
continue
}
info := PodInfo{Name: p.Name, NodeName: p.Spec.NodeName, Phase: string(p.Status.Phase)}
for _, c := range p.Spec.Containers {
info.Containers = append(info.Containers, c.Name)
}
out = append(out, info)
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
writeJSON(w, out)
}
// handleLogs returns a container's recent log tail. No follow: this is a
// click-to-inspect view, not a live tail.
func (s *Server) handleLogs(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
ns, pod, container := q.Get("namespace"), q.Get("pod"), q.Get("container")
if ns == "" || pod == "" {
http.Error(w, "namespace and pod are required", http.StatusBadRequest)
return
}
tail := s.cfg.LogTailLines
opts := &corev1.PodLogOptions{TailLines: &tail, Container: container}
stream, err := s.cache.Client.CoreV1().Pods(ns).GetLogs(pod, opts).Stream(r.Context())
if err != nil {
http.Error(w, err.Error(), apiStatus(err))
return
}
defer stream.Close()
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if _, err := io.Copy(w, stream); err != nil {
slog.Debug("streaming logs", "err", err)
}
}
@@ -0,0 +1,108 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package server
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"testing/fstest"
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"git.project-chimera.ru/fanchji/cluster-map/internal/config"
"git.project-chimera.ru/fanchji/cluster-map/internal/kube"
"git.project-chimera.ru/fanchji/cluster-map/internal/traffic"
)
func newServer(t *testing.T, mode config.TrafficMode) (*Server, http.Handler) {
t.Helper()
cfg := config.Config{TrafficMode: mode, Retention: time.Hour, LogTailLines: 10, SystemNamespacePrefixes: []string{"d8-"}}
s := New(cfg, fstest.MapFS{"index.html": {Data: []byte("<!doctype html>")}})
return s, s.Handler()
}
func get(h http.Handler, path string) *httptest.ResponseRecorder {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil))
return rec
}
func TestNotReadyUntilCachesSync(t *testing.T) {
_, h := newServer(t, config.TrafficDisabled)
if code := get(h, "/readyz").Code; code != http.StatusServiceUnavailable {
t.Errorf("readyz before sync: %d", code)
}
if code := get(h, "/api/graph").Code; code != http.StatusServiceUnavailable {
t.Errorf("api before sync: %d", code)
}
if code := get(h, "/healthz").Code; code != http.StatusOK {
t.Errorf("healthz must not depend on caches: %d", code)
}
}
func TestSecurityHeaders(t *testing.T) {
_, h := newServer(t, config.TrafficDisabled)
rec := get(h, "/")
if csp := rec.Header().Get("Content-Security-Policy"); !strings.Contains(csp, "frame-ancestors 'none'") || !strings.Contains(csp, "default-src 'self'") {
t.Errorf("CSP: %q", csp)
}
if rec.Header().Get("X-Content-Type-Options") != "nosniff" {
t.Error("nosniff missing")
}
}
func TestPodsAndFlows(t *testing.T) {
yes := true
client := fake.NewSimpleClientset(
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "web-5f-abc", Namespace: "shop", OwnerReferences: []metav1.OwnerReference{{Kind: "ReplicaSet", Name: "web-5f", Controller: &yes}}},
Spec: corev1.PodSpec{NodeName: "node-a", Containers: []corev1.Container{{Name: "app"}, {Name: "sidecar"}}},
Status: corev1.PodStatus{Phase: corev1.PodRunning},
},
&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "other", Namespace: "shop"}},
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cache, err := kube.Start(ctx, client, 10*time.Second)
if err != nil {
t.Fatal(err)
}
s, h := newServer(t, config.TrafficDisabled)
s.SetReady(cache, traffic.NewCollector(s.cfg, nil, nil))
rec := get(h, "/api/pods?namespace=shop&id=wl/shop/deployment/web")
var pods []PodInfo
if err := json.Unmarshal(rec.Body.Bytes(), &pods); err != nil || len(pods) != 1 || len(pods[0].Containers) != 2 {
t.Fatalf("pods: %d %s", rec.Code, rec.Body)
}
if code := get(h, "/api/pods?namespace=shop&id=wl/other/deployment/web").Code; code != http.StatusBadRequest {
t.Errorf("id from another namespace must be rejected: %d", code)
}
var res traffic.Result
rec = get(h, "/api/flows?namespaces=shop&window=300")
if err := json.Unmarshal(rec.Body.Bytes(), &res); err != nil || res.Mode != config.TrafficDisabled {
t.Fatalf("flows in disabled mode: %d %s", rec.Code, rec.Body)
}
}
@@ -0,0 +1,466 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package topology turns the cached cluster state into the graph the map
// draws: namespaces, workloads, Services, Ingresses and nodes, joined by
// configuration edges (Ingress backend, Service selector) and placement.
package topology
import (
"sort"
"strconv"
"strings"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"git.project-chimera.ru/fanchji/cluster-map/internal/kube"
)
// Node is one card or box on the map.
type Node struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"` // namespace | deployment | statefulset | daemonset | cronjob | pod | service | ingress | node
Namespace string `json:"namespace"` // empty for namespace and node
Parent string `json:"parent,omitempty"`
Facts map[string]string `json:"facts,omitempty"` // short summary shown without a follow-up fetch
}
// Edge is a configuration or placement link between two nodes.
type Edge struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
Kind string `json:"kind"` // selects (workload -> service) | routes (ingress -> service) | schedules-on (workload -> node)
}
// Graph is the whole /api/graph response.
type Graph struct {
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
}
// WorkloadID is the graph ID of a workload. Traffic endpoints use the same
// scheme, which is what lets Hubble flows attach to graph cards.
func WorkloadID(ns, kind, name string) string { return "wl/" + ns + "/" + kind + "/" + name }
var nativeKinds = map[string]bool{"deployment": true, "statefulset": true, "daemonset": true, "cronjob": true}
type workloadRef struct {
id string
labels map[string]string
}
// Build assembles the graph from the cache. isSystem classifies namespaces.
func Build(c *kube.Cache, isSystem func(string) bool) (*Graph, error) {
g := &Graph{}
namespaces, err := kube.List[corev1.Namespace](c.Namespaces)
if err != nil {
return nil, err
}
for _, ns := range namespaces {
g.Nodes = append(g.Nodes, Node{
ID: "ns/" + ns.Name, Label: ns.Name, Kind: "namespace",
Facts: map[string]string{"system": strconv.FormatBool(isSystem(ns.Name))},
})
}
var workloads []workloadRef
deployments, err := kube.List[appsv1.Deployment](c.Deployments)
if err != nil {
return nil, err
}
for _, d := range deployments {
id := WorkloadID(d.Namespace, "deployment", d.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "deployment", d.Namespace, d.Name, deploymentFacts(d)))
workloads = append(workloads, workloadRef{id, d.Spec.Template.Labels})
}
statefulsets, err := kube.List[appsv1.StatefulSet](c.StatefulSets)
if err != nil {
return nil, err
}
for _, s := range statefulsets {
id := WorkloadID(s.Namespace, "statefulset", s.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "statefulset", s.Namespace, s.Name, statefulsetFacts(s)))
workloads = append(workloads, workloadRef{id, s.Spec.Template.Labels})
}
daemonsets, err := kube.List[appsv1.DaemonSet](c.DaemonSets)
if err != nil {
return nil, err
}
for _, ds := range daemonsets {
id := WorkloadID(ds.Namespace, "daemonset", ds.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "daemonset", ds.Namespace, ds.Name, daemonsetFacts(ds)))
workloads = append(workloads, workloadRef{id, ds.Spec.Template.Labels})
}
cronjobs, err := kube.List[batchv1.CronJob](c.CronJobs)
if err != nil {
return nil, err
}
for _, cj := range cronjobs {
id := WorkloadID(cj.Namespace, "cronjob", cj.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "cronjob", cj.Namespace, cj.Name, cronjobFacts(cj)))
}
pods, err := kube.List[corev1.Pod](c.Pods)
if err != nil {
return nil, err
}
nodes, foreignRefs := foreignWorkloads(pods, g.Nodes)
g.Nodes = append(g.Nodes, nodes...)
workloads = append(workloads, foreignRefs...)
services, err := kube.List[corev1.Service](c.Services)
if err != nil {
return nil, err
}
for _, svc := range services {
id := "service/" + svc.Namespace + "/" + svc.Name
g.Nodes = append(g.Nodes, Node{ID: id, Label: svc.Name, Kind: "service", Namespace: svc.Namespace, Parent: "ns/" + svc.Namespace, Facts: serviceFacts(svc)})
for _, wl := range workloads {
if strings.HasPrefix(wl.id, "wl/"+svc.Namespace+"/") && SelectorMatches(svc.Spec.Selector, wl.labels) {
g.Edges = append(g.Edges, Edge{ID: wl.id + "->" + id, Source: wl.id, Target: id, Kind: "selects"})
}
}
}
ingresses, err := kube.List[networkingv1.Ingress](c.Ingresses)
if err != nil {
return nil, err
}
for _, ing := range ingresses {
id := "ingress/" + ing.Namespace + "/" + ing.Name
g.Nodes = append(g.Nodes, Node{ID: id, Label: ing.Name, Kind: "ingress", Namespace: ing.Namespace, Parent: "ns/" + ing.Namespace, Facts: ingressFacts(ing)})
for _, svcName := range IngressBackendServices(ing) {
target := "service/" + ing.Namespace + "/" + svcName
g.Edges = append(g.Edges, Edge{ID: id + "->" + target, Source: id, Target: target, Kind: "routes"})
}
}
hostNodes, err := kube.List[corev1.Node](c.Nodes)
if err != nil {
return nil, err
}
for _, n := range hostNodes {
g.Nodes = append(g.Nodes, Node{ID: "node/" + n.Name, Label: n.Name, Kind: "node", Facts: nodeFacts(n)})
}
g.Edges = append(g.Edges, placementEdges(pods)...)
sort.Slice(g.Nodes, func(i, j int) bool { return g.Nodes[i].ID < g.Nodes[j].ID })
sort.Slice(g.Edges, func(i, j int) bool { return g.Edges[i].ID < g.Edges[j].ID })
return g, nil
}
// foreignWorkloads turns pods whose controller is not a native workload
// (kruise Advanced DaemonSet, database operators, bare Jobs, static pods)
// into workload nodes of their own, named the way Hubble names workloads.
func foreignWorkloads(pods []corev1.Pod, existing []Node) ([]Node, []workloadRef) {
known := make(map[string]bool, len(existing))
for _, n := range existing {
known[n.ID] = true
}
type acc struct {
ns, kind, name, controller string
pods, ready int
labels map[string]string
}
byID := map[string]*acc{}
for _, p := range pods {
kind, name, ctrl := PodOwner(p)
if kind == "" {
continue
}
id := WorkloadID(p.Namespace, kind, name)
if known[id] {
continue
}
a := byID[id]
if a == nil {
a = &acc{ns: p.Namespace, kind: kind, name: name, controller: ctrl, labels: p.Labels}
byID[id] = a
}
if p.Status.Phase == corev1.PodSucceeded {
continue
}
a.pods++
if podReady(p) {
a.ready++
}
}
var nodes []Node
var refs []workloadRef
for id, a := range byID {
kind := a.kind
if !nativeKinds[kind] {
kind = "pod"
}
nodes = append(nodes, workloadNode(id, kind, a.ns, a.name, map[string]string{
"controller": a.controller,
"pods": strconv.Itoa(a.pods),
"ready": strconv.Itoa(a.ready),
"health": Health(a.pods, a.ready),
"foreign": "true",
}))
refs = append(refs, workloadRef{id, a.labels})
}
return nodes, refs
}
func placementEdges(pods []corev1.Pod) []Edge {
seen := map[string]bool{}
var out []Edge
for _, p := range pods {
if p.Spec.NodeName == "" {
continue
}
wl := OwnerWorkloadID(p)
if wl == "" {
continue
}
key := wl + "@" + p.Spec.NodeName
if seen[key] {
continue
}
seen[key] = true
out = append(out, Edge{ID: key, Source: wl, Target: "node/" + p.Spec.NodeName, Kind: "schedules-on"})
}
return out
}
// SelectorMatches reports whether every key/value of a Service selector is
// present in a pod template's labels. An empty selector matches nothing
// here: in Kubernetes it selects no pods for endpoints either.
func SelectorMatches(sel, labels map[string]string) bool {
if len(sel) == 0 {
return false
}
for k, v := range sel {
if labels[k] != v {
return false
}
}
return true
}
// PodOwner names the workload a pod belongs to the way Hubble does
// (cilium's GetWorkloadMetaFromPod): ReplicaSet -> its Deployment, a Job
// whose name ends in the scheduler's numeric suffix -> its CronJob, a
// kubelet mirror pod -> its component, any other controller kind as-is.
// controller is "<apiVersion> <Kind>" of the owner reference.
func PodOwner(p corev1.Pod) (kind, name, controller string) {
var o *metav1.OwnerReference
for i := range p.OwnerReferences {
if c := p.OwnerReferences[i].Controller; c != nil && *c {
o = &p.OwnerReferences[i]
break
}
}
if o == nil && len(p.OwnerReferences) > 0 {
o = &p.OwnerReferences[0]
}
if o == nil {
return "", "", ""
}
controller = o.APIVersion + " " + o.Kind
switch o.Kind {
case "ReplicaSet":
if i := strings.LastIndex(o.Name, "-"); i > 0 {
return "deployment", o.Name[:i], controller
}
case "Job":
if name, ok := CronJobFromJob(o.Name); ok {
return "cronjob", name, controller
}
case "Node":
// static pod "<component>-<node>", grouped per component across nodes
return "staticpod", strings.TrimSuffix(p.Name, "-"+p.Spec.NodeName), "static pod (kubelet)"
}
return strings.ToLower(o.Kind), o.Name, controller
}
// CronJobFromJob returns the CronJob behind a Job name produced by the
// CronJob controller ("<cronjob>-<scheduled minute>").
func CronJobFromJob(job string) (string, bool) {
i := strings.LastIndex(job, "-")
if i <= 0 || !allDigits(job[i+1:]) {
return "", false
}
return job[:i], true
}
// OwnerWorkloadID is PodOwner as a graph ID, empty for bare pods.
func OwnerWorkloadID(p corev1.Pod) string {
kind, name, _ := PodOwner(p)
if kind == "" {
return ""
}
return WorkloadID(p.Namespace, kind, name)
}
func allDigits(s string) bool {
if s == "" {
return false
}
for _, c := range s {
if c < '0' || c > '9' {
return false
}
}
return true
}
func podReady(p corev1.Pod) bool {
for _, c := range p.Status.Conditions {
if c.Type == corev1.PodReady {
return c.Status == corev1.ConditionTrue
}
}
return false
}
func workloadNode(id, kind, ns, name string, facts map[string]string) Node {
return Node{ID: id, Label: name, Kind: kind, Namespace: ns, Parent: "ns/" + ns, Facts: facts}
}
// IngressBackendServices lists the distinct Services an Ingress routes to.
func IngressBackendServices(ing networkingv1.Ingress) []string {
seen := map[string]bool{}
var out []string
add := func(name string) {
if name != "" && !seen[name] {
seen[name] = true
out = append(out, name)
}
}
if b := ing.Spec.DefaultBackend; b != nil && b.Service != nil {
add(b.Service.Name)
}
for _, rule := range ing.Spec.Rules {
if rule.HTTP == nil {
continue
}
for _, path := range rule.HTTP.Paths {
if path.Backend.Service != nil {
add(path.Backend.Service.Name)
}
}
}
return out
}
// Health is what the status dot on a card shows: ok, warn (partly ready),
// error (nothing ready) or idle (scaled to zero or suspended).
func Health(want, ready int) string {
switch {
case want == 0:
return "idle"
case ready >= want:
return "ok"
case ready == 0:
return "error"
}
return "warn"
}
func replicasOf(p *int32) int {
if p == nil {
return 1
}
return int(*p)
}
func firstImage(cs []corev1.Container) string {
if len(cs) == 0 {
return ""
}
return cs[0].Image
}
func deploymentFacts(d appsv1.Deployment) map[string]string {
want := replicasOf(d.Spec.Replicas)
return map[string]string{
"replicas": strconv.Itoa(want), "readyReplicas": strconv.Itoa(int(d.Status.ReadyReplicas)),
"image": firstImage(d.Spec.Template.Spec.Containers), "health": Health(want, int(d.Status.ReadyReplicas)),
}
}
func statefulsetFacts(s appsv1.StatefulSet) map[string]string {
want := replicasOf(s.Spec.Replicas)
return map[string]string{
"replicas": strconv.Itoa(want), "readyReplicas": strconv.Itoa(int(s.Status.ReadyReplicas)),
"image": firstImage(s.Spec.Template.Spec.Containers), "health": Health(want, int(s.Status.ReadyReplicas)),
}
}
func daemonsetFacts(ds appsv1.DaemonSet) map[string]string {
want, ready := int(ds.Status.DesiredNumberScheduled), int(ds.Status.NumberReady)
return map[string]string{
"desired": strconv.Itoa(want), "ready": strconv.Itoa(ready),
"image": firstImage(ds.Spec.Template.Spec.Containers), "health": Health(want, ready),
}
}
func cronjobFacts(cj batchv1.CronJob) map[string]string {
f := map[string]string{"schedule": cj.Spec.Schedule, "health": "ok", "active": strconv.Itoa(len(cj.Status.Active))}
if cj.Spec.Suspend != nil && *cj.Spec.Suspend {
f["suspended"] = "true"
f["health"] = "idle"
}
if t := cj.Status.LastSuccessfulTime; t != nil {
f["lastSuccess"] = t.UTC().Format("2006-01-02 15:04")
}
return f
}
func serviceFacts(svc corev1.Service) map[string]string {
var ports []string
for _, p := range svc.Spec.Ports {
ports = append(ports, strconv.Itoa(int(p.Port))+"/"+string(p.Protocol))
}
return map[string]string{"type": string(svc.Spec.Type), "ports": strings.Join(ports, ", ")}
}
func ingressFacts(ing networkingv1.Ingress) map[string]string {
var hosts []string
for _, r := range ing.Spec.Rules {
if r.Host != "" {
hosts = append(hosts, r.Host)
}
}
class := ""
if ing.Spec.IngressClassName != nil {
class = *ing.Spec.IngressClassName
}
return map[string]string{"hosts": strings.Join(hosts, ", "), "class": class}
}
func nodeFacts(n corev1.Node) map[string]string {
ready := "False"
for _, c := range n.Status.Conditions {
if c.Type == corev1.NodeReady {
ready = string(c.Status)
}
}
h := "ok"
if ready != "True" {
h = "error"
}
return map[string]string{"ready": ready, "os": n.Status.NodeInfo.OSImage, "kubelet": n.Status.NodeInfo.KubeletVersion, "health": h}
}
@@ -0,0 +1,175 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package topology
import (
"context"
"testing"
"time"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"git.project-chimera.ru/fanchji/cluster-map/internal/kube"
)
func owned(kind, name string) []metav1.OwnerReference {
t := true
return []metav1.OwnerReference{{APIVersion: "apps/v1", Kind: kind, Name: name, Controller: &t}}
}
func TestPodOwner(t *testing.T) {
cases := []struct {
name string
pod corev1.Pod
kind, want string
}{
{"replicaset -> deployment", corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: owned("ReplicaSet", "web-7d9f8c")}}, "deployment", "web"},
{"statefulset", corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: owned("StatefulSet", "db")}}, "statefulset", "db"},
{"cronjob job", corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: owned("Job", "backup-29316120")}}, "cronjob", "backup"},
{"standalone job", corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: owned("Job", "llama-model-download")}}, "job", "llama-model-download"},
{"custom controller", corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: owned("Cluster", "d8ms-pg")}}, "cluster", "d8ms-pg"},
{"static pod", corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "kube-apiserver-master-0", OwnerReferences: owned("Node", "master-0")},
Spec: corev1.PodSpec{NodeName: "master-0"},
}, "staticpod", "kube-apiserver"},
{"bare pod", corev1.Pod{}, "", ""},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
kind, name, _ := PodOwner(c.pod)
if kind != c.kind || name != c.want {
t.Fatalf("got %s/%s, want %s/%s", kind, name, c.kind, c.want)
}
})
}
}
func TestPodOwnerPrefersControllerRef(t *testing.T) {
t.Parallel()
yes := true
p := corev1.Pod{ObjectMeta: metav1.ObjectMeta{OwnerReferences: []metav1.OwnerReference{
{Kind: "ConfigMap", Name: "not-the-controller"},
{Kind: "StatefulSet", Name: "db", Controller: &yes},
}}}
if kind, name, _ := PodOwner(p); kind != "statefulset" || name != "db" {
t.Fatalf("got %s/%s", kind, name)
}
}
func TestSelectorMatches(t *testing.T) {
t.Parallel()
labels := map[string]string{"app": "web", "tier": "front"}
if !SelectorMatches(map[string]string{"app": "web"}, labels) {
t.Error("subset selector should match")
}
if SelectorMatches(map[string]string{"app": "db"}, labels) {
t.Error("different value should not match")
}
if SelectorMatches(nil, labels) {
t.Error("empty selector must not match anything")
}
}
func TestHealth(t *testing.T) {
t.Parallel()
for _, c := range []struct {
want, ready int
out string
}{{0, 0, "idle"}, {2, 2, "ok"}, {2, 0, "error"}, {3, 1, "warn"}} {
if got := Health(c.want, c.ready); got != c.out {
t.Errorf("Health(%d,%d)=%s want %s", c.want, c.ready, got, c.out)
}
}
}
func TestBuildGraph(t *testing.T) {
replicas := int32(2)
pathType := networkingv1.PathTypePrefix
client := fake.NewSimpleClientset(
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "shop"}},
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "d8-system"}},
&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{Name: "web", Namespace: "shop"},
Spec: appsv1.DeploymentSpec{Replicas: &replicas, Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"app": "web"}},
}},
Status: appsv1.DeploymentStatus{ReadyReplicas: 1},
},
&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "web", Namespace: "shop"}, Spec: corev1.ServiceSpec{Selector: map[string]string{"app": "web"}}},
&networkingv1.Ingress{ObjectMeta: metav1.ObjectMeta{Name: "web", Namespace: "shop"}, Spec: networkingv1.IngressSpec{Rules: []networkingv1.IngressRule{{
Host: "shop.example.com",
IngressRuleValue: networkingv1.IngressRuleValue{HTTP: &networkingv1.HTTPIngressRuleValue{Paths: []networkingv1.HTTPIngressPath{{
Path: "/", PathType: &pathType,
Backend: networkingv1.IngressBackend{Service: &networkingv1.IngressServiceBackend{Name: "web"}},
}}}},
}}}},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "web-7d9f8c-abcde", Namespace: "shop", OwnerReferences: owned("ReplicaSet", "web-7d9f8c")},
Spec: corev1.PodSpec{NodeName: "node-a"},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{Name: "pg-1", Namespace: "shop", Labels: map[string]string{"cnpg": "pg"}, OwnerReferences: owned("Cluster", "pg")},
Spec: corev1.PodSpec{NodeName: "node-b"},
Status: corev1.PodStatus{Phase: corev1.PodRunning, Conditions: []corev1.PodCondition{{Type: corev1.PodReady, Status: corev1.ConditionTrue}}},
},
&corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node-a"}},
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cache, err := kube.Start(ctx, client, 10*time.Second)
if err != nil {
t.Fatal(err)
}
g, err := Build(cache, func(ns string) bool { return ns == "d8-system" })
if err != nil {
t.Fatal(err)
}
nodes := map[string]Node{}
for _, n := range g.Nodes {
nodes[n.ID] = n
}
edges := map[string]string{}
for _, e := range g.Edges {
edges[e.ID] = e.Kind
}
web := nodes["wl/shop/deployment/web"]
if web.Facts["health"] != "warn" || web.Facts["replicas"] != "2" {
t.Errorf("deployment facts: %v", web.Facts)
}
if nodes["ns/d8-system"].Facts["system"] != "true" || nodes["ns/shop"].Facts["system"] != "false" {
t.Error("system namespace classification")
}
pg, ok := nodes["wl/shop/cluster/pg"]
if !ok || pg.Kind != "pod" || pg.Facts["foreign"] != "true" || pg.Facts["ready"] != "1" {
t.Errorf("foreign workload: %+v", pg)
}
for id, kind := range map[string]string{
"wl/shop/deployment/web->service/shop/web": "selects",
"ingress/shop/web->service/shop/web": "routes",
"wl/shop/deployment/web@node-a": "schedules-on",
"wl/shop/cluster/pg@node-b": "schedules-on",
} {
if edges[id] != kind {
t.Errorf("edge %s: got %q want %q", id, edges[id], kind)
}
}
}
@@ -0,0 +1,452 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package traffic aggregates Cilium Hubble flows into per-minute buckets of
// distinct connections between workloads.
//
// Why a collector instead of querying Hubble on demand: every agent keeps
// only its ring buffer (4095 flows by default), which at a few hundred
// flows per second is about ten seconds of history. A request for "the
// last 15 minutes" answered from the buffer silently returns the last few
// seconds. So flows are read from a follow stream and kept here.
package traffic
import (
"context"
"hash/fnv"
"log/slog"
"sort"
"strconv"
"sync"
"time"
flowpb "github.com/cilium/cilium/api/v1/flow"
observerpb "github.com/cilium/cilium/api/v1/observer"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/timestamppb"
"git.project-chimera.ru/fanchji/cluster-map/internal/config"
"git.project-chimera.ru/fanchji/cluster-map/internal/metrics"
)
// maxTuplesPerKey bounds memory per edge per minute; beyond it the distinct
// count for that edge stops growing for the rest of the minute.
const maxTuplesPerKey = 20000
// InfraFilters are applied at the agents, so the relay never serialises
// these flows. On a 12k-event sample from a real cluster they were ~74% of
// non-reply events: host-originated traffic (kubelet probes, hostNetwork
// pods) 43%, DNS 19%, remote-node 11%, cilium health 1%. None of them map
// to a workload card, and streaming them kept hubble-relay at ~400m CPU.
var InfraFilters = []*flowpb.FlowFilter{
{SourceLabel: []string{"reserved:host"}},
{SourceLabel: []string{"reserved:remote-node"}},
{SourceLabel: []string{"reserved:health"}},
{DestinationLabel: []string{"reserved:health"}},
{DestinationPort: []string{"53"}},
}
var flowFields = []string{"time", "verdict", "IP", "l4", "source", "destination", "source_names", "destination_names", "node_name"}
// Endpoint is one side of a traffic edge: a workload, a pod or an address.
type Endpoint struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"` // lowercased controller kind, "pod", or "external"
Namespace string `json:"namespace,omitempty"`
}
// Edge is aggregated traffic from Source to Target on one port.
type Edge struct {
Source string `json:"source"`
Target string `json:"target"`
Port string `json:"port"` // "443/TCP"
Connections int `json:"connections"` // distinct 5-tuples seen in the window
New int `json:"new"` // of those, opened by TCP SYN inside the window
Dropped int `json:"dropped"` // distinct 5-tuples with a DROPPED verdict
Last string `json:"last"`
}
// Result is the /api/flows response.
type Result struct {
Mode config.TrafficMode `json:"mode"`
WindowSec int `json:"windowSec"`
CoveredSec int `json:"coveredSec"` // how much of the window the collector has actually seen
Connected bool `json:"connected"`
Error string `json:"error,omitempty"`
Endpoints []Endpoint `json:"endpoints"`
Edges []Edge `json:"edges"`
}
// PodResolver maps a pod to the workload that owns it; ok is false for
// pods the cache doesn't know (already gone).
type PodResolver func(namespace, pod string) (Endpoint, bool)
type edgeKey struct{ src, dst, port string }
const (
tupleSYN uint8 = 1
tupleDrop uint8 = 2
)
type bucketEdge struct {
tuples map[uint64]uint8
last int64
}
type bucket struct {
minute int64
edges map[edgeKey]*bucketEdge
}
// Collector keeps minute buckets of distinct connections for the
// configured retention.
type Collector struct {
cfg config.Config
obs observerpb.ObserverClient
resolve PodResolver
now func() time.Time
mu sync.Mutex
base context.Context // lifetime of Run; streams started by Query live under it
buckets []*bucket
endpoints map[string]Endpoint
coveredFrom time.Time // start of the current uninterrupted collection
running bool
connected bool
lastErr string
lastQuery time.Time
cancel context.CancelFunc
}
// NewCollector builds a collector; obs may be nil when traffic is off or
// the Hubble client could not be set up.
func NewCollector(cfg config.Config, obs observerpb.ObserverClient, resolve PodResolver) *Collector {
return &Collector{
cfg: cfg, obs: obs, resolve: resolve, now: time.Now,
buckets: make([]*bucket, int(cfg.Retention/time.Minute)),
endpoints: map[string]Endpoint{},
}
}
// Run blocks until ctx is done. In Continuous mode it streams all the
// time; in OnDemand mode it streams from the first Query until
// OnDemandIdle passes without one.
func (c *Collector) Run(ctx context.Context) {
c.mu.Lock()
c.base = ctx
c.mu.Unlock()
switch c.cfg.TrafficMode {
case config.TrafficDisabled:
return
case config.TrafficContinuous:
c.start(ctx)
<-ctx.Done()
case config.TrafficOnDemand:
t := time.NewTicker(30 * time.Second)
defer t.Stop()
for {
select {
case <-ctx.Done():
c.stop()
return
case <-t.C:
c.mu.Lock()
idle := c.running && c.now().Sub(c.lastQuery) > c.cfg.OnDemandIdle
c.mu.Unlock()
if idle {
slog.Info("traffic: no viewers, closing Hubble stream", "idle", c.cfg.OnDemandIdle)
c.stop()
}
}
}
}
}
func (c *Collector) start(parent context.Context) {
c.mu.Lock()
if c.running || c.obs == nil {
c.mu.Unlock()
return
}
ctx, cancel := context.WithCancel(parent)
c.running, c.cancel, c.coveredFrom = true, cancel, c.now()
c.mu.Unlock()
metrics.HubbleStreamActive.Set(1)
go c.loop(ctx)
}
func (c *Collector) stop() {
c.mu.Lock()
defer c.mu.Unlock()
if !c.running {
return
}
c.cancel()
c.running, c.connected = false, false
metrics.HubbleStreamActive.Set(0)
metrics.HubbleConnected.Set(0)
}
func (c *Collector) loop(ctx context.Context) {
useMask := true
backoff := time.Second
for ctx.Err() == nil {
req := &observerpb.GetFlowsRequest{
Follow: true,
// Backfill whatever the ring buffers still hold; tuples seen twice
// after a reconnect collapse in the per-minute sets.
Since: timestamppb.New(c.now().Add(-time.Minute)),
Whitelist: []*flowpb.FlowFilter{{Reply: []bool{false}}},
}
if !c.cfg.CollectInfra {
req.Blacklist = InfraFilters
}
if useMask {
req.FieldMask = &fieldmaskpb.FieldMask{Paths: flowFields}
}
received, err := c.stream(ctx, req)
if ctx.Err() != nil {
return
}
if status.Code(err) == codes.InvalidArgument && useMask {
useMask = false
slog.Warn("traffic: relay rejected the field mask, retrying without it", "err", err)
continue
}
c.setErr(err)
metrics.HubbleReconnects.Inc()
if received > 0 {
backoff = time.Second
}
select {
case <-ctx.Done():
return
case <-time.After(backoff):
}
backoff = min(backoff*2, 30*time.Second)
}
}
func (c *Collector) stream(ctx context.Context, req *observerpb.GetFlowsRequest) (int, error) {
s, err := c.obs.GetFlows(ctx, req)
if err != nil {
return 0, err
}
n := 0
for {
resp, err := s.Recv()
if err != nil {
return n, err
}
if f := resp.GetFlow(); f != nil {
c.Add(f)
n++
}
}
}
func (c *Collector) setErr(err error) {
c.mu.Lock()
defer c.mu.Unlock()
c.connected = false
if err != nil {
c.lastErr = err.Error()
}
metrics.HubbleConnected.Set(0)
slog.Warn("traffic: Hubble stream ended", "err", err)
}
// Add records one flow. Exported for tests and for replaying captures.
func (c *Collector) Add(f *flowpb.Flow) {
src := c.endpoint(f.GetSource(), f.GetSourceNames(), f.GetNodeName())
dst := c.endpoint(f.GetDestination(), f.GetDestinationNames(), f.GetNodeName())
metrics.FlowsProcessed.Inc()
if src.ID == dst.ID {
return
}
port, tuple, syn := l4Info(f)
ts := c.now()
if t := f.GetTime(); t != nil {
ts = t.AsTime()
}
minute := ts.Unix() / 60
c.mu.Lock()
defer c.mu.Unlock()
if !c.connected {
c.connected, c.lastErr = true, ""
metrics.HubbleConnected.Set(1)
}
slot := int(minute % int64(len(c.buckets)))
b := c.buckets[slot]
if b == nil || b.minute != minute {
if b != nil && b.minute > minute {
return // older than retention
}
b = &bucket{minute: minute, edges: map[edgeKey]*bucketEdge{}}
c.buckets[slot] = b
c.pruneEndpoints()
}
c.endpoints[src.ID] = src
c.endpoints[dst.ID] = dst
k := edgeKey{src.ID, dst.ID, port}
e := b.edges[k]
if e == nil {
e = &bucketEdge{tuples: map[uint64]uint8{}}
b.edges[k] = e
}
h := hashTuple(f.GetIP().GetSource(), f.GetIP().GetDestination(), tuple)
flags, seen := e.tuples[h]
if !seen && len(e.tuples) >= maxTuplesPerKey {
return
}
if syn {
flags |= tupleSYN
}
if f.GetVerdict() == flowpb.Verdict_DROPPED {
flags |= tupleDrop
}
e.tuples[h] = flags
e.last = max(e.last, ts.Unix())
}
// pruneEndpoints drops metadata for endpoints no retained bucket mentions.
// Called with c.mu held, once per minute rollover.
func (c *Collector) pruneEndpoints() {
used := map[string]bool{}
tuples := 0
for _, b := range c.buckets {
if b == nil {
continue
}
for k, e := range b.edges {
used[k.src], used[k.dst] = true, true
tuples += len(e.tuples)
}
}
for id := range c.endpoints {
if !used[id] {
delete(c.endpoints, id)
}
}
metrics.TrackedTuples.Set(float64(tuples))
}
// Query returns traffic touching any of the namespaces over the last
// window. In OnDemand mode it also (re)starts collection.
func (c *Collector) Query(namespaces map[string]bool, window time.Duration) Result {
if c.cfg.TrafficMode == config.TrafficOnDemand {
c.mu.Lock()
c.lastQuery = c.now()
base := c.base
c.mu.Unlock()
if base != nil {
c.start(base)
}
}
window = min(window, c.cfg.Retention)
now := c.now()
fromMinute := now.Add(-window).Unix() / 60
c.mu.Lock()
defer c.mu.Unlock()
res := Result{Mode: c.cfg.TrafficMode, WindowSec: int(window.Seconds()), Connected: c.connected, Error: c.lastErr}
if c.running {
res.CoveredSec = min(res.WindowSec, int(now.Sub(c.coveredFrom).Seconds()))
}
touches := func(id string) bool { return namespaces[c.endpoints[id].Namespace] }
merged := map[edgeKey]*bucketEdge{}
for _, b := range c.buckets {
if b == nil || b.minute < fromMinute {
continue
}
for k, e := range b.edges {
if !touches(k.src) && !touches(k.dst) {
continue
}
m := merged[k]
if m == nil {
m = &bucketEdge{tuples: make(map[uint64]uint8, len(e.tuples))}
merged[k] = m
}
for h, fl := range e.tuples {
m.tuples[h] |= fl
}
m.last = max(m.last, e.last)
}
}
eps := map[string]bool{}
for k, m := range merged {
e := Edge{Source: k.src, Target: k.dst, Port: k.port, Connections: len(m.tuples), Last: time.Unix(m.last, 0).UTC().Format(time.RFC3339)}
for _, fl := range m.tuples {
if fl&tupleSYN != 0 {
e.New++
}
if fl&tupleDrop != 0 {
e.Dropped++
}
}
res.Edges = append(res.Edges, e)
eps[k.src], eps[k.dst] = true, true
}
for id := range eps {
res.Endpoints = append(res.Endpoints, c.endpoints[id])
}
sort.Slice(res.Endpoints, func(i, j int) bool { return res.Endpoints[i].ID < res.Endpoints[j].ID })
sort.Slice(res.Edges, func(i, j int) bool {
if res.Edges[i].Connections != res.Edges[j].Connections {
return res.Edges[i].Connections > res.Edges[j].Connections
}
return res.Edges[i].Source+res.Edges[i].Target+res.Edges[i].Port < res.Edges[j].Source+res.Edges[j].Target+res.Edges[j].Port
})
return res
}
func hashTuple(srcIP, dstIP, rest string) uint64 {
h := fnv.New64a()
h.Write([]byte(srcIP))
h.Write([]byte{0})
h.Write([]byte(dstIP))
h.Write([]byte{0})
h.Write([]byte(rest))
return h.Sum64()
}
// l4Info returns the display port ("443/TCP"), the port part of the
// connection tuple, and whether this event opens a TCP connection.
func l4Info(f *flowpb.Flow) (port, tuple string, syn bool) {
l4 := f.GetL4()
p := func(n uint32) string { return strconv.FormatUint(uint64(n), 10) }
switch {
case l4.GetTCP() != nil:
t := l4.GetTCP()
return p(t.GetDestinationPort()) + "/TCP", "tcp:" + p(t.GetSourcePort()) + ":" + p(t.GetDestinationPort()),
t.GetFlags().GetSYN() && !t.GetFlags().GetACK()
case l4.GetUDP() != nil:
u := l4.GetUDP()
return p(u.GetDestinationPort()) + "/UDP", "udp:" + p(u.GetSourcePort()) + ":" + p(u.GetDestinationPort()), false
case l4.GetSCTP() != nil:
s := l4.GetSCTP()
return p(s.GetDestinationPort()) + "/SCTP", "sctp:" + p(s.GetSourcePort()) + ":" + p(s.GetDestinationPort()), false
case l4.GetICMPv4() != nil || l4.GetICMPv6() != nil:
return "ICMP", "icmp", false
}
return "?", "?", false
}
@@ -0,0 +1,165 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package traffic
import (
"testing"
"time"
flowpb "github.com/cilium/cilium/api/v1/flow"
"google.golang.org/protobuf/types/known/timestamppb"
"git.project-chimera.ru/fanchji/cluster-map/internal/config"
)
var t0 = time.Date(2026, 9, 23, 12, 0, 0, 0, time.UTC)
func newTestCollector(now *time.Time) *Collector {
cfg := config.Config{TrafficMode: config.TrafficContinuous, Retention: 60 * time.Minute}
c := NewCollector(cfg, nil, func(ns, pod string) (Endpoint, bool) {
if pod == "gone" {
return Endpoint{}, false
}
return Endpoint{ID: "wl/" + ns + "/deployment/" + pod, Label: pod, Kind: "deployment", Namespace: ns}, true
})
c.now = func() time.Time { return *now }
c.running, c.coveredFrom = true, t0
return c
}
func tcpFlow(at time.Time, srcNs, src, dstNs, dst string, srcPort uint32, syn bool, verdict flowpb.Verdict) *flowpb.Flow {
return &flowpb.Flow{
Time: timestamppb.New(at),
Verdict: verdict,
IP: &flowpb.IP{Source: "10.0.0.1", Destination: "10.0.0.2"},
L4: &flowpb.Layer4{Protocol: &flowpb.Layer4_TCP{TCP: &flowpb.TCP{SourcePort: srcPort, DestinationPort: 5432, Flags: &flowpb.TCPFlags{SYN: syn, ACK: !syn}}}},
Source: &flowpb.Endpoint{Namespace: srcNs, PodName: src},
Destination: &flowpb.Endpoint{Namespace: dstNs, PodName: dst},
}
}
func TestDistinctConnections(t *testing.T) {
now := t0.Add(2 * time.Minute)
c := newTestCollector(&now)
// one connection seen three times (SYN + two data events), one more opened
c.Add(tcpFlow(t0, "app", "web", "db", "pg", 40000, true, flowpb.Verdict_FORWARDED))
c.Add(tcpFlow(t0.Add(time.Second), "app", "web", "db", "pg", 40000, false, flowpb.Verdict_FORWARDED))
c.Add(tcpFlow(t0.Add(70*time.Second), "app", "web", "db", "pg", 40000, false, flowpb.Verdict_FORWARDED))
c.Add(tcpFlow(t0.Add(2*time.Second), "app", "web", "db", "pg", 40001, true, flowpb.Verdict_FORWARDED))
// a long-lived pooled connection: data only, no SYN in the window
c.Add(tcpFlow(t0, "app", "worker", "db", "pg", 50000, false, flowpb.Verdict_FORWARDED))
// dropped attempt
c.Add(tcpFlow(t0, "app", "web", "db", "pg", 40002, true, flowpb.Verdict_DROPPED))
res := c.Query(map[string]bool{"db": true}, 5*time.Minute)
got := map[string]Edge{}
for _, e := range res.Edges {
got[e.Source] = e
}
web := got["wl/app/deployment/web"]
if web.Connections != 3 || web.New != 3 || web.Dropped != 1 || web.Port != "5432/TCP" {
t.Errorf("web -> pg: %+v", web)
}
worker := got["wl/app/deployment/worker"]
if worker.Connections != 1 || worker.New != 0 {
t.Errorf("worker -> pg: %+v", worker)
}
if res.CoveredSec != 120 {
t.Errorf("coveredSec = %d, want 120", res.CoveredSec)
}
}
func TestWindowAndNamespaceFilter(t *testing.T) {
now := t0.Add(30 * time.Minute)
c := newTestCollector(&now)
c.Add(tcpFlow(t0, "app", "old", "db", "pg", 1, true, flowpb.Verdict_FORWARDED))
c.Add(tcpFlow(now.Add(-time.Minute), "app", "recent", "db", "pg", 2, true, flowpb.Verdict_FORWARDED))
c.Add(tcpFlow(now.Add(-time.Minute), "other", "a", "other", "b", 3, true, flowpb.Verdict_FORWARDED))
res := c.Query(map[string]bool{"db": true}, 5*time.Minute)
if len(res.Edges) != 1 || res.Edges[0].Source != "wl/app/deployment/recent" {
t.Fatalf("5 min window: %+v", res.Edges)
}
res = c.Query(map[string]bool{"db": true}, time.Hour)
if len(res.Edges) != 2 {
t.Fatalf("hour window should include the old flow: %+v", res.Edges)
}
}
func TestRetentionOverwritesOldBuckets(t *testing.T) {
now := t0
c := newTestCollector(&now)
c.Add(tcpFlow(t0, "app", "web", "db", "pg", 1, true, flowpb.Verdict_FORWARDED))
// exactly one retention later the same slot is reused
now = t0.Add(60 * time.Minute)
c.Add(tcpFlow(now, "app", "web", "db", "pg", 2, true, flowpb.Verdict_FORWARDED))
res := c.Query(map[string]bool{"db": true}, time.Hour)
if len(res.Edges) != 1 || res.Edges[0].Connections != 1 {
t.Fatalf("old bucket should have been replaced: %+v", res.Edges)
}
// a late flow for the replaced minute is ignored
c.Add(tcpFlow(t0, "app", "late", "db", "pg", 3, true, flowpb.Verdict_FORWARDED))
for _, e := range c.Query(map[string]bool{"db": true}, time.Hour).Edges {
if e.Source == "wl/app/deployment/late" {
t.Fatal("flow older than retention was recorded")
}
}
}
func TestEndpointMapping(t *testing.T) {
now := t0
c := newTestCollector(&now)
cases := []struct {
ep *flowpb.Endpoint
names []string
want string
}{
{&flowpb.Endpoint{Namespace: "app", PodName: "web"}, nil, "wl/app/deployment/web"},
{&flowpb.Endpoint{Namespace: "app", PodName: "gone", Workloads: []*flowpb.Workload{{Kind: "Job", Name: "backup-29316120"}}}, nil, "wl/app/cronjob/backup"},
{&flowpb.Endpoint{Namespace: "app", PodName: "gone"}, nil, "pod/app/gone"},
{&flowpb.Endpoint{Labels: []string{"reserved:kube-apiserver"}}, nil, "ext/kube-apiserver"},
{&flowpb.Endpoint{Labels: []string{"reserved:world"}}, []string{"api.github.com"}, "ext/dns/api.github.com"},
{&flowpb.Endpoint{Labels: []string{"reserved:world"}}, nil, "ext/world"},
{&flowpb.Endpoint{Labels: []string{"reserved:host"}}, nil, "ext/host/node-a"},
}
for _, tc := range cases {
if got := c.endpoint(tc.ep, tc.names, "node-a").ID; got != tc.want {
t.Errorf("%v: got %s want %s", tc.ep, got, tc.want)
}
}
}
func TestL4Info(t *testing.T) {
t.Parallel()
udp := &flowpb.Flow{L4: &flowpb.Layer4{Protocol: &flowpb.Layer4_UDP{UDP: &flowpb.UDP{SourcePort: 1234, DestinationPort: 53}}}}
if port, _, syn := l4Info(udp); port != "53/UDP" || syn {
t.Errorf("udp: %s %v", port, syn)
}
synAck := &flowpb.Flow{L4: &flowpb.Layer4{Protocol: &flowpb.Layer4_TCP{TCP: &flowpb.TCP{DestinationPort: 443, Flags: &flowpb.TCPFlags{SYN: true, ACK: true}}}}}
if _, _, syn := l4Info(synAck); syn {
t.Error("SYN-ACK is a reply, not an opened connection")
}
}
func TestDisabledModeNeverStreams(t *testing.T) {
t.Parallel()
c := NewCollector(config.Config{TrafficMode: config.TrafficDisabled, Retention: time.Hour}, nil, nil)
c.start(t.Context())
if c.running {
t.Fatal("collector without a Hubble client must not start")
}
}
@@ -0,0 +1,69 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package traffic
import (
"slices"
"strings"
flowpb "github.com/cilium/cilium/api/v1/flow"
"git.project-chimera.ru/fanchji/cluster-map/internal/topology"
)
// endpoint maps a Hubble endpoint to an ID that matches a graph node when
// the peer is one of our workloads. Hubble leaves Endpoint.Workloads empty
// on some flows (typically the half observed on the peer's node), so pods
// are resolved through the cache with the graph's own rules first, and
// Hubble's workload name is only a fallback for pods already gone.
func (c *Collector) endpoint(e *flowpb.Endpoint, names []string, nodeName string) Endpoint {
if pod := e.GetPodName(); pod != "" {
ns := e.GetNamespace()
if c.resolve != nil {
if ep, ok := c.resolve(ns, pod); ok {
return ep
}
}
for _, wl := range e.GetWorkloads() {
kind, name := strings.ToLower(wl.GetKind()), wl.GetName()
if kind == "job" {
if cj, ok := topology.CronJobFromJob(name); ok {
kind, name = "cronjob", cj
}
}
if kind != "" && name != "" {
return Endpoint{ID: topology.WorkloadID(ns, kind, name), Label: name, Kind: kind, Namespace: ns}
}
}
return Endpoint{ID: "pod/" + ns + "/" + pod, Label: pod, Kind: "pod", Namespace: ns}
}
labels := e.GetLabels()
switch {
case slices.Contains(labels, "reserved:host"):
return Endpoint{ID: "ext/host/" + nodeName, Label: "host " + nodeName, Kind: "external"}
case slices.Contains(labels, "reserved:remote-node"):
return Endpoint{ID: "ext/remote-node", Label: "remote nodes", Kind: "external"}
case slices.Contains(labels, "reserved:kube-apiserver"):
return Endpoint{ID: "ext/kube-apiserver", Label: "kube-apiserver", Kind: "external"}
case slices.Contains(labels, "reserved:health"):
return Endpoint{ID: "ext/health", Label: "cilium health", Kind: "external"}
}
if len(names) > 0 {
return Endpoint{ID: "ext/dns/" + names[0], Label: names[0], Kind: "external"}
}
return Endpoint{ID: "ext/world", Label: "world", Kind: "external"}
}
+35
View File
@@ -0,0 +1,35 @@
/*
Copyright 2026 The cluster-map Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package web embeds the frontend so the binary needs no files on disk.
package web
import (
"embed"
"io/fs"
)
//go:embed static
var files embed.FS
// Static returns the frontend rooted at static/.
func Static() fs.FS {
sub, err := fs.Sub(files, "static")
if err != nil {
panic(err) // the embed directive guarantees the directory exists
}
return sub
}
@@ -12,15 +12,15 @@ const KIND = {
service: { title: 'Service', color: '#14a37f' },
ingress: { title: 'Ingress', color: '#d99a06' },
node: { title: 'Node', color: '#64748b' },
pod: { title: 'Контроллер', color: '#0ea5e9' },
external: { title: 'Внешний', color: '#94a3b8' },
pod: { title: t('kind.pod'), color: '#0ea5e9' },
external: { title: t('kind.external'), color: '#94a3b8' },
};
const WORKLOAD = new Set(['deployment', 'statefulset', 'daemonset', 'cronjob']);
const KIND_ORDER = ['ingress', 'service', 'deployment', 'statefulset', 'daemonset', 'cronjob', 'pod'];
const FOLDER_TITLE = { pod: 'Другие контроллеры' };
const FOLDER_TITLE = { pod: t('folder.pod') };
const hasPods = (n) => WORKLOAD.has(n.kind) || n.facts?.foreign === 'true';
const controllerKind = (n) => (n.facts?.controller || '').startsWith('static') ? 'static pod' : (n.facts?.controller || '').split(' ').pop();
const HEALTH_TEXT = { ok: 'в норме', warn: 'готов частично', error: 'не готов', idle: 'выключен' };
const HEALTH_TEXT = { ok: t('health.ok'), warn: t('health.warn'), error: t('health.error'), idle: t('health.idle') };
const HEALTH_RANK = { error: 3, warn: 2, ok: 1, idle: 0 };
const ICON = {
deployment: '<rect x="3" y="6" width="11" height="11" rx="2"/><path d="M6 3h9a2 2 0 0 1 2 2v9"/>',
@@ -52,11 +52,6 @@ const el = (tag, props = {}, ...children) => {
for (const c of children.flat()) if (c !== null && c !== undefined) e.append(c);
return e;
};
const plural = (n, one, few, many) => {
const m10 = n % 10, m100 = n % 100;
const w = m10 === 1 && m100 !== 11 ? one : m10 >= 2 && m10 <= 4 && (m100 < 12 || m100 > 14) ? few : many;
return `${n} ${w}`;
};
const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
const iconSvg = (kind, size = 14) =>
`<svg class="icon" viewBox="0 0 20 20" width="${size}" height="${size}" fill="none" stroke="${(KIND[kind] || KIND.external).color}" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICON[kind] || ''}</svg>`;
@@ -64,7 +59,8 @@ const iconSvg = (kind, size = 14) =>
/* ---------- theme ---------- */
let T = {};
function readTheme() {
const probe = el('span', { style: 'display:none' });
const probe = el('span');
probe.style.display = 'none';
document.body.append(probe);
const tok = (name) => { probe.style.color = `var(--${name})`; return getComputedStyle(probe).color; };
T = {
@@ -165,11 +161,11 @@ function nsHealth(ns) {
}
function subline(n) {
const f = n.facts || {};
if (f.foreign === 'true') return `${f.ready}/${f.pods} готово · ${controllerKind(n)}`;
if (f.foreign === 'true') return `${t('sub.ready', { ready: f.ready, want: f.pods })} · ${controllerKind(n)}`;
switch (n.kind) {
case 'deployment': case 'statefulset': return `${f.readyReplicas ?? '?'}/${f.replicas ?? '?'} готово`;
case 'daemonset': return `${f.ready ?? '?'}/${f.desired ?? '?'} на нодах`;
case 'cronjob': return f.suspended === 'true' ? `${f.schedule} · пауза` : f.schedule;
case 'deployment': case 'statefulset': return t('sub.ready', { ready: f.readyReplicas ?? '?', want: f.replicas ?? '?' });
case 'daemonset': return t('sub.onNodes', { ready: f.ready ?? '?', want: f.desired ?? '?' });
case 'cronjob': return f.suspended === 'true' ? t('sub.paused', { schedule: f.schedule }) : f.schedule;
case 'service': return [f.type, f.ports].filter(Boolean).join(' · ');
case 'ingress': return f.hosts || f.class || '';
case 'node': return f.ready === 'True' ? 'Ready' : 'NotReady';
@@ -243,10 +239,10 @@ function buildTreeModel() {
const user = G.nsNodes.filter((n) => n.facts?.system !== 'true').map(nsItem);
const sys = G.nsNodes.filter((n) => n.facts?.system === 'true').map(nsItem);
return [{
id: 't:cluster', label: 'Кластер', icon: 'node', activate: scopeCluster, forceOpen: true,
id: 't:cluster', label: t('tree.cluster'), icon: 'node', activate: scopeCluster, forceOpen: true,
children: [
{ id: 't:grp:user', label: 'Приложения', icon: 'namespace', count: user.length, children: user, activate: scopeCluster },
{ id: 't:grp:sys', label: 'Системные (d8-*, kube-*)', icon: 'namespace', count: sys.length, children: sys, activate: scopeCluster },
{ id: 't:grp:user', label: t('tree.apps'), icon: 'namespace', count: user.length, children: user, activate: scopeCluster },
{ id: 't:grp:sys', label: t('tree.system', { prefixes: 'd8-*, kube-*' }), icon: 'namespace', count: sys.length, children: sys, activate: scopeCluster },
],
}];
}
@@ -495,6 +491,12 @@ function cardNode(n, parent, ghost) {
},
};
}
// Hubble's reserved identities get a translated name; DNS names and node
// hosts are shown as they are.
function epLabel(ep) {
const k = 'ext.' + ep.id.slice(4);
return ep.id.startsWith('ext/') && !ep.id.startsWith('ext/dns/') && !ep.id.startsWith('ext/host/') && t(k) !== k ? t(k) : ep.label;
}
function externalNode(ep) {
const inNs = !!ep.namespace;
const kind = !inNs ? 'external' : KIND[ep.kind] ? ep.kind : 'pod';
@@ -503,7 +505,7 @@ function externalNode(ep) {
group: 'nodes',
data: {
id: ep.id, ref: ep.id, kind, w: size.w, h: size.h, parent: inNs ? 'box:' + ep.namespace : undefined, external: ep,
img: cardImage({ kind, title: ep.label, sub: inNs ? `${ep.namespace} · ${ep.kind}` : null, ghost: inNs, w: size.w, h: size.h }),
img: cardImage({ kind, title: epLabel(ep), sub: inNs ? `${ep.namespace} · ${ep.kind}` : null, ghost: inNs, w: size.w, h: size.h }),
},
};
}
@@ -550,7 +552,7 @@ function buildElements() {
} else {
const host = state.scope.node;
members = [...(G.onNode.get(host) || [])].map((id) => G.byId.get(id)).filter(Boolean);
add({ group: 'nodes', classes: 'hostbox', data: { id: 'host:' + host, label: 'нода ' + host, kind: 'hostbox', w: 1, h: 1, img: 'none', lmx: 0 } });
add({ group: 'nodes', classes: 'hostbox', data: { id: 'host:' + host, label: t('node', { name: host }), kind: 'hostbox', w: 1, h: 1, img: 'none', lmx: 0 } });
for (const ns of new Set(members.map((m) => m.namespace))) add(nsBox(ns, false, 'host:' + host));
}
const memberIds = new Set(members.map((m) => m.id));
@@ -593,7 +595,7 @@ function trafficEdgeElement(e) {
function trafficEdgeData(e) {
return {
width: 1.6 + Math.min(4.5, Math.log10(e.count + 1) * 1.7),
label: `${e.ports.slice(0, 3).join(', ')}${e.ports.length > 3 ? '…' : ''} · ${e.count} соед.${e.dropped ? ` · drop ${e.dropped}` : ''}`,
label: `${e.ports.slice(0, 3).join(', ')}${e.ports.length > 3 ? '…' : ''} · ${t('edge.conns', { n: e.count })}${e.dropped ? t('edge.drop', { n: e.dropped }) : ''}`,
flow: e,
};
}
@@ -601,7 +603,7 @@ function trafficEdgeData(e) {
// Refresh traffic on the drawn map without relayout: counts and widths are
// updated, edges between cards already on the map come and go. Peers that
// would need new cards are only counted, so the layout never jumps under
// the cursor; "Обновить" redraws with them.
// the cursor; the Refresh button redraws with them.
let hiddenPeers = 0;
async function refreshTraffic() {
if (!state.traffic || state.scope.mode === 'cluster' || document.hidden) return;
@@ -637,8 +639,8 @@ setInterval(refreshTraffic, 30000);
function buildClusterElements() {
const els = [];
const groups = [
['grp:user', 'Приложения', G.nsNodes.filter((n) => n.facts?.system !== 'true')],
['grp:sys', 'Системные', G.nsNodes.filter((n) => n.facts?.system === 'true')],
['grp:user', t('group.apps'), G.nsNodes.filter((n) => n.facts?.system !== 'true')],
['grp:sys', t('group.system'), G.nsNodes.filter((n) => n.facts?.system === 'true')],
];
let y0 = 0;
const gapX = 18, gapY = 18;
@@ -767,10 +769,10 @@ async function renderMap() {
state.flowsError = null;
const namespaces = scopeNamespaces();
if (state.traffic && namespaces.length) {
setStatus('загрузка трафика…');
setStatus(t('status.loadingTraffic'));
try {
state.flows = await fetchFlows(namespaces.slice(0, 100));
if (!state.flows.connected && !state.flows.edges?.length) state.flowsError = state.flows.error || 'нет связи с Hubble Relay';
if (!state.flows.connected && !state.flows.edges?.length) state.flowsError = state.flows.error || t('status.noRelay');
} catch (err) {
state.flowsError = err.message;
}
@@ -793,29 +795,30 @@ async function renderMap() {
function updateStatus(els) {
if (state.scope.mode === 'cluster') { setStatus(''); return; }
const cards = els.filter((x) => x.group === 'nodes' && x.data.kind !== 'nsbox' && x.data.kind !== 'hostbox').length;
if (!cards) { setStatus('здесь нет объектов'); return; }
if (!cards) { setStatus(t('status.empty')); return; }
if (!state.traffic) { setStatus(''); return; }
if (state.flowsError) { setStatus('трафик недоступен: ' + state.flowsError, true); return; }
if (state.flows?.mode === 'Disabled') { setStatus(t('status.trafficOff')); return; }
if (state.flowsError) { setStatus(t('status.trafficFailed', { err: state.flowsError }), true); return; }
if (state.flows) {
const total = state.trafficEdges.reduce((s, e) => s + e.count, 0);
const f = state.flows;
// The collector only knows what it has seen since the pod started.
const win = f.coveredSec < f.windowSec - 30
? `${fmtDuration(f.coveredSec)} (из ${fmtDuration(f.windowSec)}: сбор идёт с запуска)`
? t(f.mode === 'OnDemand' ? 'status.onDemandPartial' : 'status.partial', { covered: fmtDuration(f.coveredSec), window: fmtDuration(f.windowSec) })
: fmtDuration(f.windowSec);
if (!f.connected) setStatus(`связь с Hubble потеряна (${f.error || 'нет ответа'}), данные могут устареть`, true);
const hint = state.trafficEdges.length > QUIET_AT ? ' — наведите на карточку, чтобы увидеть её трафик' : '';
if (!f.connected) setStatus(t('status.lost', { err: f.error || t('status.noAnswer') }), true);
const hint = state.trafficEdges.length > QUIET_AT ? t('status.hoverHint') : '';
if (!f.connected) return;
const more = hiddenPeers ? `; ещё ${plural(hiddenPeers, 'новое направление', 'новых направления', 'новых направлений')} — «Обновить»` : '';
const more = hiddenPeers ? t('status.more', { n: t('plural.newDirection', { n: hiddenPeers }) }) : '';
setStatus(state.trafficEdges.length
? `трафик за ${win}: ${plural(state.trafficEdges.length, 'направление', 'направления', 'направлений')}, ${plural(total, 'соединение', 'соединения', 'соединений')}${hint}${more}`
: `трафика за ${win} не видно${more}`);
? t('status.traffic', { window: win, edges: t('plural.direction', { n: state.trafficEdges.length }), conns: t('plural.connection', { n: total }), hint, more })
: t('status.noTraffic', { window: win, more }));
}
}
function fmtDuration(sec) {
if (sec < 90) return plural(Math.max(1, Math.round(sec)), 'секунду', 'секунды', 'секунд');
if (sec < 5400) return Math.round(sec / 60) + ' мин';
return plural(Math.round(sec / 3600), 'час', 'часа', 'часов');
if (sec < 90) return t('plural.second', { n: Math.max(1, Math.round(sec)) });
if (sec < 5400) return t('unit.min', { n: Math.round(sec / 60) });
return t('plural.hour', { n: Math.round(sec / 3600) });
}
function setStatus(text, isError = false) {
const s = $('#stage-status');
@@ -904,15 +907,15 @@ requestAnimationFrame(tick);
/* ---------- crumbs & legend ---------- */
function renderCrumbs() {
const c = $('#crumbs');
const parts = [el('button', { type: 'button', onclick: scopeCluster }, 'Кластер')];
const parts = [el('button', { type: 'button', onclick: scopeCluster }, t('tree.cluster'))];
if (state.scope.mode === 'ns') {
parts.push(el('span', { class: 'sep', 'aria-hidden': 'true' }, '›'));
for (const ns of state.scope.ns) {
parts.push(el('span', { class: 'chip' }, ns,
state.scope.ns.length > 1 ? el('button', { type: 'button', 'aria-label': 'Убрать ' + ns, onclick: () => scopeNs(ns, true) }, '×') : null));
state.scope.ns.length > 1 ? el('button', { type: 'button', 'aria-label': t('crumb.remove', { ns }), onclick: () => scopeNs(ns, true) }, '×') : null));
}
} else if (state.scope.mode === 'node') {
parts.push(el('span', { class: 'sep', 'aria-hidden': 'true' }, '›'), el('span', { class: 'chip' }, 'нода ' + state.scope.node));
parts.push(el('span', { class: 'sep', 'aria-hidden': 'true' }, '›'), el('span', { class: 'chip' }, t('node', { name: state.scope.node })));
}
const sel = state.selected && G.byId.get(state.selected);
if (sel) parts.push(el('span', { class: 'sep', 'aria-hidden': 'true' }, '›'), el('span', {}, `${KIND[sel.kind].title} ${sel.label}`));
@@ -922,17 +925,17 @@ function renderLegend() {
const l = $('#legend');
if (state.scope.mode === 'cluster') {
l.replaceChildren(
el('span', {}, 'Карточка — namespace, точка — худшее состояние его workload’ов:'),
el('span', {}, t('legend.cluster')),
...['ok', 'warn', 'error', 'idle'].map((h) => el('span', {}, el('span', { class: 'dot ' + h }), HEALTH_TEXT[h])),
);
return;
}
l.replaceChildren(
el('span', {}, el('span', { class: 'line config' }), 'по конфигурации (Ingress → Service → Pod)'),
el('span', {}, el('span', { class: 'line traffic' }), 'реальный трафик (Hubble)'),
el('span', {}, el('span', { class: 'line drop' }), 'есть drop'),
el('span', {}, 'пунктирная карточка — из другого namespace'),
el('span', {}, 'не собирается: пробы kubelet и трафик с хостов нод, DNS, cilium health'),
el('span', {}, el('span', { class: 'line config' }), t('legend.config')),
el('span', {}, el('span', { class: 'line traffic' }), t('legend.traffic')),
el('span', {}, el('span', { class: 'line drop' }), t('legend.drop')),
el('span', {}, t('legend.ghost')),
el('span', {}, t('legend.notCollected')),
);
}
@@ -980,15 +983,16 @@ function tabVisible(name, visible) {
}
const FACT_LABELS = {
replicas: 'Реплик', readyReplicas: 'Готово', desired: 'Нужно', ready: 'Готово', image: 'Образ', schedule: 'Расписание',
suspended: 'Пауза', active: 'Активных запусков', lastSuccess: 'Последний успех (UTC)', type: 'Тип', ports: 'Порты',
hosts: 'Хосты', class: 'IngressClass', os: 'ОС', kubelet: 'kubelet', controller: 'Контроллер', pods: 'Подов',
replicas: t('fact.replicas'), readyReplicas: t('fact.readyReplicas'), desired: t('fact.desired'), ready: t('fact.ready'),
image: t('fact.image'), schedule: t('fact.schedule'), suspended: t('fact.suspended'), active: t('fact.active'),
lastSuccess: t('fact.lastSuccess'), type: t('fact.type'), ports: t('fact.ports'), hosts: t('fact.hosts'), class: t('fact.class'),
os: t('fact.os'), kubelet: t('fact.kubelet'), controller: t('fact.controller'), pods: t('fact.pods'),
};
function openDetails(id) {
const n = G.byId.get(id);
if (!n) return;
detailsId = id;
showPanelHead(n.kind, n.label, n.namespace ? `namespace ${n.namespace}` : '');
showPanelHead(n.kind, n.label, n.namespace ? t('details.namespace', { ns: n.namespace }) : '');
const foreign = n.facts?.foreign === 'true';
tabVisible('yaml', !foreign);
tabVisible('logs', hasPods(n));
@@ -996,7 +1000,7 @@ function openDetails(id) {
const panel = document.querySelector('[data-panel="overview"]');
const dl = el('dl', { class: 'facts' });
const h = n.facts?.health;
if (h) dl.append(el('dt', {}, 'Состояние'), el('dd', {}, el('span', { class: 'status' }, el('span', { class: 'dot ' + h }), HEALTH_TEXT[h])));
if (h) dl.append(el('dt', {}, t('details.state')), el('dd', {}, el('span', { class: 'status' }, el('span', { class: 'dot ' + h }), HEALTH_TEXT[h])));
for (const [k, v] of Object.entries(n.facts || {})) {
if (k === 'health' || k === 'system' || k === 'foreign' || v === '') continue;
dl.append(el('dt', {}, FACT_LABELS[k] || k), el('dd', {}, v));
@@ -1004,7 +1008,7 @@ function openDetails(id) {
const parts = [dl];
const hosts = [...(G.placement.get(id) || [])].sort();
if (hosts.length) {
parts.push(el('div', { class: 'section-title' }, 'Работает на нодах'),
parts.push(el('div', { class: 'section-title' }, t('details.runsOn')),
el('ul', { class: 'link-list' }, hosts.map((host) => el('li', {}, el('button', { type: 'button', onclick: () => scopeNode(host) },
el('span', { html: iconSvg('node') }).firstChild, host)))));
}
@@ -1018,13 +1022,13 @@ function openDetails(id) {
function openExternalDetails(ep) {
detailsId = ep.id;
showPanelHead(ep.namespace ? (KIND[ep.kind] ? ep.kind : 'pod') : 'external', ep.label, ep.namespace ? `namespace ${ep.namespace}` : 'за пределами кластера или служебный адрес');
showPanelHead(ep.namespace ? (KIND[ep.kind] ? ep.kind : 'pod') : 'external', ep.label, ep.namespace ? t('details.namespace', { ns: ep.namespace }) : t('details.outside'));
tabVisible('yaml', false);
tabVisible('logs', false);
document.querySelector('[data-panel="overview"]').replaceChildren(
el('p', { class: 'muted' }, ep.namespace
? 'Этот workload есть в трафике, но его нет в графе: под без контроллера или уже удалён.'
: 'Адрес, с которым общались поды из текущего вида. Имя — из DNS, если Hubble его видел.'));
? t('details.ghostPod')
: t('details.external')));
renderLinks(ep.id);
setTab('overview');
}
@@ -1033,7 +1037,7 @@ function linkButton(id, meta, dropped) {
const n = G.byId.get(id);
const ep = state.flows?.endpoints.find((x) => x.id === id);
const kind = n?.kind || (ep?.namespace ? (KIND[ep.kind] ? ep.kind : 'pod') : 'external');
const label = n ? `${n.label}` : ep?.label || id;
const label = n ? n.label : ep ? epLabel(ep) : id;
const ns = n?.namespace || ep?.namespace;
return el('li', {}, el('button', { type: 'button', onclick: () => (n ? selectObject(id) : null) },
el('span', { html: iconSvg(kind) }).firstChild,
@@ -1044,34 +1048,34 @@ function renderLinks(id) {
const panel = document.querySelector('[data-panel="links"]');
const incoming = [], outgoing = [];
for (const e of G.cfgEdges) {
const what = e.kind === 'routes' ? 'маршрут' : 'селектор';
const what = e.kind === 'routes' ? t('link.route') : t('link.selector');
if (e.target === id) incoming.push(linkButton(e.source, what));
if (e.source === id) outgoing.push(linkButton(e.target, what));
}
const tIn = [], tOut = [];
for (const e of state.trafficEdges || []) {
const meta = `${e.ports.join(', ')} · ${e.count} соед.${e.fresh ? `, новых ${e.fresh}` : ''}${e.dropped ? ` · drop ${e.dropped}` : ''}`;
const meta = `${e.ports.join(', ')} · ${t('edge.conns', { n: e.count })}${e.fresh ? t('edge.new', { n: e.fresh }) : ''}${e.dropped ? t('edge.drop', { n: e.dropped }) : ''}`;
if (e.target === id) tIn.push(linkButton(e.source, meta, e.dropped));
if (e.source === id) tOut.push(linkButton(e.target, meta, e.dropped));
}
const section = (title, items, empty) => [el('div', { class: 'section-title' }, title),
items.length ? el('ul', { class: 'link-list' }, items) : el('p', { class: 'muted small' }, empty)];
const trafficNote = !state.traffic ? 'трафик выключен' : state.flowsError ? 'трафик недоступен' : 'нет за выбранное окно';
const trafficNote = !state.traffic || state.flows?.mode === 'Disabled' ? t('link.trafficOff') : state.flowsError ? t('link.trafficFailed') : t('link.noTraffic');
panel.replaceChildren(
...section('Конфигурация: кто ссылается сюда', incoming, 'нет'),
...section('Конфигурация: куда ссылается', outgoing, 'нет'),
...section('Трафик: входящие соединения', tIn, trafficNote),
...section('Трафик: исходящие соединения', tOut, trafficNote),
...section(t('link.cfgIn'), incoming, t('link.none')),
...section(t('link.cfgOut'), outgoing, t('link.none')),
...section(t('link.trafficIn'), tIn, trafficNote),
...section(t('link.trafficOut'), tOut, trafficNote),
);
}
async function loadYaml(n) {
const pre = $('#d-yaml');
if (yamlCache.has(n.id)) { pre.textContent = yamlCache.get(n.id); return; }
pre.textContent = 'загрузка…';
pre.textContent = t('loading');
const p = new URLSearchParams({ kind: n.kind, namespace: n.namespace || '', name: n.label });
const r = await fetch('/api/resource?' + p);
const text = r.ok ? await r.text() : 'не удалось получить манифест: HTTP ' + r.status;
const text = r.ok ? await r.text() : t('yaml.failed', { code: r.status });
if (r.ok) yamlCache.set(n.id, text);
if (detailsId === n.id) pre.textContent = text;
}
@@ -1081,7 +1085,7 @@ async function loadPods(n) {
if (podsFor === n.id) return;
podsFor = n.id;
const podSel = $('#pod-select'), cSel = $('#container-select'), out = $('#d-logs');
podSel.replaceChildren(el('option', {}, 'загрузка…'));
podSel.replaceChildren(el('option', {}, t('loading')));
cSel.replaceChildren();
out.textContent = '';
const p = new URLSearchParams({ id: n.id, namespace: n.namespace });
@@ -1089,8 +1093,8 @@ async function loadPods(n) {
const pods = r.ok ? await r.json() : [];
if (detailsId !== n.id) return;
if (!pods.length) {
podSel.replaceChildren(el('option', { value: '' }, 'нет живых подов'));
out.textContent = 'У этого workload сейчас нет подов.';
podSel.replaceChildren(el('option', { value: '' }, t('logs.noPods')));
out.textContent = t('logs.noPodsText');
return;
}
podSel.replaceChildren(...pods.map((pod) => el('option', { value: pod.name }, `${pod.name} · ${pod.phase} · ${pod.nodeName}`)));
@@ -1108,10 +1112,10 @@ async function loadLogs() {
const pod = $('#pod-select').value;
if (!n || !pod) return;
const out = $('#d-logs');
out.textContent = 'загрузка логов…';
out.textContent = t('logs.loading');
const p = new URLSearchParams({ namespace: n.namespace, pod, container: $('#container-select').value || '' });
const r = await fetch('/api/logs?' + p);
const text = r.ok ? (await r.text()) || '(лог пуст)' : 'не удалось получить логи: HTTP ' + r.status;
const text = r.ok ? (await r.text()) || t('logs.empty') : t('logs.failed', { code: r.status });
if (detailsId === n.id) { out.textContent = text; out.scrollTop = out.scrollHeight; }
}
$('#logs-reload').addEventListener('click', loadLogs);
@@ -1129,16 +1133,16 @@ matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
});
async function load() {
setStatus('загрузка графа…');
setStatus(t('status.loadingGraph'));
const r = await fetch('/api/graph');
if (!r.ok) { setStatus('не удалось загрузить граф: HTTP ' + r.status, true); return; }
if (!r.ok) { setStatus(t('status.graphFailed', { code: r.status }), true); return; }
indexGraph(await r.json());
podsFor = null;
yamlCache.clear();
if (state.scope.mode === 'ns') state.scope.ns = state.scope.ns.filter((ns) => G.byNs.has(ns));
if (state.scope.mode === 'ns' && !state.scope.ns.length) state.scope = { mode: 'cluster' };
if (state.selected && !G.byId.has(state.selected)) state.selected = null;
$('#updated').textContent = 'обновлено ' + new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
$('#updated').textContent = t('updated', { time: new Date().toLocaleTimeString(LANG, { hour: '2-digit', minute: '2-digit' }) });
if (state.selected) revealInTree(state.selected);
await renderMap();
if (state.selected) { openDetails(state.selected); focusOnMap(state.selected); }
@@ -1153,6 +1157,9 @@ window.addEventListener('hashchange', () => {
renderMap().then(() => state.selected && focusOnMap(state.selected));
});
applyStaticI18n();
$('#lang').value = LANG;
$('#lang').addEventListener('change', (e) => setLang(e.target.value));
readTheme();
cy.style(mapStyle());
readHash();
+159
View File
@@ -0,0 +1,159 @@
'use strict';
/* UI strings in English and Russian. Language: ?lang=, then the saved
choice, then the browser. Plural forms go through Intl.PluralRules, so
every plural key has one entry per category the language uses. */
const I18N = {
en: {
'kind.pod': 'Controller', 'kind.external': 'External', 'folder.pod': 'Other controllers',
'health.ok': 'healthy', 'health.warn': 'partly ready', 'health.error': 'not ready', 'health.idle': 'stopped',
'sub.ready': '{ready}/{want} ready', 'sub.onNodes': '{ready}/{want} on nodes', 'sub.paused': '{schedule} · suspended',
'tree.cluster': 'Cluster', 'tree.apps': 'Applications', 'tree.system': 'System ({prefixes})', 'group.apps': 'Applications', 'group.system': 'System',
'node': 'node {name}',
'edge.conns': '{n} conn.', 'edge.new': ', {n} new', 'edge.drop': ' · drop {n}',
'status.loadingTraffic': 'loading traffic…', 'status.loadingGraph': 'loading graph…',
'status.graphFailed': 'could not load the graph: HTTP {code}', 'status.empty': 'nothing here',
'status.noRelay': 'no connection to Hubble Relay', 'status.trafficFailed': 'traffic unavailable: {err}',
'status.partial': '{covered} (of {window}: collecting since start)',
'status.onDemandPartial': '{covered} (of {window}: collecting since the map was opened)',
'status.lost': 'lost connection to Hubble ({err}), data may be stale', 'status.noAnswer': 'no answer',
'status.hoverHint': ' — hover a card to see its traffic',
'status.more': '; {n} more — press "Refresh"',
'status.traffic': 'traffic over {window}: {edges}, {conns}{hint}{more}', 'status.noTraffic': 'no traffic over {window}{more}',
'status.trafficOff': 'traffic collection is disabled in the module settings',
'plural.direction': { one: '{n} direction', other: '{n} directions' },
'plural.newDirection': { one: '{n} new direction', other: '{n} new directions' },
'plural.connection': { one: '{n} connection', other: '{n} connections' },
'plural.second': { one: '{n} second', other: '{n} seconds' },
'plural.hour': { one: '{n} hour', other: '{n} hours' },
'unit.min': '{n} min',
'crumb.remove': 'Remove {ns}',
'legend.cluster': 'Card — namespace, dot — the worst state of its workloads:',
'legend.config': 'configuration (Ingress → Service → Pod)', 'legend.traffic': 'real traffic (Hubble)',
'legend.drop': 'dropped', 'legend.ghost': 'dashed card — from another namespace',
'legend.notCollected': 'not collected: kubelet probes and node host traffic, DNS, cilium health',
'fact.replicas': 'Replicas', 'fact.readyReplicas': 'Ready', 'fact.desired': 'Desired', 'fact.ready': 'Ready', 'fact.image': 'Image',
'fact.schedule': 'Schedule', 'fact.suspended': 'Suspended', 'fact.active': 'Active runs', 'fact.lastSuccess': 'Last success (UTC)',
'fact.type': 'Type', 'fact.ports': 'Ports', 'fact.hosts': 'Hosts', 'fact.class': 'IngressClass', 'fact.os': 'OS',
'fact.kubelet': 'kubelet', 'fact.controller': 'Controller', 'fact.pods': 'Pods',
'details.state': 'State', 'details.runsOn': 'Runs on nodes', 'details.namespace': 'namespace {ns}',
'details.outside': 'outside the cluster or a service address',
'details.ghostPod': 'This workload shows up in traffic but not in the graph: a pod without a controller, or already deleted.',
'details.external': 'An address the pods in this view talked to. The name comes from DNS if Hubble saw the lookup.',
'link.route': 'route', 'link.selector': 'selector', 'link.none': 'none',
'link.trafficOff': 'traffic is off', 'link.trafficFailed': 'traffic unavailable', 'link.noTraffic': 'none in the selected window',
'link.cfgIn': 'Configuration: what points here', 'link.cfgOut': 'Configuration: what this points to',
'link.trafficIn': 'Traffic: incoming connections', 'link.trafficOut': 'Traffic: outgoing connections',
'loading': 'loading…', 'yaml.failed': 'could not get the manifest: HTTP {code}',
'logs.noPods': 'no live pods', 'logs.noPodsText': 'This workload has no pods right now.', 'logs.loading': 'loading logs…',
'logs.empty': '(log is empty)', 'logs.failed': 'could not get logs: HTTP {code}',
'updated': 'updated {time}',
'ext.world': 'world', 'ext.remote-node': 'remote nodes', 'ext.kube-apiserver': 'kube-apiserver', 'ext.health': 'cilium health',
'html.traffic': 'Traffic', 'html.window': 'Traffic window', 'html.min5': '5 min', 'html.min15': '15 min', 'html.hour': '1 hour',
'html.refresh': 'Refresh', 'html.inventory': 'Inventory', 'html.grouping': 'Grouping', 'html.nodes': 'Nodes',
'html.search': 'Search: name, namespace, image…', 'html.searchLabel': 'Search the inventory', 'html.treeLabel': 'Cluster objects',
'html.hint': 'Click to open on the map. Ctrl+click a namespace to add it to the current view.',
'html.map': 'Map', 'html.zoomIn': 'Zoom in', 'html.zoomOut': 'Zoom out', 'html.fit': 'Fit', 'html.zoom': 'Zoom',
'html.details': 'Object details', 'html.close': 'Close panel', 'html.sections': 'Sections',
'html.overview': 'Overview', 'html.links': 'Links', 'html.logs': 'Logs', 'html.pod': 'Pod', 'html.container': 'Container',
'html.view': 'Current view', 'html.lang': 'Language',
},
ru: {
'kind.pod': 'Контроллер', 'kind.external': 'Внешний', 'folder.pod': 'Другие контроллеры',
'health.ok': 'в норме', 'health.warn': 'готов частично', 'health.error': 'не готов', 'health.idle': 'выключен',
'sub.ready': '{ready}/{want} готово', 'sub.onNodes': '{ready}/{want} на нодах', 'sub.paused': '{schedule} · пауза',
'tree.cluster': 'Кластер', 'tree.apps': 'Приложения', 'tree.system': 'Системные ({prefixes})', 'group.apps': 'Приложения', 'group.system': 'Системные',
'node': 'нода {name}',
'edge.conns': '{n} соед.', 'edge.new': ', новых {n}', 'edge.drop': ' · drop {n}',
'status.loadingTraffic': 'загрузка трафика…', 'status.loadingGraph': 'загрузка графа…',
'status.graphFailed': 'не удалось загрузить граф: HTTP {code}', 'status.empty': 'здесь нет объектов',
'status.noRelay': 'нет связи с Hubble Relay', 'status.trafficFailed': 'трафик недоступен: {err}',
'status.partial': '{covered} (из {window}: сбор идёт с запуска)',
'status.onDemandPartial': '{covered} (из {window}: сбор идёт с открытия карты)',
'status.lost': 'связь с Hubble потеряна ({err}), данные могут устареть', 'status.noAnswer': 'нет ответа',
'status.hoverHint': ' — наведите на карточку, чтобы увидеть её трафик',
'status.more': '; ещё {n} — «Обновить»',
'status.traffic': 'трафик за {window}: {edges}, {conns}{hint}{more}', 'status.noTraffic': 'трафика за {window} не видно{more}',
'status.trafficOff': 'сбор трафика выключен в настройках модуля',
'plural.direction': { one: '{n} направление', few: '{n} направления', many: '{n} направлений', other: '{n} направления' },
'plural.newDirection': { one: '{n} новое направление', few: '{n} новых направления', many: '{n} новых направлений', other: '{n} новых направления' },
'plural.connection': { one: '{n} соединение', few: '{n} соединения', many: '{n} соединений', other: '{n} соединения' },
'plural.second': { one: '{n} секунду', few: '{n} секунды', many: '{n} секунд', other: '{n} секунды' },
'plural.hour': { one: '{n} час', few: '{n} часа', many: '{n} часов', other: '{n} часа' },
'unit.min': '{n} мин',
'crumb.remove': 'Убрать {ns}',
'legend.cluster': 'Карточка — namespace, точка — худшее состояние его workload’ов:',
'legend.config': 'по конфигурации (Ingress → Service → Pod)', 'legend.traffic': 'реальный трафик (Hubble)',
'legend.drop': 'есть drop', 'legend.ghost': 'пунктирная карточка — из другого namespace',
'legend.notCollected': 'не собирается: пробы kubelet и трафик с хостов нод, DNS, cilium health',
'fact.replicas': 'Реплик', 'fact.readyReplicas': 'Готово', 'fact.desired': 'Нужно', 'fact.ready': 'Готово', 'fact.image': 'Образ',
'fact.schedule': 'Расписание', 'fact.suspended': 'Пауза', 'fact.active': 'Активных запусков', 'fact.lastSuccess': 'Последний успех (UTC)',
'fact.type': 'Тип', 'fact.ports': 'Порты', 'fact.hosts': 'Хосты', 'fact.class': 'IngressClass', 'fact.os': 'ОС',
'fact.kubelet': 'kubelet', 'fact.controller': 'Контроллер', 'fact.pods': 'Подов',
'details.state': 'Состояние', 'details.runsOn': 'Работает на нодах', 'details.namespace': 'namespace {ns}',
'details.outside': 'за пределами кластера или служебный адрес',
'details.ghostPod': 'Этот workload есть в трафике, но его нет в графе: под без контроллера или уже удалён.',
'details.external': 'Адрес, с которым общались поды из текущего вида. Имя — из DNS, если Hubble видел запрос.',
'link.route': 'маршрут', 'link.selector': 'селектор', 'link.none': 'нет',
'link.trafficOff': 'трафик выключен', 'link.trafficFailed': 'трафик недоступен', 'link.noTraffic': 'нет за выбранное окно',
'link.cfgIn': 'Конфигурация: кто ссылается сюда', 'link.cfgOut': 'Конфигурация: куда ссылается',
'link.trafficIn': 'Трафик: входящие соединения', 'link.trafficOut': 'Трафик: исходящие соединения',
'loading': 'загрузка…', 'yaml.failed': 'не удалось получить манифест: HTTP {code}',
'logs.noPods': 'нет живых подов', 'logs.noPodsText': 'У этого workload сейчас нет подов.', 'logs.loading': 'загрузка логов…',
'logs.empty': '(лог пуст)', 'logs.failed': 'не удалось получить логи: HTTP {code}',
'updated': 'обновлено {time}',
'ext.world': 'интернет', 'ext.remote-node': 'другие ноды', 'ext.kube-apiserver': 'kube-apiserver', 'ext.health': 'cilium health',
'html.traffic': 'Трафик', 'html.window': 'Окно трафика', 'html.min5': '5 мин', 'html.min15': '15 мин', 'html.hour': '1 час',
'html.refresh': 'Обновить', 'html.inventory': 'Инвентарь', 'html.grouping': 'Группировка', 'html.nodes': 'Ноды',
'html.search': 'Поиск: имя, namespace, образ…', 'html.searchLabel': 'Поиск по инвентарю', 'html.treeLabel': 'Объекты кластера',
'html.hint': 'Клик — открыть на карте. Ctrl+клик по namespace — добавить к текущему виду.',
'html.map': 'Карта', 'html.zoomIn': 'Приблизить', 'html.zoomOut': 'Отдалить', 'html.fit': 'Показать всё', 'html.zoom': 'Масштаб',
'html.details': 'Детали объекта', 'html.close': 'Закрыть панель', 'html.sections': 'Разделы',
'html.overview': 'Обзор', 'html.links': 'Связи', 'html.logs': 'Логи', 'html.pod': 'Под', 'html.container': 'Контейнер',
'html.view': 'Текущий вид', 'html.lang': 'Язык',
},
};
function pickLang() {
const q = new URLSearchParams(location.search).get('lang');
if (q && I18N[q]) return q;
try {
const saved = localStorage.getItem('cluster-map.lang');
if (saved && I18N[saved]) return saved;
} catch { /* storage unavailable */ }
return (navigator.language || 'en').toLowerCase().startsWith('ru') ? 'ru' : 'en';
}
const LANG = pickLang();
const pluralRules = new Intl.PluralRules(LANG);
function fill(s, params) {
return s.replace(/\{(\w+)\}/g, (_, k) => (params[k] ?? `{${k}}`));
}
// t('key', {param}) — plain string; t('plural.key', {n}) — picks the form.
function t(key, params = {}) {
const dict = I18N[LANG];
const v = dict[key] ?? I18N.en[key] ?? key;
if (typeof v === 'object') return fill(v[pluralRules.select(params.n)] ?? v.other, params);
return fill(v, params);
}
function setLang(lang) {
try { localStorage.setItem('cluster-map.lang', lang); } catch { /* storage unavailable */ }
const u = new URL(location.href);
u.searchParams.delete('lang');
location.replace(u);
}
// Elements with data-i18n get textContent, data-i18n-attr="attr:key;attr:key" gets attributes.
function applyStaticI18n(root = document) {
document.documentElement.lang = LANG;
for (const el of root.querySelectorAll('[data-i18n]')) el.textContent = t(el.dataset.i18n);
for (const el of root.querySelectorAll('[data-i18n-attr]')) {
for (const pair of el.dataset.i18nAttr.split(';')) {
const [attr, key] = pair.split(':');
el.setAttribute(attr, t(key));
}
}
}
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="#1d2a44"/><g fill="none" stroke="#6aa0ff" stroke-width="3" stroke-linecap="round"><path d="M20 22 32 32l12-10M32 32v14"/></g><g fill="#6aa0ff"><circle cx="20" cy="22" r="6"/><circle cx="44" cy="22" r="6"/><circle cx="32" cy="46" r="6"/></g><circle cx="32" cy="32" r="5" fill="#3fcf7f"/></svg>

After

Width:  |  Height:  |  Size: 396 B

@@ -0,0 +1,86 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>cluster-map</title>
<link rel="icon" href="icon.svg" type="image/svg+xml">
<link rel="stylesheet" href="app.css">
<script src="i18n.js"></script>
<script src="vendor/cytoscape.min.js"></script>
<script src="vendor/elk.bundled.js"></script>
</head>
<body>
<header class="topbar">
<div class="brand">cluster-map</div>
<nav class="crumbs" id="crumbs" data-i18n-attr="aria-label:html.view"></nav>
<div class="topbar-actions">
<label class="toggle"><input type="checkbox" id="traffic-on" checked> <span data-i18n="html.traffic"></span></label>
<select id="traffic-window" data-i18n-attr="aria-label:html.window">
<option value="300" data-i18n="html.min5"></option>
<option value="900" data-i18n="html.min15"></option>
<option value="3600" data-i18n="html.hour"></option>
</select>
<button type="button" id="reload" class="btn" data-i18n="html.refresh"></button>
<span class="muted small" id="updated"></span>
<select id="lang" data-i18n-attr="aria-label:html.lang">
<option value="en">EN</option>
<option value="ru">RU</option>
</select>
</div>
</header>
<div class="layout">
<aside class="sidebar" data-i18n-attr="aria-label:html.inventory">
<div class="seg" role="tablist" data-i18n-attr="aria-label:html.grouping">
<button type="button" role="tab" id="view-ns" aria-selected="true" aria-controls="tree">Namespaces</button>
<button type="button" role="tab" id="view-nodes" aria-selected="false" aria-controls="tree" data-i18n="html.nodes"></button>
</div>
<input type="search" id="tree-filter" data-i18n-attr="placeholder:html.search;aria-label:html.searchLabel">
<ul class="tree" id="tree" role="tree" data-i18n-attr="aria-label:html.treeLabel"></ul>
<p class="hint" data-i18n="html.hint"></p>
</aside>
<main class="stage">
<div id="cy" data-i18n-attr="aria-label:html.map"></div>
<div class="stage-status" id="stage-status" role="status" aria-live="polite"></div>
<div class="zoom" role="group" data-i18n-attr="aria-label:html.zoom">
<button type="button" class="btn icon" id="zoom-in" data-i18n-attr="aria-label:html.zoomIn">+</button>
<button type="button" class="btn icon" id="zoom-out" data-i18n-attr="aria-label:html.zoomOut">−</button>
<button type="button" class="btn icon" id="zoom-fit" data-i18n-attr="aria-label:html.fit">⤢</button>
</div>
<div class="legend" id="legend"></div>
</main>
<aside class="details" id="details" data-i18n-attr="aria-label:html.details" hidden>
<div class="details-head">
<div class="details-title">
<span class="kind-chip" id="d-kind"></span>
<h2 id="d-name"></h2>
<div class="muted small" id="d-sub"></div>
</div>
<button type="button" class="btn icon" id="d-close" data-i18n-attr="aria-label:html.close">×</button>
</div>
<div class="tabs" role="tablist" data-i18n-attr="aria-label:html.sections">
<button type="button" role="tab" data-tab="overview" aria-selected="true" data-i18n="html.overview"></button>
<button type="button" role="tab" data-tab="links" aria-selected="false" data-i18n="html.links"></button>
<button type="button" role="tab" data-tab="yaml" aria-selected="false">YAML</button>
<button type="button" role="tab" data-tab="logs" aria-selected="false" data-i18n="html.logs"></button>
</div>
<section class="tab-panel" data-panel="overview" role="tabpanel"></section>
<section class="tab-panel" data-panel="links" role="tabpanel" hidden></section>
<section class="tab-panel" data-panel="yaml" role="tabpanel" hidden><pre class="code" id="d-yaml"></pre></section>
<section class="tab-panel" data-panel="logs" role="tabpanel" hidden>
<div class="logs-bar">
<select id="pod-select" data-i18n-attr="aria-label:html.pod"></select>
<select id="container-select" data-i18n-attr="aria-label:html.container"></select>
<button type="button" class="btn" id="logs-reload" data-i18n="html.refresh"></button>
</div>
<pre class="code" id="d-logs"></pre>
</section>
</aside>
</div>
<script src="app.js"></script>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
---
image: {{ .ModuleName }}/{{ .ImageName }}-build
fromImage: builder/golang-alpine
final: false
git:
- add: {{ .ModuleDir }}images/{{ .ImageName }}/src
to: /src
stageDependencies:
install:
- go.mod
- go.sum
setup:
- '**/*'
shell:
install:
- cd /src && go mod download
setup:
- cd /src && CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /cluster-map ./cmd/cluster-map
---
image: {{ .ModuleName }}/{{ .ImageName }}
fromImage: base/distroless
import:
- image: {{ .ModuleName }}/{{ .ImageName }}-build
add: /cluster-map
to: /cluster-map
before: setup
imageSpec:
config:
entrypoint: ["/cluster-map"]
-87
View File
@@ -1,87 +0,0 @@
package main
import (
"fmt"
"time"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/informers"
appslisters "k8s.io/client-go/listers/apps/v1"
batchlisters "k8s.io/client-go/listers/batch/v1"
corelisters "k8s.io/client-go/listers/core/v1"
netlisters "k8s.io/client-go/listers/networking/v1"
)
var (
nsLister corelisters.NamespaceLister
podLister corelisters.PodLister
svcLister corelisters.ServiceLister
nodeLister corelisters.NodeLister
deployLister appslisters.DeploymentLister
stsLister appslisters.StatefulSetLister
dsLister appslisters.DaemonSetLister
cronLister batchlisters.CronJobLister
ingLister netlisters.IngressLister
)
func startInformers() error {
f := informers.NewSharedInformerFactoryWithOptions(clientset, 0,
// managedFields is most of a cached object's size and nothing here reads it
informers.WithTransform(func(obj any) (any, error) {
if a, err := meta.Accessor(obj); err == nil {
a.SetManagedFields(nil)
}
return obj, nil
}))
nsLister = f.Core().V1().Namespaces().Lister()
podLister = f.Core().V1().Pods().Lister()
svcLister = f.Core().V1().Services().Lister()
nodeLister = f.Core().V1().Nodes().Lister()
deployLister = f.Apps().V1().Deployments().Lister()
stsLister = f.Apps().V1().StatefulSets().Lister()
dsLister = f.Apps().V1().DaemonSets().Lister()
cronLister = f.Batch().V1().CronJobs().Lister()
ingLister = f.Networking().V1().Ingresses().Lister()
stop := make(chan struct{})
f.Start(stop)
done := make(chan map[string]bool, 1)
go func() {
synced := map[string]bool{}
for t, ok := range f.WaitForCacheSync(stop) {
synced[fmt.Sprint(t)] = ok
}
done <- synced
}()
select {
case synced := <-done:
for t, ok := range synced {
if !ok {
return fmt.Errorf("cache for %s did not sync", t)
}
}
return nil
case <-time.After(90 * time.Second):
return fmt.Errorf("caches did not sync in 90s")
}
}
type listOf[T any] struct{ Items []T }
// listAll reads a lister into the same shape a typed List() call returns,
// so graph code iterates .Items unchanged. Items are copies: callers may not
// mutate cached objects, and copying the top-level struct is cheap.
func listAll[T any](l interface {
List(labels.Selector) ([]*T, error)
}) (*listOf[T], error) {
ptrs, err := l.List(labels.Everything())
if err != nil {
return nil, err
}
out := &listOf[T]{Items: make([]T, len(ptrs))}
for i, p := range ptrs {
out.Items[i] = *p
}
return out, nil
}
-659
View File
@@ -1,659 +0,0 @@
// cluster-map: a live topology view of a Deckhouse/Kubernetes cluster.
//
// Builds a graph on every request to /api/graph from informer caches:
// namespaces group workloads, which connect to Services (by label-selector
// match) and Ingresses (by backend reference). Informers keep the caches
// in step with the API by watch; a fresh List per request cost ~0.9 s and
// timed out the 1 s probe.
package main
import (
"context"
"encoding/json"
"io"
"log"
"net/http"
"sort"
"strings"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/yaml"
)
type Node struct {
ID string `json:"id"`
Label string `json:"label"`
Kind string `json:"kind"` // namespace | deployment | statefulset | daemonset | cronjob | service | ingress | node
Namespace string `json:"namespace"` // empty for namespace/node kind
Parent string `json:"parent,omitempty"`
NodeName string `json:"nodeName,omitempty"` // physical node a workload's pods land on, if known
Facts map[string]string `json:"facts,omitempty"` // short summary shown in the sidebar without a follow-up fetch
}
type Edge struct {
ID string `json:"id"`
Source string `json:"source"`
Target string `json:"target"`
Kind string `json:"kind"` // selects | routes | schedules-on
}
type Graph struct {
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
}
var clientset *kubernetes.Clientset
func main() {
cfg, err := rest.InClusterConfig()
if err != nil {
log.Fatalf("not running in-cluster and no kubeconfig fallback wired up: %v", err)
}
clientset, err = kubernetes.NewForConfig(cfg)
if err != nil {
log.Fatalf("building clientset: %v", err)
}
if err := startInformers(); err != nil {
log.Fatalf("informers: %v", err)
}
startHubble()
mux := http.NewServeMux()
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("ok")) })
mux.HandleFunc("/api/flows", handleFlows)
mux.HandleFunc("/api/graph", handleGraph)
mux.HandleFunc("/api/resource", handleResource)
mux.HandleFunc("/api/pods", handlePods)
mux.HandleFunc("/api/logs", handleLogs)
mux.Handle("/", http.FileServer(http.Dir("./static")))
addr := ":8080"
log.Printf("cluster-map listening on %s", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}
func handleGraph(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
g, err := buildGraph(ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(g)
}
// selectorSubset reports whether every key/value in sel is present in labels --
// the standard Kubernetes rule for whether a Service's spec.selector matches a
// pod template's labels.
func selectorSubset(sel, labels map[string]string) bool {
if len(sel) == 0 {
return false // an empty selector matches everything in real k8s, but showing an edge to "everything" is useless noise here
}
for k, v := range sel {
if labels[k] != v {
return false
}
}
return true
}
func buildGraph(ctx context.Context) (*Graph, error) {
g := &Graph{}
namespaces, err := listAll[corev1.Namespace](nsLister)
if err != nil {
return nil, err
}
for _, ns := range namespaces.Items {
system := strings.HasPrefix(ns.Name, "d8-") || ns.Name == "kube-system" || ns.Name == "kube-public" || ns.Name == "kube-node-lease"
g.Nodes = append(g.Nodes, Node{
ID: "ns/" + ns.Name,
Label: ns.Name,
Kind: "namespace",
Facts: map[string]string{"system": boolStr(system)},
})
}
// pod-template-labels indexed by namespace, used to match Services to
// their owning workload below.
type workloadRef struct {
id string
labels map[string]string
}
var workloads []workloadRef
deployments, err := listAll[appsv1.Deployment](deployLister)
if err != nil {
return nil, err
}
for _, d := range deployments.Items {
id := workloadID(d.Namespace, "deployment", d.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "deployment", d.Namespace, d.Name, deploymentFacts(d)))
workloads = append(workloads, workloadRef{id, d.Spec.Template.Labels})
}
statefulsets, err := listAll[appsv1.StatefulSet](stsLister)
if err != nil {
return nil, err
}
for _, s := range statefulsets.Items {
id := workloadID(s.Namespace, "statefulset", s.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "statefulset", s.Namespace, s.Name, statefulsetFacts(s)))
workloads = append(workloads, workloadRef{id, s.Spec.Template.Labels})
}
daemonsets, err := listAll[appsv1.DaemonSet](dsLister)
if err != nil {
return nil, err
}
for _, ds := range daemonsets.Items {
id := workloadID(ds.Namespace, "daemonset", ds.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "daemonset", ds.Namespace, ds.Name, daemonsetFacts(ds)))
workloads = append(workloads, workloadRef{id, ds.Spec.Template.Labels})
}
cronjobs, err := listAll[batchv1.CronJob](cronLister)
if err != nil {
return nil, err
}
for _, cj := range cronjobs.Items {
id := workloadID(cj.Namespace, "cronjob", cj.Name)
g.Nodes = append(g.Nodes, workloadNode(id, "cronjob", cj.Namespace, cj.Name, cronjobFacts(cj)))
// CronJob pods don't back a Service, so no labels needed for matching.
}
// Pods whose controller is not a native workload (kruise Advanced
// DaemonSet behind ingress-nginx, database operators, bare Jobs) would
// otherwise be invisible. They become workload nodes of their own, IDed
// the way Hubble names workloads, so traffic attaches to them too.
pods, err := listAll[corev1.Pod](podLister)
if err != nil {
return nil, err
}
known := map[string]bool{}
for _, n := range g.Nodes {
known[n.ID] = true
}
type foreignWl struct {
ns, kind, name, controller string
pods, ready int
labels map[string]string
}
foreign := map[string]*foreignWl{}
for _, p := range pods.Items {
kind, name, ctrl := podOwner(p)
if kind == "" {
continue
}
id := workloadID(p.Namespace, kind, name)
if known[id] {
continue
}
f := foreign[id]
if f == nil {
f = &foreignWl{ns: p.Namespace, kind: kind, name: name, controller: ctrl, labels: p.Labels}
foreign[id] = f
}
if p.Status.Phase == corev1.PodSucceeded {
continue
}
f.pods++
if podReady(p) {
f.ready++
}
}
for id, f := range foreign {
kind := f.kind
switch kind {
case "deployment", "statefulset", "daemonset", "cronjob":
default:
kind = "pod"
}
n := workloadNode(id, kind, f.ns, f.name, map[string]string{
"controller": f.controller,
"pods": itoa(f.pods),
"ready": itoa(f.ready),
"health": health(f.pods, f.ready),
"foreign": "true",
})
g.Nodes = append(g.Nodes, n)
workloads = append(workloads, workloadRef{id, f.labels})
}
services, err := listAll[corev1.Service](svcLister)
if err != nil {
return nil, err
}
for _, svc := range services.Items {
id := "service/" + svc.Namespace + "/" + svc.Name
g.Nodes = append(g.Nodes, Node{
ID: id, Label: svc.Name, Kind: "service", Namespace: svc.Namespace, Parent: "ns/" + svc.Namespace,
Facts: serviceFacts(svc),
})
for _, wl := range workloads {
if !strings.HasPrefix(wl.id, "wl/"+svc.Namespace+"/") {
continue
}
if selectorSubset(svc.Spec.Selector, wl.labels) {
g.Edges = append(g.Edges, Edge{ID: wl.id + "->" + id, Source: wl.id, Target: id, Kind: "selects"})
}
}
}
ingresses, err := listAll[networkingv1.Ingress](ingLister)
if err != nil {
return nil, err
}
for _, ing := range ingresses.Items {
id := "ingress/" + ing.Namespace + "/" + ing.Name
g.Nodes = append(g.Nodes, Node{
ID: id, Label: ing.Name, Kind: "ingress", Namespace: ing.Namespace, Parent: "ns/" + ing.Namespace,
Facts: ingressFacts(ing),
})
for _, svcName := range ingressBackendServices(ing) {
target := "service/" + ing.Namespace + "/" + svcName
g.Edges = append(g.Edges, Edge{ID: id + "->" + target, Source: id, Target: target, Kind: "routes"})
}
}
// Physical nodes as a separate, non-namespaced layer, linked from each
// workload to wherever its pods actually run right now -- this is the
// "what's deployed where" question specifically, not covered by the
// Service/Ingress graph above.
nodes, err := listAll[corev1.Node](nodeLister)
if err != nil {
return nil, err
}
for _, n := range nodes.Items {
g.Nodes = append(g.Nodes, Node{ID: "node/" + n.Name, Label: n.Name, Kind: "node", Facts: nodeFacts(n)})
}
seenPlacement := map[string]bool{}
for _, p := range pods.Items {
if p.Spec.NodeName == "" {
continue
}
ownerWl := ownerWorkloadID(p)
if ownerWl == "" {
continue
}
key := ownerWl + "@" + p.Spec.NodeName
if seenPlacement[key] {
continue
}
seenPlacement[key] = true
g.Edges = append(g.Edges, Edge{ID: key, Source: ownerWl, Target: "node/" + p.Spec.NodeName, Kind: "schedules-on"})
}
sort.Slice(g.Nodes, func(i, j int) bool { return g.Nodes[i].ID < g.Nodes[j].ID })
sort.Slice(g.Edges, func(i, j int) bool { return g.Edges[i].ID < g.Edges[j].ID })
return g, nil
}
// podOwner names the workload a pod belongs to the way Hubble does
// (cilium's GetWorkloadMetaFromPod): ReplicaSet -> its Deployment, a Job
// whose name ends in the scheduler's numeric suffix -> its CronJob, any
// other controller kind as-is. controller is "<apiVersion> <Kind>".
func podOwner(p corev1.Pod) (kind, name, controller string) {
var o *metav1.OwnerReference
for i := range p.OwnerReferences {
if p.OwnerReferences[i].Controller != nil && *p.OwnerReferences[i].Controller {
o = &p.OwnerReferences[i]
break
}
}
if o == nil && len(p.OwnerReferences) > 0 {
o = &p.OwnerReferences[0]
}
if o == nil {
return "", "", ""
}
controller = o.APIVersion + " " + o.Kind
switch o.Kind {
case "Node":
// static pod mirrored by the kubelet: "<component>-<node>", grouped
// per component across nodes like a DaemonSet would be
return "staticpod", strings.TrimSuffix(p.Name, "-"+p.Spec.NodeName), "static pod (kubelet)"
case "ReplicaSet":
if i := strings.LastIndex(o.Name, "-"); i > 0 {
return "deployment", o.Name[:i], controller
}
case "Job":
if i := strings.LastIndex(o.Name, "-"); i > 0 && allDigits(o.Name[i+1:]) {
return "cronjob", o.Name[:i], controller
}
}
return strings.ToLower(o.Kind), o.Name, controller
}
func allDigits(s string) bool {
if s == "" {
return false
}
for _, c := range s {
if c < '0' || c > '9' {
return false
}
}
return true
}
func podReady(p corev1.Pod) bool {
for _, c := range p.Status.Conditions {
if c.Type == corev1.PodReady {
return c.Status == corev1.ConditionTrue
}
}
return false
}
func ownerWorkloadID(p corev1.Pod) string {
kind, name, _ := podOwner(p)
if kind == "" {
return ""
}
return workloadID(p.Namespace, kind, name)
}
func workloadID(ns, kind, name string) string { return "wl/" + ns + "/" + kind + "/" + name }
func workloadNode(id, kind, ns, name string, facts map[string]string) Node {
return Node{ID: id, Label: name, Kind: kind, Namespace: ns, Parent: "ns/" + ns, Facts: facts}
}
func boolStr(b bool) string {
if b {
return "true"
}
return "false"
}
func ingressBackendServices(ing networkingv1.Ingress) []string {
seen := map[string]bool{}
var out []string
add := func(name string) {
if name != "" && !seen[name] {
seen[name] = true
out = append(out, name)
}
}
if ing.Spec.DefaultBackend != nil && ing.Spec.DefaultBackend.Service != nil {
add(ing.Spec.DefaultBackend.Service.Name)
}
for _, rule := range ing.Spec.Rules {
if rule.HTTP == nil {
continue
}
for _, path := range rule.HTTP.Paths {
if path.Backend.Service != nil {
add(path.Backend.Service.Name)
}
}
}
return out
}
func firstContainerImage(containers []corev1.Container) string {
if len(containers) == 0 {
return ""
}
return containers[0].Image
}
// health is what the status dot on a card shows: ok, warn (partly ready),
// error (nothing ready), idle (scaled to zero or suspended).
func health(want, ready int) string {
switch {
case want == 0:
return "idle"
case ready >= want:
return "ok"
case ready == 0:
return "error"
}
return "warn"
}
func replicasOf(p *int32) int {
if p == nil {
return 1
}
return int(*p)
}
func deploymentFacts(d appsv1.Deployment) map[string]string {
return map[string]string{
"replicas": itoa32(d.Spec.Replicas),
"readyReplicas": itoa(int(d.Status.ReadyReplicas)),
"image": firstContainerImage(d.Spec.Template.Spec.Containers),
"health": health(replicasOf(d.Spec.Replicas), int(d.Status.ReadyReplicas)),
}
}
func statefulsetFacts(s appsv1.StatefulSet) map[string]string {
return map[string]string{
"replicas": itoa32(s.Spec.Replicas),
"readyReplicas": itoa(int(s.Status.ReadyReplicas)),
"image": firstContainerImage(s.Spec.Template.Spec.Containers),
"health": health(replicasOf(s.Spec.Replicas), int(s.Status.ReadyReplicas)),
}
}
func daemonsetFacts(ds appsv1.DaemonSet) map[string]string {
return map[string]string{
"desired": itoa(int(ds.Status.DesiredNumberScheduled)),
"ready": itoa(int(ds.Status.NumberReady)),
"image": firstContainerImage(ds.Spec.Template.Spec.Containers),
"health": health(int(ds.Status.DesiredNumberScheduled), int(ds.Status.NumberReady)),
}
}
func cronjobFacts(cj batchv1.CronJob) map[string]string {
f := map[string]string{"schedule": cj.Spec.Schedule, "health": "ok", "active": itoa(len(cj.Status.Active))}
if cj.Spec.Suspend != nil && *cj.Spec.Suspend {
f["suspended"] = "true"
f["health"] = "idle"
}
if cj.Status.LastSuccessfulTime != nil {
f["lastSuccess"] = cj.Status.LastSuccessfulTime.UTC().Format("2006-01-02 15:04")
}
return f
}
func serviceFacts(svc corev1.Service) map[string]string {
var ports []string
for _, p := range svc.Spec.Ports {
ports = append(ports, itoa(int(p.Port))+"/"+string(p.Protocol))
}
return map[string]string{"type": string(svc.Spec.Type), "ports": strings.Join(ports, ", ")}
}
func ingressFacts(ing networkingv1.Ingress) map[string]string {
var hosts []string
for _, r := range ing.Spec.Rules {
if r.Host != "" {
hosts = append(hosts, r.Host)
}
}
class := ""
if ing.Spec.IngressClassName != nil {
class = *ing.Spec.IngressClassName
}
return map[string]string{"hosts": strings.Join(hosts, ", "), "class": class}
}
func nodeFacts(n corev1.Node) map[string]string {
ready := "False"
for _, c := range n.Status.Conditions {
if c.Type == corev1.NodeReady {
ready = string(c.Status)
}
}
h := "ok"
if ready != "True" {
h = "error"
}
return map[string]string{"ready": ready, "os": n.Status.NodeInfo.OSImage, "kubelet": n.Status.NodeInfo.KubeletVersion, "health": h}
}
func itoa(i int) string {
if i == 0 {
return "0"
}
neg := i < 0
if neg {
i = -i
}
var b []byte
for i > 0 {
b = append([]byte{byte('0' + i%10)}, b...)
i /= 10
}
if neg {
b = append([]byte{'-'}, b...)
}
return string(b)
}
func itoa32(p *int32) string {
if p == nil {
return "?"
}
return itoa(int(*p))
}
// handleResource returns the raw manifest (as YAML, easiest to read) for a
// single graph node, fetched fresh -- not cached alongside the graph, since
// most nodes are never clicked and a full spec dump for every workload on
// every /api/graph call would be wasteful.
func handleResource(w http.ResponseWriter, r *http.Request) {
kind := r.URL.Query().Get("kind")
ns := r.URL.Query().Get("namespace")
name := r.URL.Query().Get("name")
ctx := r.Context()
var obj interface{}
var err error
switch kind {
case "namespace":
obj, err = clientset.CoreV1().Namespaces().Get(ctx, name, metav1.GetOptions{})
case "deployment":
obj, err = clientset.AppsV1().Deployments(ns).Get(ctx, name, metav1.GetOptions{})
case "statefulset":
obj, err = clientset.AppsV1().StatefulSets(ns).Get(ctx, name, metav1.GetOptions{})
case "daemonset":
obj, err = clientset.AppsV1().DaemonSets(ns).Get(ctx, name, metav1.GetOptions{})
case "cronjob":
obj, err = clientset.BatchV1().CronJobs(ns).Get(ctx, name, metav1.GetOptions{})
case "service":
obj, err = clientset.CoreV1().Services(ns).Get(ctx, name, metav1.GetOptions{})
case "ingress":
obj, err = clientset.NetworkingV1().Ingresses(ns).Get(ctx, name, metav1.GetOptions{})
case "node":
obj, err = clientset.CoreV1().Nodes().Get(ctx, name, metav1.GetOptions{})
default:
http.Error(w, "unknown kind: "+kind, http.StatusBadRequest)
return
}
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if a, ok := obj.(metav1.Object); ok {
a.SetManagedFields(nil)
}
out, err := yaml.Marshal(obj)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Write(out)
}
// podsForWorkload finds the live pods currently owned by a given workload,
// reusing the same ownerReferences-walking logic buildGraph uses for the
// schedules-on edges -- so "which pods back this node" stays consistent
// with what the graph already shows for placement.
func podsForWorkload(ctx context.Context, ns, target string) ([]corev1.Pod, error) {
pods, err := listAll[corev1.Pod](podLister.Pods(ns))
if err != nil {
return nil, err
}
var out []corev1.Pod
for _, p := range pods.Items {
if ownerWorkloadID(p) == target {
out = append(out, p)
}
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
return out, nil
}
type PodInfo struct {
Name string `json:"name"`
NodeName string `json:"nodeName"`
Phase string `json:"phase"`
Containers []string `json:"containers"`
}
// handlePods lists the pods backing a workload node, with their containers --
// the frontend uses this to build the pod/container pickers before fetching
// logs, since a Deployment/StatefulSet/DaemonSet/CronJob isn't itself a log
// source, its pods are.
func handlePods(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
ns := r.URL.Query().Get("namespace")
if ns == "" || !strings.HasPrefix(id, "wl/"+ns+"/") {
http.Error(w, "namespace and a workload id (wl/<ns>/<kind>/<name>) are required", http.StatusBadRequest)
return
}
pods, err := podsForWorkload(r.Context(), ns, id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
out := make([]PodInfo, 0, len(pods))
for _, p := range pods {
var containers []string
for _, c := range p.Spec.Containers {
containers = append(containers, c.Name)
}
out = append(out, PodInfo{Name: p.Name, NodeName: p.Spec.NodeName, Phase: string(p.Status.Phase), Containers: containers})
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(out)
}
// handleLogs streams a single container's recent log tail. Read-only,
// no follow -- this is a click-to-inspect tool, not a live tail viewer.
func handleLogs(w http.ResponseWriter, r *http.Request) {
ns := r.URL.Query().Get("namespace")
pod := r.URL.Query().Get("pod")
container := r.URL.Query().Get("container")
if ns == "" || pod == "" {
http.Error(w, "namespace and pod are required", http.StatusBadRequest)
return
}
var tail int64 = 500
opts := &corev1.PodLogOptions{TailLines: &tail}
if container != "" {
opts.Container = container
}
stream, err := clientset.CoreV1().Pods(ns).GetLogs(pod, opts).Stream(r.Context())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer stream.Close()
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
io.Copy(w, stream)
}
+25
View File
@@ -0,0 +1,25 @@
name: cluster-map
stage: Experimental
namespace: d8-cluster-map
subsystems:
- observability
descriptions:
en: >-
Interactive topology map of the cluster: an inventory tree of namespaces
and nodes, workloads with their Services and Ingresses, live traffic
between them from Cilium Hubble, and per-object YAML and logs.
ru: >-
Интерактивная карта кластера: дерево namespace и нод, workload'ы с их
Service и Ingress, живой трафик между ними из Cilium Hubble, YAML и логи
каждого объекта.
tags: ["observability", "ui"]
requirements:
deckhouse: ">= 1.72"
kubernetes: ">= 1.29"
disable:
confirmation: false
accessibility:
editions:
_default:
available: true
enabledInBundles: []
@@ -0,0 +1,28 @@
- name: d8.cluster-map
rules:
- alert: ClusterMapHubbleDisconnected
expr: max by (pod) (cluster_map_hubble_stream_active == 1 and cluster_map_hubble_connected == 0)
for: 15m
labels:
severity_level: "8"
tier: cluster
annotations:
plk_markup_format: markdown
plk_protocol_version: "1"
summary: cluster-map has no flows from Hubble Relay.
description: |
The traffic layer of cluster-map has received no flows for 15 minutes while it is supposed to be collecting. The topology map still works; traffic windows go stale.
Check the pod log: `kubectl -n d8-cluster-map logs deploy/cluster-map`, and that hubble-relay is running: `kubectl -n d8-cni-cilium get pods -l app=hubble-relay`.
- alert: ClusterMapTrackedTuplesHigh
expr: max(cluster_map_traffic_tracked_tuples) > 2000000
for: 30m
labels:
severity_level: "9"
tier: cluster
annotations:
plk_markup_format: markdown
plk_protocol_version: "1"
summary: cluster-map keeps more than 2 million connection tuples.
description: |
Memory of the traffic collector grows with the number of distinct connections in the retention window. Lower `traffic.retentionMinutes` or switch `traffic.mode` to `OnDemand` in the `cluster-map` ModuleConfig.
+189
View File
@@ -0,0 +1,189 @@
type: object
properties:
traffic:
type: object
default: {}
description: Live traffic between workloads, read from Cilium Hubble Relay.
properties:
mode:
type: string
default: Continuous
enum: ["Continuous", "OnDemand", "Disabled"]
description: |
When flows are read from Hubble.
- `Continuous` — a Hubble follow stream is always open, so every traffic window is full as soon as the map is opened. Costs hubble-relay about 100–150m CPU on a busy cluster.
- `OnDemand` — the stream opens with the first traffic request and closes after `onDemandIdleMinutes` without one. Near-zero cost while nobody looks at the map, but windows only fill while it is in use.
- `Disabled` — no connection to Hubble; the map shows configuration links only.
Traffic also stays off when the `cilium-hubble` module is disabled.
retentionMinutes:
type: integer
default: 60
minimum: 5
maximum: 1440
description: |
How far back traffic windows can reach, in minutes. Memory grows with retention and with the number of distinct connections in the cluster.
onDemandIdleMinutes:
type: integer
default: 10
minimum: 1
maximum: 120
description: In `OnDemand` mode, how long the stream stays open after the last traffic request.
collectInfraTraffic:
type: boolean
default: false
description: |
Also collect kubelet probes and other traffic originating from node hosts, node-to-node traffic, Cilium health checks and DNS.
Off by default: on a typical cluster this is about three quarters of all flows, none of it maps to a workload, and filtering it at the Hubble agents keeps hubble-relay load several times lower.
logs:
type: object
default: {}
properties:
tailLines:
type: integer
default: 500
minimum: 10
maximum: 10000
description: How many last lines of a container log the Logs tab shows.
systemNamespacePrefixes:
type: array
default: ["d8-", "kube-"]
items:
type: string
description: |
Namespaces grouped as "System" in the inventory tree. An entry ending in `-` matches by prefix, any other entry matches the whole name.
ingressClass:
type: string
pattern: '^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'
description: |
The class of the Ingress controller used for the web interface.
Optional. By default, the `modules.ingressClass` global value is used.
nodeSelector:
type: object
additionalProperties:
type: string
description: |
The same as the `spec.nodeSelector` pod parameter in Kubernetes.
If the parameter is omitted or `false`, it will be determined [automatically](https://deckhouse.io/products/kubernetes-platform/documentation/v1/#advanced-scheduling).
tolerations:
type: array
description: |
The same as `spec.tolerations` for the Kubernetes Pod.
If the parameter is omitted or `false`, it will be determined [automatically](https://deckhouse.io/products/kubernetes-platform/documentation/v1/#advanced-scheduling).
items:
type: object
properties:
effect:
type: string
key:
type: string
operator:
type: string
tolerationSeconds:
type: integer
format: int64
value:
type: string
auth:
type: object
default: {}
description: |
Access to the web interface.
Anyone admitted here sees every namespace, the manifests of workloads, Services and Ingresses (never Secrets) and container logs, through the module's own read-only service account. Restrict access with `allowedUserGroups`.
properties:
externalAuthentication:
type: object
description: |
Parameters to enable external authentication based on the Ingress NGINX [external-auth](https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/) mechanism.
> External authentication is enabled automatically if the [user-authn](https://deckhouse.io/modules/user-authn/) module is enabled.
properties:
authURL:
type: string
x-examples: ["https://example.com/dex/auth"]
description: The URL of the authentication service. If the user is authenticated, the service should return an HTTP 200 response code.
authSignInURL:
type: string
x-examples: ["https://example.com/dex/sign_in"]
description: The URL to redirect the user for authentication (if the authentication service returned a non-200 HTTP response code).
allowedUserEmails:
type: array
items:
type: string
description: |
Emails of users allowed to open the web interface.
Used if the `user-authn` module is enabled or `externalAuthentication` is set.
allowedUserGroups:
type: array
items:
type: string
x-examples:
- ["admins"]
description: |
User groups allowed to open the web interface.
Used if the `user-authn` module is enabled or `externalAuthentication` is set.
**Caution!** When used together with the [user-authn](https://deckhouse.io/modules/user-authn/) module, add these groups to the matching field of the DexProvider.
whitelistSourceRanges:
type: array
items:
type: string
x-examples:
- ["1.1.1.1/32"]
description: CIDRs allowed to open the web interface.
https:
type: object
x-examples:
- mode: Disabled
- mode: OnlyInURI
- mode: CustomCertificate
customCertificate:
secretName: "foobar"
- mode: CertManager
certManager:
clusterIssuerName: letsencrypt
description: |
What certificate type to use.
This parameter completely overrides the `global.modules.https` settings.
properties:
mode:
type: string
default: "CertManager"
description: |
The HTTPS usage mode:
- `CertManager` — the web interface is served over HTTPS with a certificate from the ClusterIssuer set in `certManager.clusterIssuerName`;
- `CustomCertificate` — the web interface is served over HTTPS with a certificate from the `d8-system` namespace;
- `Disabled` — the web interface is served over HTTP only;
- `OnlyInURI` — the web interface is served over HTTP behind an external HTTPS load balancer that terminates TLS; links are generated with the HTTPS scheme.
enum:
- "Disabled"
- "CertManager"
- "CustomCertificate"
- "OnlyInURI"
certManager:
type: object
properties:
clusterIssuerName:
type: string
default: "letsencrypt"
x-examples: ["letsencrypt", "letsencrypt-staging", "selfsigned"]
description: The ClusterIssuer used to get the certificate.
customCertificate:
type: object
default: {}
properties:
secretName:
type: string
description: |
The name of the Secret in the `d8-system` namespace to use for the web interface.
The Secret must have the [kubernetes.io/tls](https://kubernetes.github.io/ingress-nginx/user-guide/tls/#tls-secrets) format.
+100
View File
@@ -0,0 +1,100 @@
type: object
properties:
traffic:
description: Живой трафик между workload'ами из Cilium Hubble Relay.
properties:
mode:
description: |
Когда читать потоки из Hubble.
- `Continuous` — поток из Hubble открыт всегда, поэтому любое окно трафика заполнено сразу при открытии карты. На нагруженном кластере стоит hubble-relay около 100–150m CPU.
- `OnDemand` — поток открывается при первом запросе трафика и закрывается через `onDemandIdleMinutes` без запросов. Пока карту никто не смотрит, нагрузки почти нет, но окна заполняются только во время работы с картой.
- `Disabled` — без подключения к Hubble, карта показывает только связи по конфигурации.
Трафик выключен и тогда, когда выключен модуль `cilium-hubble`.
retentionMinutes:
description: |
На сколько минут назад могут смотреть окна трафика. Память растёт вместе с этим значением и с числом различных соединений в кластере.
onDemandIdleMinutes:
description: В режиме `OnDemand` — сколько минут поток остаётся открытым после последнего запроса трафика.
collectInfraTraffic:
description: |
Собирать также пробы kubelet и прочий трафик с хостов нод, трафик между нодами, проверки Cilium health и DNS.
По умолчанию выключено: на обычном кластере это около трёх четвертей всех потоков, ни один из них не привязан к workload'у, а отсев на агентах Hubble снижает нагрузку на hubble-relay в несколько раз.
logs:
properties:
tailLines:
description: Сколько последних строк лога контейнера показывает вкладка «Логи».
systemNamespacePrefixes:
description: |
Namespace, которые в дереве инвентаря попадают в группу «Системные». Элемент, заканчивающийся на `-`, сравнивается как префикс, остальные — по имени целиком.
ingressClass:
description: |
Класс Ingress-контроллера для веб-интерфейса.
Опциональный параметр. По умолчанию используется глобальное значение `modules.ingressClass`.
nodeSelector:
description: |
Аналогично параметру Kubernetes `spec.nodeSelector` у подов.
Если параметр не указан или указано `false`, значение будет определено [автоматически](https://deckhouse.ru/products/kubernetes-platform/documentation/v1/#выделение-узлов-под-определенный-вид-нагрузки).
tolerations:
description: |
Аналогично параметру Kubernetes `spec.tolerations` у подов.
Если параметр не указан или указано `false`, значение будет определено [автоматически](https://deckhouse.ru/products/kubernetes-platform/documentation/v1/#выделение-узлов-под-определенный-вид-нагрузки).
auth:
description: |
Доступ к веб-интерфейсу.
Любой, кого сюда пустили, видит все namespace, манифесты workload'ов, Service и Ingress (Secret — никогда) и логи контейнеров — через собственную read-only-учётку модуля. Ограничивайте доступ через `allowedUserGroups`.
properties:
externalAuthentication:
description: |
Параметры для подключения внешней аутентификации на основе механизма Ingress NGINX [external-auth](https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/).
> Внешняя аутентификация включается автоматически, если включен модуль [user-authn](https://deckhouse.ru/modules/user-authn/).
properties:
authURL:
description: URL сервиса аутентификации. Если пользователь прошёл аутентификацию, сервис должен вернуть код ответа HTTP 200.
authSignInURL:
description: URL, куда будет перенаправлен пользователь для прохождения аутентификации (если сервис аутентификации вернул код ответа HTTP, отличный от 200).
allowedUserEmails:
description: |
Email пользователей, которым разрешено открывать веб-интерфейс.
Используется, если включен модуль `user-authn` или задан параметр `externalAuthentication`.
allowedUserGroups:
description: |
Группы пользователей, которым разрешено открывать веб-интерфейс.
Используется, если включен модуль `user-authn` или задан параметр `externalAuthentication`.
**Внимание!** При использовании совместно с модулем [user-authn](https://deckhouse.ru/modules/user-authn/) эти группы нужно добавить в соответствующее поле DexProvider.
whitelistSourceRanges:
description: Список CIDR, которым разрешено открывать веб-интерфейс.
https:
description: |
Тип сертификата.
Этот параметр полностью переопределяет глобальные настройки `global.modules.https`.
properties:
mode:
description: |
Режим работы HTTPS:
- `CertManager` — веб-интерфейс по HTTPS с сертификатом от ClusterIssuer из `certManager.clusterIssuerName`;
- `CustomCertificate` — веб-интерфейс по HTTPS с сертификатом из namespace `d8-system`;
- `Disabled` — веб-интерфейс только по HTTP;
- `OnlyInURI` — веб-интерфейс по HTTP за внешним HTTPS-балансировщиком, который терминирует TLS; ссылки формируются со схемой HTTPS.
certManager:
properties:
clusterIssuerName:
description: ClusterIssuer, через который получается сертификат.
customCertificate:
properties:
secretName:
description: |
Имя Secret в namespace `d8-system` с сертификатом для веб-интерфейса.
Secret должен быть в формате [kubernetes.io/tls](https://kubernetes.github.io/ingress-nginx/user-guide/tls/#tls-secrets).
+33
View File
@@ -0,0 +1,33 @@
x-extend:
schema: config-values.yaml
type: object
properties:
internal:
type: object
default: {}
properties:
deployDexAuthenticator:
type: boolean
hubbleCA:
type: string
default: ""
x-examples: ["-----BEGIN CERTIFICATE-----"]
description: Public certificate of the hubble CA, read by the hubble_ca hook. Empty when cilium-hubble is not installed.
customCertificateData:
type: object
properties:
tls.crt:
type: string
x-examples:
- plainstring
tls.key:
type: string
x-examples:
- plainstring
ca.crt:
type: string
x-examples:
- plainstring
registry:
type: object
description: "System field, overwritten by Deckhouse. Don't use"
+24
View File
@@ -0,0 +1,24 @@
- id: cytoscape
name: Cytoscape.js
version: 3.30.2
description: Graph rendering for the topology map.
link: https://js.cytoscape.org/
license: MIT
- id: elkjs
name: ELK.js
version: 0.9.3
description: Layered graph layout (Eclipse Layout Kernel compiled to JavaScript).
link: https://github.com/kieler/elkjs
license: EPL-2.0
- id: cilium
name: Cilium Hubble API
version: 1.17.4
description: Observer gRPC API used to read flows from Hubble Relay.
link: https://github.com/cilium/cilium
license: Apache License 2.0
- id: client-go
name: Kubernetes client-go
version: 0.32.0
description: Kubernetes API client and informers.
link: https://github.com/kubernetes/client-go
license: Apache License 2.0
-80
View File
@@ -1,80 +0,0 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light dark">
<title>cluster-map</title>
<link rel="stylesheet" href="app.css">
<script src="vendor/cytoscape.min.js"></script>
<script src="vendor/elk.bundled.js"></script>
</head>
<body>
<header class="topbar">
<div class="brand">cluster-map</div>
<nav class="crumbs" id="crumbs" aria-label="Текущий вид"></nav>
<div class="topbar-actions">
<label class="toggle"><input type="checkbox" id="traffic-on" checked> Трафик</label>
<select id="traffic-window" aria-label="Окно трафика">
<option value="300">5 мин</option>
<option value="900">15 мин</option>
<option value="3600">1 час</option>
</select>
<button type="button" id="reload" class="btn">Обновить</button>
<span class="muted small" id="updated"></span>
</div>
</header>
<div class="layout">
<aside class="sidebar" aria-label="Инвентарь">
<div class="seg" role="tablist" aria-label="Группировка">
<button type="button" role="tab" id="view-ns" aria-selected="true" aria-controls="tree">Namespaces</button>
<button type="button" role="tab" id="view-nodes" aria-selected="false" aria-controls="tree">Ноды</button>
</div>
<input type="search" id="tree-filter" placeholder="Поиск: имя, namespace, образ…" aria-label="Поиск по инвентарю">
<ul class="tree" id="tree" role="tree" aria-label="Объекты кластера"></ul>
<p class="hint">Клик — открыть на карте. Ctrl+клик по namespace — добавить к текущему виду.</p>
</aside>
<main class="stage">
<div id="cy" aria-label="Карта"></div>
<div class="stage-status" id="stage-status" role="status" aria-live="polite"></div>
<div class="zoom" role="group" aria-label="Масштаб">
<button type="button" class="btn icon" id="zoom-in" aria-label="Приблизить">+</button>
<button type="button" class="btn icon" id="zoom-out" aria-label="Отдалить">−</button>
<button type="button" class="btn icon" id="zoom-fit" aria-label="Показать всё">⤢</button>
</div>
<div class="legend" id="legend"></div>
</main>
<aside class="details" id="details" aria-label="Детали объекта" hidden>
<div class="details-head">
<div class="details-title">
<span class="kind-chip" id="d-kind"></span>
<h2 id="d-name"></h2>
<div class="muted small" id="d-sub"></div>
</div>
<button type="button" class="btn icon" id="d-close" aria-label="Закрыть панель">×</button>
</div>
<div class="tabs" role="tablist" aria-label="Разделы">
<button type="button" role="tab" data-tab="overview" aria-selected="true">Обзор</button>
<button type="button" role="tab" data-tab="links" aria-selected="false">Связи</button>
<button type="button" role="tab" data-tab="yaml" aria-selected="false">YAML</button>
<button type="button" role="tab" data-tab="logs" aria-selected="false">Логи</button>
</div>
<section class="tab-panel" data-panel="overview" role="tabpanel"></section>
<section class="tab-panel" data-panel="links" role="tabpanel" hidden></section>
<section class="tab-panel" data-panel="yaml" role="tabpanel" hidden><pre class="code" id="d-yaml"></pre></section>
<section class="tab-panel" data-panel="logs" role="tabpanel" hidden>
<div class="logs-bar">
<select id="pod-select" aria-label="Под"></select>
<select id="container-select" aria-label="Контейнер"></select>
<button type="button" class="btn" id="logs-reload">Обновить</button>
</div>
<pre class="code" id="d-logs"></pre>
</section>
</aside>
</div>
<script src="app.js"></script>
</body>
</html>
+3
View File
@@ -0,0 +1,3 @@
{{- if or (eq (include "helm_lib_module_ingress_enabled" .) "true") (eq (include "helm_lib_module_gateway_enabled" .) "true") }}
{{- include "helm_lib_module_https_copy_custom_certificate" (list . "d8-cluster-map" "ingress-tls") }}
{{- end }}
+140
View File
@@ -0,0 +1,140 @@
{{- $traffic := .Values.clusterMap.traffic }}
{{- /* Without the hubble CA there is no relay to talk to: cilium-hubble is off. */}}
{{- $trafficMode := ternary $traffic.mode "Disabled" (ne .Values.clusterMap.internal.hubbleCA "") }}
{{- if (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: cluster-map
updatePolicy:
updateMode: "InPlaceOrRecreate"
resourcePolicy:
containerPolicies:
- containerName: cluster-map
minAllowed:
cpu: 10m
memory: 64Mi
maxAllowed:
cpu: 500m
# the traffic collector keeps distinct connections for the whole
# retention window; a day on a busy cluster needs more than an hour
memory: {{ ternary "2Gi" "512Mi" (gt (int $traffic.retentionMinutes) 180) }}
{{- end }}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
maxUnavailable: 1
selector:
matchLabels:
app: cluster-map
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
# One replica by design: traffic history lives in the process. Two replicas
# would each keep their own history and double the load on hubble-relay.
replicas: 1
revisionHistoryLimit: 2
strategy:
type: Recreate
selector:
matchLabels:
app: cluster-map
template:
metadata:
labels:
app: cluster-map
annotations:
checksum/hubble-ca: {{ .Values.clusterMap.internal.hubbleCA | sha256sum }}
spec:
serviceAccountName: cluster-map
automountServiceAccountToken: true
{{- include "helm_lib_priority_class" (tuple . "cluster-low") | nindent 6 }}
{{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
{{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
{{- include "helm_lib_module_pod_security_context_run_as_user_deckhouse" . | nindent 6 }}
{{- if .Values.clusterMap.registry.dockercfg }}
imagePullSecrets:
- name: deckhouse-registry
{{- end }}
containers:
- name: cluster-map
image: {{ include "helm_lib_module_image" (list . "clusterMap") }}
imagePullPolicy: IfNotPresent
{{- include "helm_lib_module_container_security_context_read_only_root_filesystem_capabilities_drop_all_pss_restricted" . | nindent 8 }}
env:
- name: LISTEN_ADDR
value: ":8080"
- name: METRICS_ADDR
value: ":9090"
- name: TRAFFIC_MODE
value: {{ $trafficMode | quote }}
- name: TRAFFIC_RETENTION
value: {{ printf "%dm" (int $traffic.retentionMinutes) | quote }}
- name: TRAFFIC_ON_DEMAND_IDLE
value: {{ printf "%dm" (int $traffic.onDemandIdleMinutes) | quote }}
- name: TRAFFIC_COLLECT_INFRA
value: {{ $traffic.collectInfraTraffic | quote }}
- name: HUBBLE_RELAY_ADDR
value: {{ printf "hubble-relay.d8-cni-cilium.svc.%s:443" .Values.global.discovery.clusterDomain | quote }}
- name: HUBBLE_CA_FILE
value: /etc/hubble-ca/ca.crt
- name: LOG_TAIL_LINES
value: {{ .Values.clusterMap.logs.tailLines | quote }}
- name: SYSTEM_NAMESPACE_PREFIXES
value: {{ .Values.clusterMap.systemNamespacePrefixes | join "," | quote }}
ports:
- name: http
containerPort: 8080
protocol: TCP
- name: metrics
containerPort: 9090
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: http
periodSeconds: 10
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /readyz
port: http
periodSeconds: 5
timeoutSeconds: 3
resources:
requests:
{{- include "helm_lib_module_ephemeral_storage_only_logs" . | nindent 12 }}
{{- if not (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") }}
cpu: 25m
memory: 96Mi
{{- end }}
{{- if .Values.clusterMap.internal.hubbleCA }}
volumeMounts:
- name: hubble-ca
mountPath: /etc/hubble-ca
readOnly: true
{{- end }}
{{- if .Values.clusterMap.internal.hubbleCA }}
volumes:
- name: hubble-ca
configMap:
name: hubble-ca
{{- end }}
+38
View File
@@ -0,0 +1,38 @@
{{- $moduleGateway := dict }}
{{- include "helm_lib_module_gateway" (list . $moduleGateway) }}
{{- $ingressEnabled := eq (include "helm_lib_module_ingress_enabled" .) "true" }}
{{- $gatewayEnabled := eq (include "helm_lib_module_gateway_enabled" .) "true" }}
{{- if and .Values.clusterMap.internal.deployDexAuthenticator (or $ingressEnabled $gatewayEnabled) }}
---
apiVersion: deckhouse.io/v1
kind: DexAuthenticator
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "dex-authenticator" "name" "cluster-map")) | nindent 2 }}
spec:
applicationDomain: {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
{{- if and $ingressEnabled (include "helm_lib_module_https_ingress_tls_enabled" .) }}
applicationIngressCertificateSecretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls") }}
{{- end }}
{{- if and $gatewayEnabled (include "helm_lib_module_https_route_tls_enabled" .) }}
gatewayAPI:
applicationHTTPRouteListenerSetName: cluster-map
{{- end }}
applicationIngressClassName: {{ include "helm_lib_module_ingress_class" . | quote }}
{{- with .Values.clusterMap.auth.allowedUserEmails }}
allowedEmails:
{{- . | toYaml | nindent 2 }}
{{- end }}
{{- with .Values.clusterMap.auth.allowedUserGroups }}
allowedGroups:
{{- . | toYaml | nindent 2 }}
{{- end }}
{{- with .Values.clusterMap.auth.whitelistSourceRanges }}
whitelistSourceRanges:
{{- . | toYaml | nindent 2 }}
{{- end }}
{{- include "helm_lib_node_selector" (tuple . "system") | nindent 2 }}
{{- include "helm_lib_tolerations" (tuple . "system") | nindent 2 }}
highAvailability: false
{{- end }}
+123
View File
@@ -0,0 +1,123 @@
{{- $moduleGateway := dict }}
{{- include "helm_lib_module_gateway" (list . $moduleGateway) }}
{{- if and (eq (include "helm_lib_module_gateway_enabled" .) "true") .Values.global.modules.publicDomainTemplate .Values.global.clusterIsBootstrapped }}
---
apiVersion: gateway.networking.k8s.io/v1
kind: ListenerSet
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
listeners:
{{- if (include "helm_lib_module_https_route_tls_enabled" .) }}
- allowedRoutes:
namespaces:
from: Same
hostname: {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
name: cluster-map
port: 443
protocol: HTTPS
tls:
certificateRefs:
- group: ""
kind: Secret
name: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls" "httproute-tls") }}
namespace: d8-cluster-map
mode: Terminate
- allowedRoutes:
namespaces:
from: Same
hostname: {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
name: cluster-map-redirect
port: 80
protocol: HTTP
{{- else }}
- allowedRoutes:
namespaces:
from: Same
hostname: {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
name: cluster-map
port: 80
protocol: HTTP
{{- end }}
parentRef:
group: gateway.networking.k8s.io
kind: Gateway
name: {{ $moduleGateway.name }}
namespace: {{ $moduleGateway.namespace }}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
annotations:
web.deckhouse.io/export-name: "cluster-map"
web.deckhouse.io/export-icon: "/icon.svg"
{{- if and (ne (include "helm_lib_module_https_mode" .) "Disabled") .Values.clusterMap.auth.externalAuthentication }}
alb.network.deckhouse.io/auth-signin: {{ replace "$host" (include "helm_lib_module_public_domain" (list . "cluster-map")) .Values.clusterMap.auth.externalAuthentication.authSignInURL | quote }}
alb.network.deckhouse.io/auth-url: {{ .Values.clusterMap.auth.externalAuthentication.authURL | quote }}
alb.network.deckhouse.io/auth-response-headers: "X-Auth-Request-User,X-Auth-Request-Email"
{{- end }}
{{- if .Values.clusterMap.auth.whitelistSourceRanges }}
alb.network.deckhouse.io/whitelist-source-range: {{ .Values.clusterMap.auth.whitelistSourceRanges | join "," | quote }}
{{- end }}
spec:
hostnames:
- {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
parentRefs:
- group: gateway.networking.k8s.io
kind: ListenerSet
name: cluster-map
namespace: d8-cluster-map
sectionName: cluster-map
rules:
- backendRefs:
- group: ""
kind: Service
name: cluster-map
port: 80
weight: 1
matches:
- path:
type: PathPrefix
value: /
{{- if or (eq (include "helm_lib_module_https_mode" .) "CertManager") (eq (include "helm_lib_module_https_mode" .) "CustomCertificate") }}
filters:
- type: ResponseHeaderModifier
responseHeaderModifier:
add:
- name: Strict-Transport-Security
value: max-age=31536000; includeSubDomains
{{- end }}
{{- if (include "helm_lib_module_https_route_tls_enabled" .) }}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: cluster-map-redirect
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
hostnames:
- {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
parentRefs:
- group: gateway.networking.k8s.io
kind: ListenerSet
name: cluster-map
namespace: d8-cluster-map
sectionName: cluster-map-redirect
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301
matches:
- path:
type: PathPrefix
value: /
{{- end }}
{{- end }}
+13
View File
@@ -0,0 +1,13 @@
{{- if .Values.clusterMap.internal.hubbleCA }}
---
# Public certificate of the hubble CA, copied by the hubble_ca hook from
# d8-cni-cilium. Used to verify hubble-relay's server certificate.
apiVersion: v1
kind: ConfigMap
metadata:
name: hubble-ca
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
data:
ca.crt: {{ .Values.clusterMap.internal.hubbleCA | quote }}
{{- end }}
+85
View File
@@ -0,0 +1,85 @@
{{- if and .Values.global.modules.publicDomainTemplate .Values.global.clusterIsBootstrapped }}
{{- $moduleGateway := dict }}
{{- include "helm_lib_module_gateway" (list . $moduleGateway) }}
{{- if eq (include "helm_lib_module_ingress_enabled" .) "true" }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
annotations:
web.deckhouse.io/export-name: "cluster-map"
web.deckhouse.io/export-icon: "/icon.svg"
{{- if and (ne (include "helm_lib_module_https_mode" .) "Disabled") .Values.clusterMap.auth.externalAuthentication }}
nginx.ingress.kubernetes.io/auth-signin: {{ .Values.clusterMap.auth.externalAuthentication.authSignInURL | quote }}
nginx.ingress.kubernetes.io/auth-url: {{ .Values.clusterMap.auth.externalAuthentication.authURL | quote }}
nginx.ingress.kubernetes.io/auth-response-headers: "X-Auth-Request-User,X-Auth-Request-Email"
{{- end }}
{{- if .Values.clusterMap.auth.whitelistSourceRanges }}
nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.clusterMap.auth.whitelistSourceRanges | join "," | quote }}
{{- end }}
nginx.ingress.kubernetes.io/configuration-snippet: |
{{- include "helm_lib_module_ingress_configuration_snippet" . | nindent 6 }}
spec:
ingressClassName: {{ include "helm_lib_module_ingress_class" . | quote }}
rules:
- host: {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: cluster-map
port:
name: http
{{- if (include "helm_lib_module_https_ingress_tls_enabled" .) }}
tls:
- hosts:
- {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls") }}
{{- end }}
{{- end }}
{{- if and (eq (include "helm_lib_module_ingress_enabled" .) "true") (eq (include "helm_lib_module_https_mode" .) "CertManager") }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
certificateOwnerRef: false
secretName: {{ include "helm_lib_module_https_secret_name" (list . "ingress-tls") }}
{{- include "helm_lib_module_generate_common_name" (list . "cluster-map") | nindent 2 }}
dnsNames:
- {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
issuerRef:
name: {{ include "helm_lib_module_https_cert_manager_cluster_issuer_name" . }}
kind: ClusterIssuer
{{- end }}
{{- if and (eq (include "helm_lib_module_gateway_enabled" .) "true") (eq (include "helm_lib_module_https_mode" .) "CertManager") }}
{{- $issuerName := include "helm_lib_module_https_cert_manager_cluster_issuer_name" . }}
{{- if or (eq $issuerName "letsencrypt") (eq $issuerName "letsencrypt-staging") }}
{{- $issuerName = printf "%s-gateway-%s" $issuerName $moduleGateway.name }}
{{- end }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: cluster-map-httproute
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
certificateOwnerRef: false
secretName: {{ include "helm_lib_module_https_secret_name" (list . "httproute-tls") }}
{{- include "helm_lib_module_generate_common_name" (list . "cluster-map") | nindent 2 }}
dnsNames:
- {{ include "helm_lib_module_public_domain" (list . "cluster-map") }}
issuerRef:
name: {{ $issuerName }}
kind: ClusterIssuer
{{- end }}
{{- end }}
+30
View File
@@ -0,0 +1,30 @@
{{- if (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1/PodMonitor") }}
---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map" "prometheus" "main")) | nindent 2 }}
spec:
selector:
matchLabels:
app: cluster-map
podMetricsEndpoints:
- port: metrics
scheme: http
path: /metrics
relabelings:
- regex: endpoint|namespace|pod|service
action: labeldrop
- targetLabel: job
replacement: cluster-map
- sourceLabels: [__meta_kubernetes_pod_node_name]
targetLabel: node
- targetLabel: tier
replacement: cluster
- sourceLabels: [__meta_kubernetes_pod_ready]
regex: "true"
action: keep
{{- end }}
{{- include "helm_lib_prometheus_rules" (list . "d8-cluster-map") }}
+6
View File
@@ -0,0 +1,6 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "prometheus.deckhouse.io/rules-watcher-enabled" "true" "prometheus.deckhouse.io/monitor-watcher-enabled" "true")) | nindent 2 }}
+46
View File
@@ -0,0 +1,46 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
automountServiceAccountToken: true
---
# Read-only on exactly what the map shows. No Secrets, no ConfigMaps, no
# write verbs. pods/log backs the Logs tab.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: d8:cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
rules:
- apiGroups: [""]
resources: ["namespaces", "pods", "services", "nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets", "daemonsets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["batch"]
resources: ["cronjobs"]
verbs: ["get", "list", "watch"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: d8:cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: d8:cluster-map
subjects:
- kind: ServiceAccount
name: cluster-map
namespace: d8-cluster-map
+12
View File
@@ -0,0 +1,12 @@
{{- if .Values.clusterMap.registry.dockercfg }}
---
apiVersion: v1
kind: Secret
type: kubernetes.io/dockerconfigjson
metadata:
name: deckhouse-registry
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
data:
.dockerconfigjson: {{ .Values.clusterMap.registry.dockercfg }}
{{- end }}
+16
View File
@@ -0,0 +1,16 @@
---
apiVersion: v1
kind: Service
metadata:
name: cluster-map
namespace: d8-cluster-map
{{- include "helm_lib_module_labels" (list . (dict "app" "cluster-map")) | nindent 2 }}
spec:
type: ClusterIP
selector:
app: cluster-map
ports:
- name: http
port: 80
targetPort: http
protocol: TCP
+42
View File
@@ -0,0 +1,42 @@
# Values as Deckhouse would pass them for a typical cluster: user-authn on,
# CertManager https, cilium-hubble installed. Used by `make render`.
global:
clusterIsBootstrapped: true
enabledModules: ["user-authn", "cert-manager", "vertical-pod-autoscaler", "operator-prometheus-crd", "cilium-hubble"]
discovery:
clusterDomain: cluster.local
clusterControlPlaneIsHighlyAvailable: false
d8SpecificNodeCountByRole: {}
highAvailability: false
modules:
publicDomainTemplate: "%s.example.com"
ingressClass: nginx
https:
mode: CertManager
certManager:
clusterIssuerName: letsencrypt
placement: {}
modulesImages:
registry:
base: registry.example.com/modules
digests:
clusterMap:
clusterMap: "sha256:0000000000000000000000000000000000000000000000000000000000000000"
clusterMap:
traffic:
mode: Continuous
retentionMinutes: 60
onDemandIdleMinutes: 10
collectInfraTraffic: false
logs:
tailLines: 500
systemNamespacePrefixes: ["d8-", "kube-"]
auth:
allowedUserGroups: ["admins"]
externalAuthentication:
authURL: https://cluster-map-dex-authenticator.d8-cluster-map.svc.cluster.local/dex-authenticator/auth
authSignInURL: https://$host/dex-authenticator/sign_in
internal:
deployDexAuthenticator: true
hubbleCA: "-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----\n"
registry: {}
+4
View File
@@ -0,0 +1,4 @@
# cilium-hubble absent: the hook leaves hubbleCA empty and traffic turns off.
clusterMap:
internal:
hubbleCA: ""
+9
View File
@@ -0,0 +1,9 @@
giterminismConfigVersion: 1
config:
goTemplateRendering: # The rules for the Go-template functions to be able to pass build context to the release
allowEnvVariables:
- /CI_.+/
- MODULES_MODULE_TAG
- STAGED_DOCKERFILE # Allow the use of these variable in the .werf/stages/images.yaml file
allowUncommittedFiles:
- "base_images.yml"
+17
View File
@@ -0,0 +1,17 @@
project: cluster-map
configVersion: 1
build:
imageSpec:
author: "cluster-map authors"
clearHistory: true
config:
clearWerfLabels: true
removeLabels:
- /.*/
---
{{ tpl (.Files.Get ".werf/stages/base-images.yaml") $ }}
{{ tpl (.Files.Get ".werf/stages/images.yaml") $ }}
{{ tpl (.Files.Get ".werf/stages/images-digests.yaml") $ }}
{{ tpl (.Files.Get ".werf/stages/batch-go.yaml") $ }}
{{ tpl (.Files.Get ".werf/stages/bundle.yaml") $ }}
{{ tpl (.Files.Get ".werf/stages/release.yaml") $ }}
+32
View File
@@ -0,0 +1,32 @@
configVersion: 1
project: echoserver
cleanup:
keepPolicies:
- references:
branch: /.*/
limit:
in: 168h
- references:
branch: /release-[0-9]+.*/
limit:
last: 3
imagesPerReference:
last: 1
- references:
tag: /^v([0-9]\d*)\.([0-9]\d*)\.([0-9]\d*)(-.*)?/
limit:
last: 3
imagesPerReference:
last: 1
- references:
tag: /.*/
limit:
last: 3
imagesPerReference:
last: 1
- references:
branch: /master|main/
limit:
last: 1
imagesPerReference:
last: 1