index.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package scrape
  2. import (
  3. "github.com/opencost/opencost/core/pkg/clustercache"
  4. "k8s.io/apimachinery/pkg/types"
  5. )
  6. // pvcKey is a composite key for a PersistentVolumeClaim (name + namespace).
  7. type pvcKey struct {
  8. name string
  9. namespace string
  10. }
  11. // buildNodeIndex returns a map from node name to UID.
  12. func buildNodeIndex(nodes []*clustercache.Node) map[string]types.UID {
  13. m := make(map[string]types.UID, len(nodes))
  14. for _, node := range nodes {
  15. m[node.Name] = node.UID
  16. }
  17. return m
  18. }
  19. // buildNamespaceIndex returns a map from namespace name to UID.
  20. func buildNamespaceIndex(namespaces []*clustercache.Namespace) map[string]types.UID {
  21. m := make(map[string]types.UID, len(namespaces))
  22. for _, ns := range namespaces {
  23. m[ns.Name] = ns.UID
  24. }
  25. return m
  26. }
  27. // buildPVCIndex returns a map from (name, namespace) to PVC UID.
  28. func buildPVCIndex(pvcs []*clustercache.PersistentVolumeClaim) map[pvcKey]types.UID {
  29. m := make(map[pvcKey]types.UID, len(pvcs))
  30. for _, pvc := range pvcs {
  31. m[pvcKey{name: pvc.Name, namespace: pvc.Namespace}] = pvc.UID
  32. }
  33. return m
  34. }
  35. // buildPVIndex returns a map from PV name to UID.
  36. func buildPVIndex(pvs []*clustercache.PersistentVolume) map[string]types.UID {
  37. m := make(map[string]types.UID, len(pvs))
  38. for _, pv := range pvs {
  39. m[pv.Name] = pv.UID
  40. }
  41. return m
  42. }