yonahd / kor

A Golang Tool to discover unused Kubernetes Resources
MIT License
1.04k stars 96 forks source link

fix(GetUnusedAll) - JSON concatenation #227

Closed doronkg closed 8 months ago

doronkg commented 8 months ago

This PR aims to resolve #226. Currently when executing GetUnusedAll() with JSON format, instead of merging the two lists, it appends them. This also resolves the Error parsing JSON: invalid character '{' after top-level value returned from kor exporter.

Before the fix:

$ kor all -o json
{
  "test": {
    "ConfigMap": null,
    "DaemonSet": null,
    "Deployment": null,
    "Hpa": [
      "php-apache"
    ],
    "Ingress": [
      "test-ingress-1-work"
    ],
    "Job": null,
    "Pdb": null,
    "Pvc": [
      "myclaim"
    ],
    "ReplicaSet": null,
    "Role": null,
    "Secret": null,
    "Service": [
      "app1-service",
      "app2-service"
    ],
    "ServiceAccount": null,
    "StatefulSet": null
  }
}{
  "": {
    "ClusterRole": [
      "admin",
      "view"
    ],
    "Crd": [
      "thanosrulers.monitoring.coreos.com"
    ],
    "Pv": null,
    "StorageClass": null
  }
}

After the fix:

$ kor all -o json
{
  "": {
    "ClusterRole": [
      "admin",
      "view"
    ],
    "Crd": [
      "thanosrulers.monitoring.coreos.com"
    ],
    "Pv": null,
    "StorageClass": null
  },
  "test": {
    "ConfigMap": null,
    "DaemonSet": null,
    "Deployment": null,
    "Hpa": [
      "php-apache"
    ],
    "Ingress": [
      "test-ingress-1-work"
    ],
    "Job": null,
    "Pdb": null,
    "Pvc": [
      "myclaim"
    ],
    "ReplicaSet": null,
    "Role": null,
    "Secret": null,
    "Service": [
      "app1-service",
      "app2-service"
    ],
    "ServiceAccount": null,
    "StatefulSet": null
  }
}
codecov-commenter commented 8 months ago

Codecov Report

Attention: Patch coverage is 0% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 47.20%. Comparing base (4a79f02) to head (6cda98e).

Files Patch % Lines
pkg/kor/all.go 0.00% 25 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #227 +/- ## ========================================== - Coverage 47.58% 47.20% -0.38% ========================================== Files 32 32 Lines 2915 2938 +23 ========================================== Hits 1387 1387 - Misses 1354 1377 +23 Partials 174 174 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.