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>
This commit is contained in:
Vitaliy Chefanov
2026-09-23 21:17:52 +03:00
co-authored by Claude Opus 5.5
parent 41f9b47556
commit 4518393ce1
82 changed files with 5712 additions and 1415 deletions
+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