Skip to content

Commit

Permalink
Merge pull request #289 from leanix/bugfix/missing-namespace-cronjob
Browse files Browse the repository at this point in the history
Bugfix/missing namespace cronjob
  • Loading branch information
timmeyerLeanIX authored Jun 12, 2023
2 parents aa41f02 + f66b65f commit 32969c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
5 changes: 3 additions & 2 deletions pkg/iris/workloads/models/eventsEcst.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/leanix/leanix-k8s-connector/pkg/iris/common/models"
time2 "time"

"github.com/leanix/leanix-k8s-connector/pkg/iris/common/models"
)

// ECST Discovery Items
Expand Down Expand Up @@ -147,7 +148,7 @@ func CreateEcstDiscoveryEvent(eventType string, changeAction string, data Data,
func GenerateId(workspaceId string, configId string, data Data) string {
scope := fmt.Sprintf(models.EventScopeFormat, workspaceId, configId)
// workspace/{workspaceId}/configuration/{configurationId}/discoveryItem/service/kubernetes/workload/{clusterName}/{workloadType}/{workloadName}
idString := fmt.Sprintf("%s/%s/%s/%s/%s", scope, models.EventClassWorkload, data.Cluster.Name, data.Workload.WorkloadType, data.Workload.Name)
idString := fmt.Sprintf("%s/%s/%s/%s/%s/%s", scope, models.EventClassWorkload, data.Cluster.Name, data.Workload.WorkloadType, data.Workload.Name, data.NamespaceName)
sum := sha256.Sum256([]byte(idString))
id := hex.EncodeToString(sum[:])
return id
Expand Down
23 changes: 12 additions & 11 deletions pkg/iris/workloads/services/events/eventProducer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"testing"

"github.com/leanix/leanix-k8s-connector/pkg/iris/common/models"
common "github.com/leanix/leanix-k8s-connector/pkg/iris/common/services"
workload "github.com/leanix/leanix-k8s-connector/pkg/iris/workloads/models"
"github.com/leanix/leanix-k8s-connector/pkg/mocks"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_eventProducer_filter_created(t *testing.T) {
Expand Down Expand Up @@ -257,11 +258,11 @@ func Test_eventProducer_filter_updated_changed(t *testing.T) {

func Test_eventProducer_createECSTEvents(t *testing.T) {
mockApi := mocks.NewIrisApi(t)
id1 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster1", "deployment", "testWorkload1")))
id1 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster1", "deployment", "testWorkload1", "testNamespace")))
//workspace/testWorkspaceId/configuration/testConfigId/discoveryItem/service/kubernetes/workload/testCluster1/deployment/testWorkload2
id2 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster1", "deployment", "testWorkload2")))
id3 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster2", "deployment", "testWorkload1")))
id4 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster2", "deployment", "testWorkload2")))
id2 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster1", "deployment", "testWorkload2", "testNamespace")))
id3 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster2", "deployment", "testWorkload1", "testNamespace")))
id4 := sha256.Sum256([]byte(fmt.Sprintf("%s/%s/%s/%s/%s/%s", "workspace/testWorkspaceId/configuration/testConfigId", models.EventClassWorkload, "testCluster2", "deployment", "testWorkload2", "testNamespace")))
newData := []workload.Data{
{
Workload: workload.Workload{
Expand All @@ -282,7 +283,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
},
},
ServiceName: "serviceName1",
NamespaceName: "namespaceName1",
NamespaceName: "testNamespace",
Cluster: workload.Cluster{
Name: "testCluster1",
OsImage: "linux",
Expand Down Expand Up @@ -312,7 +313,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
OsImage: "linux",
},
ServiceName: "serviceName2",
NamespaceName: "namespaceName2",
NamespaceName: "testNamespace",
Timestamp: "",
},
{
Expand All @@ -338,7 +339,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
OsImage: "linux",
},
ServiceName: "serviceName3",
NamespaceName: "namespaceName3",
NamespaceName: "testNamespace",
Timestamp: "",
},
}
Expand Down Expand Up @@ -377,7 +378,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
OsImage: "linux",
},
ServiceName: "serviceName1",
NamespaceName: "namespaceName1",
NamespaceName: "testNamespace",
Timestamp: "",
},
},
Expand Down Expand Up @@ -417,7 +418,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
OsImage: "linux",
},
ServiceName: "serviceName2",
NamespaceName: "namespaceName2",
NamespaceName: "testNamespace",
Timestamp: "",
},
},
Expand Down Expand Up @@ -457,7 +458,7 @@ func Test_eventProducer_createECSTEvents(t *testing.T) {
OsImage: "linux",
},
ServiceName: "serviceName3",
NamespaceName: "namespaceName3",
NamespaceName: "testNamespace",
Timestamp: "",
},
},
Expand Down
2 changes: 0 additions & 2 deletions pkg/iris/workloads/services/mapper/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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"
Expand All @@ -19,7 +18,6 @@ import (
)

func Test_MapWorkloads_success(t *testing.T) {
logger.Init()
dummyServices := []runtime.Object{
&corev1.Service{
Spec: corev1.ServiceSpec{
Expand Down
4 changes: 0 additions & 4 deletions pkg/kubernetes/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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"
)
Expand All @@ -14,8 +13,5 @@ func (k *API) Deployments(namespace string) (*v1.DeploymentList, error) {
if err != nil {
return nil, err
}
for _, deployment := range deployments.Items {
logger.Infof("Deployment: name=%s, namespace=%s, labels=%v", deployment.Name, deployment.Namespace, deployment.Labels)
}
return deployments, nil
}
2 changes: 0 additions & 2 deletions pkg/kubernetes/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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"
Expand All @@ -13,7 +12,6 @@ import (
)

func TestDeployments(t *testing.T) {
logger.Init()
// create a dummy nodes
dummyDeployments := []runtime.Object{
&appsv1.Deployment{
Expand Down

0 comments on commit 32969c3

Please sign in to comment.