Skip to content

Commit

Permalink
keep group/version together in apiVersion label
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Nov 30, 2023
1 parent cbf3470 commit 9444d16
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/kinbiko/jsonassert v1.1.1
github.com/kubescape/backend v0.0.13
github.com/kubescape/go-logger v0.0.21
github.com/kubescape/k8s-interface v0.0.149
github.com/kubescape/k8s-interface v0.0.150
github.com/kubescape/storage v0.0.38
github.com/panjf2000/ants/v2 v2.8.1
github.com/spf13/viper v1.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ github.com/kubescape/backend v0.0.13 h1:N+fH8giGGqvy3ff2li2AwG5guVduhdiPWyvZaZxr
github.com/kubescape/backend v0.0.13/go.mod h1:ug9NFmmxT4DcQx3sgdLRzlLPWMKGHE/fpbcYUm5G5Qo=
github.com/kubescape/go-logger v0.0.21 h1:4ZRIEw3UGUH6BG/cH3yiqFipzQSfGAoCrxlsZuk37ys=
github.com/kubescape/go-logger v0.0.21/go.mod h1:x3HBpZo3cMT/WIdy18BxvVVd5D0e/PWFVk/HiwBNu3g=
github.com/kubescape/k8s-interface v0.0.149 h1:wBgiajoviNA80y+sJFMkntwIVJ6gPZOuorT6gjqWHVM=
github.com/kubescape/k8s-interface v0.0.149/go.mod h1:5sz+5Cjvo98lTbTVDiDA4MmlXxeHSVMW/wR0V3hV4K8=
github.com/kubescape/k8s-interface v0.0.150 h1:6lLRuqUVirpOnobZUz+I1g1RnW4fk88zOO26492Pn9E=
github.com/kubescape/k8s-interface v0.0.150/go.mod h1:5sz+5Cjvo98lTbTVDiDA4MmlXxeHSVMW/wR0V3hV4K8=
github.com/kubescape/storage v0.0.38 h1:LR+QTqjeYw4kM1repIltDLDQGqHgKmG196lQyHP+xUw=
github.com/kubescape/storage v0.0.38/go.mod h1:ObCIVOnVyWwRwU0iuKTzOnrJQScqPgkw0FgvSINwosY=
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
Expand Down
12 changes: 1 addition & 11 deletions pkg/networkmanager/network_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,8 @@ func generateNetworkNeighborsNameFromWlid(parentWlid string) string {
}

func generateNetworkNeighborsLabels(workload k8sinterface.IWorkload) map[string]string {
var apiVersion, apiGroup string
apiVersionSplitted := strings.Split(workload.GetApiVersion(), "/")
if len(apiVersionSplitted) == 2 {
apiGroup = apiVersionSplitted[0]
apiVersion = apiVersionSplitted[1]
} else if len(apiVersionSplitted) == 1 {
apiVersion = apiVersionSplitted[0]
}

return map[string]string{
instanceidhandlerV1.ApiGroupMetadataKey: apiGroup,
instanceidhandlerV1.ApiVersionMetadataKey: apiVersion,
instanceidhandlerV1.ApiVersionMetadataKey: workload.GetApiVersion(),
instanceidhandlerV1.NamespaceMetadataKey: workload.GetNamespace(),
instanceidhandlerV1.KindMetadataKey: strings.ToLower(workload.GetKind()),
instanceidhandlerV1.NameMetadataKey: workload.GetName(),
Expand Down
14 changes: 4 additions & 10 deletions pkg/networkmanager/network_neighbors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) {
Name: "deployment-nginx-deployment",
Namespace: "default",
Labels: map[string]string{
"kubescape.io/workload-api-group": "apps",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-api-version": "apps/v1",
"kubescape.io/workload-namespace": "default",
"kubescape.io/workload-kind": "deployment",
"kubescape.io/workload-name": "nginx-deployment",
Expand Down Expand Up @@ -81,8 +80,7 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) {
Name: "daemonset-fluentd-elasticsearch",
Namespace: "kube-system",
Labels: map[string]string{
"kubescape.io/workload-api-group": "apps",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-api-version": "apps/v1",
"kubescape.io/workload-namespace": "kube-system",
"kubescape.io/workload-kind": "daemonset",
"kubescape.io/workload-name": "fluentd-elasticsearch",
Expand Down Expand Up @@ -116,7 +114,6 @@ func TestGenerateNetworkNeighborsCRD(t *testing.T) {
Name: "pod-nginx-deployment-fcc867f7-dgjrg",
Namespace: "default",
Labels: map[string]string{
"kubescape.io/workload-api-group": "",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-namespace": "default",
"kubescape.io/workload-kind": "pod",
Expand Down Expand Up @@ -228,8 +225,7 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) {
name: "deployment",
workload: deploymentJson,
expectedLabels: map[string]string{
"kubescape.io/workload-api-group": "apps",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-api-version": "apps/v1",
"kubescape.io/workload-namespace": "default",
"kubescape.io/workload-kind": "deployment",
"kubescape.io/workload-name": "nginx-deployment",
Expand All @@ -241,8 +237,7 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) {
name: "daemonset",
workload: daemonsetJson,
expectedLabels: map[string]string{
"kubescape.io/workload-api-group": "apps",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-api-version": "apps/v1",
"kubescape.io/workload-namespace": "kube-system",
"kubescape.io/workload-kind": "daemonset",
"kubescape.io/workload-name": "fluentd-elasticsearch",
Expand All @@ -254,7 +249,6 @@ func TestGenerateNetworkNeighborsLabels(t *testing.T) {
name: "pod",
workload: podJson,
expectedLabels: map[string]string{
"kubescape.io/workload-api-group": "",
"kubescape.io/workload-api-version": "v1",
"kubescape.io/workload-namespace": "default",
"kubescape.io/workload-kind": "pod",
Expand Down

0 comments on commit 9444d16

Please sign in to comment.