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:
co-authored by
Claude Opus 5.5
parent
41f9b47556
commit
4518393ce1
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user