Skip to content

Commit

Permalink
summary objects - move to lower case
Browse files Browse the repository at this point in the history
Signed-off-by: rcohencyberarmor <rcohen@armosec.io>
  • Loading branch information
rcohencyberarmor committed Sep 3, 2023
1 parent 5c8c0c9 commit 44d4445
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions repositories/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/armosec/utils-k8s-go/wlid"
Expand Down Expand Up @@ -297,7 +298,7 @@ func enrichSummaryManifestObjectLabels(ctx context.Context, labels map[string]st

enrichedLabels[v1.ApiGroupMetadataKey] = groupVersionScheme.Group
enrichedLabels[v1.ApiVersionMetadataKey] = groupVersionScheme.Version
enrichedLabels[v1.KindMetadataKey] = workloadKind
enrichedLabels[v1.KindMetadataKey] = strings.ToLower(workloadKind)
enrichedLabels[v1.NameMetadataKey] = wlid.GetNameFromWlid(workload.Wlid)
enrichedLabels[v1.NamespaceMetadataKey] = wlid.GetNamespaceFromWlid(workload.Wlid)
enrichedLabels[v1.ContainerNameMetadataKey] = workload.ContainerName
Expand All @@ -310,9 +311,9 @@ func GetCVESummaryK8sResourceName(ctx context.Context) (string, error) {
if !ok {
return "", domain.ErrCastingWorkload
}
kind := wlid.GetKindFromWlid(workload.Wlid)
name := wlid.GetNameFromWlid(workload.Wlid)
contName := workload.ContainerName
kind := strings.ToLower(wlid.GetKindFromWlid(workload.Wlid))
name := strings.ToLower(wlid.GetNameFromWlid(workload.Wlid))
contName := strings.ToLower(workload.ContainerName)

return fmt.Sprintf(vulnSummaryContNameFormat, kind, name, contName), nil
}
Expand Down
18 changes: 9 additions & 9 deletions repositories/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func TestAPIServerStore_enrichSummaryManifestObjectLabels(t *testing.T) {
workload domain.ScanCommand
}{
{
k8sResourceType: "Deployment",
k8sResourceType: "deployment",
k8sResourceGroup: "apps",
k8sResourceVersion: "v1",
k8sResourceName: "ccc",
Expand All @@ -489,7 +489,7 @@ func TestAPIServerStore_enrichSummaryManifestObjectLabels(t *testing.T) {
},
},
{
k8sResourceType: "CronJob",
k8sResourceType: "cronjob",
k8sResourceGroup: "batch",
k8sResourceVersion: "v1",
k8sResourceName: "123",
Expand All @@ -504,7 +504,7 @@ func TestAPIServerStore_enrichSummaryManifestObjectLabels(t *testing.T) {
},
},
{
k8sResourceType: "Job",
k8sResourceType: "job",
k8sResourceGroup: "batch",
k8sResourceVersion: "v1",
k8sResourceName: "anyJob",
Expand Down Expand Up @@ -617,42 +617,42 @@ func TestAPIServerStore_getCVESummaryK8sResourceName(t *testing.T) {
Wlid: "wlid://cluster-aaa/deployment-default/deployment-nginx",
ContainerName: "nginx",
},
expRes: "Deployment-nginx-nginx",
expRes: "deployment-nginx-nginx",
},
{
workload: domain.ScanCommand{
Wlid: "wlid://cluster-aaa/deployment-default/deployment-nginx",
ContainerName: "nginx",
},
expRes: "Deployment-nginx-nginx",
expRes: "deployment-nginx-nginx",
},
{
workload: domain.ScanCommand{
Wlid: "wlid://cluster-aaa/deployment-kubescape/deployment-kubescape",
ContainerName: "kubescape",
},
expRes: "Deployment-kubescape-kubescape",
expRes: "deployment-kubescape-kubescape",
},
{
workload: domain.ScanCommand{
Wlid: "wlid://cluster-aaa/namespace-kubescape/deployment-kubevuln",
ContainerName: "kubevuln",
},
expRes: "Deployment-kubevuln-kubevuln",
expRes: "deployment-kubevuln-kubevuln",
},
{
workload: domain.ScanCommand{
Wlid: "wlid://cluster-aaa/namespace-kubescape/deployment-operator",
ContainerName: "operator",
},
expRes: "Deployment-operator-operator",
expRes: "deployment-operator-operator",
},
{
workload: domain.ScanCommand{
Wlid: "wlid://cluster-aaa/namespace-kube-system/pod-etcd-control-plane",
ContainerName: "etcd-control-plane",
},
expRes: "Pod-etcd-control-plane-etcd-control-plane",
expRes: "pod-etcd-control-plane-etcd-control-plane",
},
}

Expand Down

0 comments on commit 44d4445

Please sign in to comment.