Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summary objects - move to lower case #151

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading