From 07cc9fb0be7e733f5c7e92ed0784115b9a6b261c Mon Sep 17 00:00:00 2001 From: timmeyerLeanIX Date: Fri, 9 Jun 2023 13:22:02 +0200 Subject: [PATCH 1/4] Add namespacename to cronjob --- pkg/iris/workloads/services/mapper/cronjob.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/iris/workloads/services/mapper/cronjob.go b/pkg/iris/workloads/services/mapper/cronjob.go index ba11be9..4595b58 100644 --- a/pkg/iris/workloads/services/mapper/cronjob.go +++ b/pkg/iris/workloads/services/mapper/cronjob.go @@ -50,8 +50,9 @@ func (m *workloadMapper) CreateCronjobEcst(cluster models.Cluster, cronJob batch NoOfNodes: cluster.NoOfNodes, K8sVersion: cluster.K8sVersion, }, - ServiceName: service, - Timestamp: cronJob.CreationTimestamp.UTC().Format(time.RFC3339), + NamespaceName: cronJob.Namespace, + ServiceName: service, + Timestamp: cronJob.CreationTimestamp.UTC().Format(time.RFC3339), } return mappedDeployment } From 689ee1160e21efd6a43805f6b32b3f7415cb0cad Mon Sep 17 00:00:00 2001 From: timmeyerLeanIX Date: Fri, 9 Jun 2023 15:14:07 +0200 Subject: [PATCH 2/4] add logging for deployments --- pkg/kubernetes/deployments.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/kubernetes/deployments.go b/pkg/kubernetes/deployments.go index 593a0ca..03d5876 100644 --- a/pkg/kubernetes/deployments.go +++ b/pkg/kubernetes/deployments.go @@ -3,6 +3,7 @@ package kubernetes import ( "context" + "github.com/leanix/leanix-k8s-connector/pkg/logger" v1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -10,6 +11,7 @@ import ( // Deployments gets the list of deployments in a namespace func (k *API) Deployments(namespace string) (*v1.DeploymentList, error) { deployments, err := k.Client.AppsV1().Deployments(namespace).List(context.Background(), metav1.ListOptions{}) + logger.Infof("list of workload deployments: %v", deployments) if err != nil { return nil, err } From 56d0a4a3a2d186f50335a3ee7ccaf848e5a4c660 Mon Sep 17 00:00:00 2001 From: timmeyerLeanIX Date: Fri, 9 Jun 2023 15:35:04 +0200 Subject: [PATCH 3/4] fix test --- pkg/kubernetes/deployments_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/kubernetes/deployments_test.go b/pkg/kubernetes/deployments_test.go index 5ddbebf..854b245 100644 --- a/pkg/kubernetes/deployments_test.go +++ b/pkg/kubernetes/deployments_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/leanix/leanix-k8s-connector/pkg/logger" "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -12,6 +13,7 @@ import ( ) func TestDeployments(t *testing.T) { + logger.Init() // create a dummy nodes dummyDeployments := []runtime.Object{ &appsv1.Deployment{ From 27471218d11df3cb62ebdee7804f448963a5b70b Mon Sep 17 00:00:00 2001 From: timmeyerLeanIX Date: Fri, 9 Jun 2023 15:40:38 +0200 Subject: [PATCH 4/4] fix test --- pkg/iris/workloads/services/mapper/mapping_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/iris/workloads/services/mapper/mapping_test.go b/pkg/iris/workloads/services/mapper/mapping_test.go index 442c87a..7f17c09 100644 --- a/pkg/iris/workloads/services/mapper/mapping_test.go +++ b/pkg/iris/workloads/services/mapper/mapping_test.go @@ -1,8 +1,12 @@ package mapper import ( + "testing" + "time" + "github.com/leanix/leanix-k8s-connector/pkg/iris/workloads/models" "github.com/leanix/leanix-k8s-connector/pkg/kubernetes" + "github.com/leanix/leanix-k8s-connector/pkg/logger" "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" @@ -12,11 +16,10 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/fake" "k8s.io/utils/pointer" - "testing" - "time" ) func Test_MapWorkloads_success(t *testing.T) { + logger.Init() dummyServices := []runtime.Object{ &corev1.Service{ Spec: corev1.ServiceSpec{