From af29605259077d08f87078f7b8aef9fc2b206695 Mon Sep 17 00:00:00 2001 From: Jonada Hoxha Date: Fri, 22 Nov 2024 15:11:48 +0100 Subject: [PATCH] Retrieve and set cluster UUID for context --- cmd/icinga-kubernetes/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/icinga-kubernetes/main.go b/cmd/icinga-kubernetes/main.go index 5a0e410..65764d5 100644 --- a/cmd/icinga-kubernetes/main.go +++ b/cmd/icinga-kubernetes/main.go @@ -28,6 +28,7 @@ import ( promv1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/spf13/pflag" "golang.org/x/sync/errgroup" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" @@ -39,6 +40,8 @@ import ( "time" ) +var clusterContextKey = struct{}{} + const expectedSchemaVersion = "0.2.0" func main() { @@ -118,6 +121,16 @@ func main() { g, ctx := errgroup.WithContext(context.Background()) + namespaceName := "kube-system" + ns, err := clientset.CoreV1().Namespaces().Get(ctx, namespaceName, v1.GetOptions{}) + if err != nil { + klog.Fatalf("Failed to retrieve namespace '%s': %v. Ensure the cluster is accessible and the namespace exists.", namespaceName, err) + } + + clusterUuid := schemav1.EnsureUUID(ns.UID) + + ctx = context.WithValue(ctx, clusterContextKey, clusterUuid) + if hasSchema { var version string