Skip to content

Commit

Permalink
feat: Deduplicate exceptions workflow (#332)
Browse files Browse the repository at this point in the history
* feat: Add exception dedup workflow

* chore: Dedup exceptions

* perf: Added JSON parallel processing
  • Loading branch information
doronkg authored Jul 25, 2024
1 parent 01ce4a6 commit 93e7d80
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 117 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/exceptions-json-sort.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/validate-exception-jsons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Validate Exception JSONs

on:
pull_request:
branches:
- main
paths:
- "pkg/kor/exceptions/**"

jobs:
sort_json:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Validate Exception JSON Sorting
run: make validate-exception-sorting

- name: Validate Exception Deduplication
run: make validate-exception-duplications
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test:

sort-exception-files:
@echo "Sorting exception files..."
@find $(EXCEPTIONS_DIR) -name '$(EXCEPTIONS_FILE_PATTERN)' -exec sh -c ' \
@find $(EXCEPTIONS_DIR) -name '$(EXCEPTIONS_FILE_PATTERN)' | xargs -I{} -P 4 sh -c ' \
jq "with_entries(.value |= sort_by(.Namespace, .ResourceName))" {} > {}.tmp && mv {}.tmp {} \
' \;

Expand All @@ -36,4 +36,27 @@ validate-exception-sorting:
done; \
if [ "$$PRINT_ERR" = 0 ]; then \
echo "Run the following command to sort all files recursively: make sort-exception-files"; \
fi; \
fi; \

dedup-exception-files:
@echo "Deduplicating exception files..."
@find $(EXCEPTIONS_DIR) -type f -name '$(EXCEPTIONS_FILE_PATTERN)' | xargs -I{} -P 4 sh -c ' \
jq '\''keys[0] as $$key | { ($$key): (.[$$key] | group_by(.Namespace, .ResourceName) | map(.[0])) }'\'' "$$1" > "$$1.tmp" && mv "$$1.tmp" "$$1" \
' sh {} \;


validate-exception-duplications:
@PRINT_ERR=1; \
for file in $(wildcard $(EXCEPTIONS_DIR)/*/$(EXCEPTIONS_FILE_PATTERN)); do \
DUPLICATES=$$(jq 'keys[0] as $$key | .[$$key] | group_by(.Namespace, .ResourceName) | map(select(length > 1))' "$$file"); \
if [ "$$DUPLICATES" != "[]" ]; then \
if [ "$$PRINT_ERR" = 1 ]; then \
echo "The following JSON files contain duplications:"; \
PRINT_ERR=0; \
fi; \
echo "\t$$file"; \
fi; \
done; \
if [ "$$PRINT_ERR" = 0 ]; then \
echo "Run the following command to deduplicate all files recursively: make dedup-exception-files"; \
fi; \
8 changes: 0 additions & 8 deletions pkg/kor/exceptions/clusterroles/clusterroles.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@
"Namespace": "",
"ResourceName": "system:aggregated-metrics-reader"
},
{
"Namespace": "",
"ResourceName": "system:aggregated-metrics-reader"
},
{
"Namespace": "",
"ResourceName": "system:auth-delegator"
Expand Down Expand Up @@ -204,10 +200,6 @@
"Namespace": "",
"ResourceName": "system:node-bootstrapper"
},
{
"Namespace": "",
"ResourceName": "system:node-bootstrapper"
},
{
"Namespace": "",
"ResourceName": "system:node-problem-detector"
Expand Down
4 changes: 0 additions & 4 deletions pkg/kor/exceptions/configmaps/configmaps.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
"Namespace": "kube-system",
"ResourceName": "cluster-dns"
},
{
"Namespace": "kube-system",
"ResourceName": "cluster-dns"
},
{
"Namespace": "kube-system",
"ResourceName": "cluster-kubestore"
Expand Down
80 changes: 0 additions & 80 deletions pkg/kor/exceptions/crds/crds.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@
"Namespace": "",
"ResourceName": "etcdsnapshotfiles.k3s.cattle.io"
},
{
"Namespace": "",
"ResourceName": "etcdsnapshotfiles.k3s.cattle.io"
},
{
"Namespace": "",
"ResourceName": "firmwareschemas.metal3.io"
Expand All @@ -152,10 +148,6 @@
"Namespace": "",
"ResourceName": "helmchartconfigs.helm.cattle.io"
},
{
"Namespace": "",
"ResourceName": "helmchartconfigs.helm.cattle.io"
},
{
"Namespace": "",
"ResourceName": "hostfirmwaresettings.metal3.io"
Expand All @@ -180,14 +172,6 @@
"Namespace": "",
"ResourceName": "ingressroutes.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "ingressroutes.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "ingressroutetcps.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "ingressroutetcps.traefik.containo.us"
Expand All @@ -196,22 +180,10 @@
"Namespace": "",
"ResourceName": "ingressroutetcps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "ingressroutetcps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "ingressrouteudps.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "ingressrouteudps.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "ingressrouteudps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "ingressrouteudps.traefik.io"
Expand Down Expand Up @@ -260,14 +232,6 @@
"Namespace": "",
"ResourceName": "middlewares.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "middlewares.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "middlewares.traefik.io"
},
{
"Namespace": "",
"ResourceName": "middlewares.traefik.io"
Expand All @@ -276,14 +240,6 @@
"Namespace": "",
"ResourceName": "middlewaretcps.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "middlewaretcps.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "middlewaretcps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "middlewaretcps.traefik.io"
Expand Down Expand Up @@ -356,14 +312,6 @@
"Namespace": "",
"ResourceName": "serverstransports.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "serverstransports.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "serverstransports.traefik.io"
},
{
"Namespace": "",
"ResourceName": "serverstransports.traefik.io"
Expand All @@ -372,10 +320,6 @@
"Namespace": "",
"ResourceName": "serverstransporttcps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "serverstransporttcps.traefik.io"
},
{
"Namespace": "",
"ResourceName": "serviceattachments.networking.gke.io"
Expand All @@ -400,22 +344,10 @@
"Namespace": "",
"ResourceName": "tlsoptions.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "tlsoptions.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "tlsoptions.traefik.io"
},
{
"Namespace": "",
"ResourceName": "tlsoptions.traefik.io"
},
{
"Namespace": "",
"ResourceName": "tlsstores.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "tlsstores.traefik.containo.us"
Expand All @@ -424,14 +356,6 @@
"Namespace": "",
"ResourceName": "tlsstores.traefik.io"
},
{
"Namespace": "",
"ResourceName": "tlsstores.traefik.io"
},
{
"Namespace": "",
"ResourceName": "traefikservices.traefik.containo.us"
},
{
"Namespace": "",
"ResourceName": "traefikservices.traefik.containo.us"
Expand All @@ -440,10 +364,6 @@
"Namespace": "",
"ResourceName": "traefikservices.traefik.io"
},
{
"Namespace": "",
"ResourceName": "traefikservices.traefik.io"
},
{
"Namespace": "",
"ResourceName": "updateinfos.nodemanagement.gke.io"
Expand Down
4 changes: 0 additions & 4 deletions pkg/kor/exceptions/storageclasses/storageclasses.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
"Namespace": "",
"ResourceName": "local-path"
},
{
"Namespace": "",
"ResourceName": "local-path"
},
{
"Namespace": "",
"ResourceName": "managed"
Expand Down

0 comments on commit 93e7d80

Please sign in to comment.