mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-21 17:39:59 -04:00
Only emit non-dupicated values as metrics
This commit is contained in:
parent
dfc9d96007
commit
f02ddd0e3b
2 changed files with 32 additions and 3 deletions
|
|
@ -326,9 +326,9 @@ func (c *volumeCache) GetConflicts(logger klog.Logger) []Conflict {
|
|||
logger.V(4).Info("Scraping conflicts")
|
||||
c.dump(logger)
|
||||
|
||||
result := make([]Conflict, 0)
|
||||
result := sets.New[Conflict]()
|
||||
for _, volConflicts := range c.conflicts {
|
||||
result = append(result, volConflicts...)
|
||||
result.Insert(volConflicts...)
|
||||
}
|
||||
return result
|
||||
return result.UnsortedList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -541,6 +541,35 @@ func TestVolumeCache_MultiVolumeConflicts(t *testing.T) {
|
|||
if len(remaining) != 0 {
|
||||
t.Errorf("Expected no conflicts after deleting podA, got %d: %+v", len(remaining), remaining)
|
||||
}
|
||||
|
||||
// Verify deduplication: podD and podE conflict on two volumes with the same labels.
|
||||
// Identical Conflict entries from different volumes must be deduplicated by GetConflicts.
|
||||
podD := cache.ObjectName{Namespace: "ns", Name: "podD"}
|
||||
podE := cache.ObjectName{Namespace: "ns", Name: "podE"}
|
||||
|
||||
c.AddVolume(logger, "vol3", podD, "system_u:system_r:labelD", v1.SELinuxChangePolicyMountOption, "driver1")
|
||||
c.AddVolume(logger, "vol4", podD, "system_u:system_r:labelD", v1.SELinuxChangePolicyMountOption, "driver1")
|
||||
|
||||
conflictsVol3 := c.AddVolume(logger, "vol3", podE, "system_u:system_r:labelE", v1.SELinuxChangePolicyMountOption, "driver1")
|
||||
conflictsVol4 := c.AddVolume(logger, "vol4", podE, "system_u:system_r:labelE", v1.SELinuxChangePolicyMountOption, "driver1")
|
||||
|
||||
if len(conflictsVol3) != len(conflictsVol4) {
|
||||
t.Fatalf("Expected same number of conflicts from vol3 and vol4 (%d vs %d)", len(conflictsVol3), len(conflictsVol4))
|
||||
}
|
||||
if len(conflictsVol3) == 0 {
|
||||
t.Fatal("Expected conflicts between podD and podE")
|
||||
}
|
||||
|
||||
allConflicts = c.GetConflicts(logger)
|
||||
deCount := 0
|
||||
for _, conflict := range allConflicts {
|
||||
if conflict.Pod == podD || conflict.Pod == podE || conflict.OtherPod == podD || conflict.OtherPod == podE {
|
||||
deCount++
|
||||
}
|
||||
}
|
||||
if deCount != len(conflictsVol3) {
|
||||
t.Errorf("Expected %d deduplicated conflicts for podD/podE (from 2 volumes), got %d", len(conflictsVol3), deCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolumeCache_DeletePodConflicts(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue