Skip to content

Commit

Permalink
feat: sort .status.conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 6, 2024
1 parent b5b5eef commit 2291086
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubernetes
import (
"encoding/json"
"fmt"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -595,6 +596,19 @@ func cleanKubernetesObject(obj map[string]any) (map[string]any, error) {
o.Delete("status", "observedGeneration")
o.Delete("status", "lastTransitionTime")

if cData := o.S("status", "conditions").Data(); cData != nil {
if conditions, ok := cData.([]any); ok {
// sort conditions to prevent unnecessary diffs
sort.Slice(conditions, func(i, j int) bool {
return gabs.Wrap(conditions[i]).S("type").Data().(string) < gabs.Wrap(conditions[j]).S("type").Data().(string)
})

if _, err := o.Set(conditions, "status", "conditions"); err != nil {
return nil, fmt.Errorf("failed to set sorted status.conditions: %w", err)
}
}
}

c, _ := o.ArrayCount("status", "conditions")
for i := 0; i < c; i += 1 {
o.Delete("status", "conditions", strconv.Itoa(i), "lastTransitionTime")
Expand Down

0 comments on commit 2291086

Please sign in to comment.