Skip to content

Commit

Permalink
fix duplicated indexes
Browse files Browse the repository at this point in the history
Signed-off-by: xixi <[email protected]>
  • Loading branch information
Hexilee committed Oct 27, 2023
1 parent dba2e23 commit 53d3437
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/dashboard/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ func (i *timeOrderedIndexes[T]) addIndex(name types.NamespacedName, resource *T,
i.list.Remove(e)
continue
}

if getCreateTime(*resource).After(getCreateTime(*currentResource).Time) {
meta := getMeta(*resource)
currentMeta := getMeta(*currentResource)
if meta.UID == currentMeta.UID && meta.CreationTimestamp.Equal(&currentMeta.CreationTimestamp) {
break
}
if meta.CreationTimestamp.After(currentMeta.CreationTimestamp.Time) {
i.list.InsertAfter(name, e)
return
}
Expand All @@ -103,18 +107,18 @@ func (i *timeOrderedIndexes[T]) debug() []types.NamespacedName {
return names
}

func getCreateTime(r any) metav1.Time {
func getMeta(r any) metav1.ObjectMeta {
switch resource := r.(type) {
case corev1.Pod:
return resource.CreationTimestamp
return resource.ObjectMeta
case corev1.PersistentVolume:
return resource.CreationTimestamp
return resource.ObjectMeta
case corev1.PersistentVolumeClaim:
return resource.CreationTimestamp
return resource.ObjectMeta
case storagev1.StorageClass:
return resource.CreationTimestamp
return resource.ObjectMeta
default:
log.Panicf("unsupported resouce type by time indexes: %s", reflect.TypeOf(r).String())
return metav1.Time{}
return metav1.ObjectMeta{}
}
}

0 comments on commit 53d3437

Please sign in to comment.