diff --git a/pkg/gather/clusterconfig/pod_network_connectivity_checks.go b/pkg/gather/clusterconfig/pod_network_connectivity_checks.go index 46fb91453..dc6e50c59 100644 --- a/pkg/gather/clusterconfig/pod_network_connectivity_checks.go +++ b/pkg/gather/clusterconfig/pod_network_connectivity_checks.go @@ -3,6 +3,7 @@ package clusterconfig import ( "context" "encoding/json" + "time" controlplanev1 "github.com/openshift/api/operatorcontrolplane/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -75,12 +76,14 @@ func gatherPNCC(ctx context.Context, dynamicClient dynamic.Interface, coreClient } } - reasons := map[string]map[string]int{} + reasons := map[string]map[string]time.Time{} for _, entry := range unsuccessful { if _, exists := reasons[entry.Reason]; !exists { - reasons[entry.Reason] = map[string]int{} + reasons[entry.Reason] = map[string]time.Time{} + } + if oldTime, exists := reasons[entry.Reason][entry.Message]; !exists || entry.Start.After(oldTime) { + reasons[entry.Reason][entry.Message] = entry.Start.Time } - reasons[entry.Reason][entry.Message]++ } return []record.Record{{Name: "config/podnetworkconnectivitychecks", Item: record.JSONMarshaller{Object: reasons}}}, nil diff --git a/pkg/gather/clusterconfig/pod_network_connectivity_checks_test.go b/pkg/gather/clusterconfig/pod_network_connectivity_checks_test.go index 7cd388123..e4872ade0 100644 --- a/pkg/gather/clusterconfig/pod_network_connectivity_checks_test.go +++ b/pkg/gather/clusterconfig/pod_network_connectivity_checks_test.go @@ -4,6 +4,7 @@ import ( "context" "reflect" "testing" + "time" "github.com/openshift/insights-operator/pkg/record" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -58,7 +59,7 @@ status: if !ok { t.Fatalf("unexpected type of record item in the first run: %q", rec.Name) } - if !reflect.DeepEqual(recItem.Object, map[string]map[string]int{}) { + if !reflect.DeepEqual(recItem.Object, map[string]map[string]time.Time{}) { t.Fatalf("unexpected value of record item in the first run: %#v", recItem) } @@ -80,7 +81,7 @@ status: if !ok { t.Fatalf("unexpected type of record item in the second run: %q", rec.Name) } - if !reflect.DeepEqual(recItem.Object, map[string]map[string]int{"TestReason": {"TestMessage": 1}}) { + if !reflect.DeepEqual(recItem.Object, map[string]map[string]time.Time{"TestReason": {"TestMessage": time.Time{}}}) { t.Fatalf("unexpected value of record item in the second run: %#v", recItem) } }