/* 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 }