From 15635073c0af8e9762736ba1d66b511cca5a6df2 Mon Sep 17 00:00:00 2001 From: Leandro Poroli Date: Thu, 27 Jun 2024 12:16:20 -0300 Subject: [PATCH] k8s config for reaching out kardinal kontrol running in localhost --- kardinal-manager/deployment/k8s.yaml | 7 ++++++- .../cluster_manager/cluster_manager.go | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kardinal-manager/deployment/k8s.yaml b/kardinal-manager/deployment/k8s.yaml index 5f88d144..6ce07e82 100644 --- a/kardinal-manager/deployment/k8s.yaml +++ b/kardinal-manager/deployment/k8s.yaml @@ -11,7 +11,7 @@ metadata: name: kardinal-manager-role rules: - apiGroups: ["*"] - resources: ["pods", "services", "deployments", "virtualservices", "workloadgroups", "workloadentries", "sidecars", "serviceentries", "gateways", "envoyfilters", "destinationrules"] + resources: ["namespaces", "pods", "services", "deployments", "virtualservices", "workloadgroups", "workloadentries", "sidecars", "serviceentries", "gateways", "envoyfilters", "destinationrules"] verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] --- @@ -55,3 +55,8 @@ spec: value: "kubernetes.default.svc" - name: KUBERNETES_SERVICE_PORT value: "443" + - name: CLUSTER_CONFIG_ENDPOINT + # This is valid for reaching out the Kardinal Kontrol if this is running on the host + value: "http://host.minikube.internal:8080/cluster-resources" + - name: FETCHER_JOB_DURATION_SECONDS + value: "10" diff --git a/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go b/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go index 55ac0557..a56c9ef1 100644 --- a/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go +++ b/kardinal-manager/kardinal-manager/cluster_manager/cluster_manager.go @@ -5,6 +5,7 @@ import ( "github.com/kurtosis-tech/kardinal/libs/manager-kontrol-api/api/golang/types" "github.com/kurtosis-tech/stacktrace" "github.com/samber/lo" + "github.com/sirupsen/logrus" istio "istio.io/api/networking/v1alpha3" "istio.io/client-go/pkg/apis/networking/v1alpha3" appsv1 "k8s.io/api/apps/v1" @@ -181,6 +182,11 @@ func (manager *ClusterManager) GetTopologyForNameSpace(namespace string) (map[st func (manager *ClusterManager) ApplyClusterResources(ctx context.Context, clusterResources *types.ClusterResources) error { + if clusterResources == nil { + logrus.Debugf("the received cluster resources is nil, nothing to apply.") + return nil + } + allNSs := [][]string{ lo.Uniq(lo.Map(*clusterResources.Services, func(item corev1.Service, _ int) string { return item.Namespace })), lo.Uniq(lo.Map(*clusterResources.Deployments, func(item appsv1.Deployment, _ int) string { return item.Namespace })), @@ -191,11 +197,9 @@ func (manager *ClusterManager) ApplyClusterResources(ctx context.Context, cluste uniqueNamespaces := lo.Uniq(lo.Flatten(allNSs)) - var ensureNamespacesErr error - for _, namespace := range uniqueNamespaces { if err := manager.ensureNamespace(ctx, namespace); err != nil { - return stacktrace.Propagate(ensureNamespacesErr, "An error occurred while creating or updating cluster namespace '%s'", namespace) + return stacktrace.Propagate(err, "An error occurred while creating or updating cluster namespace '%s'", namespace) } }