pvc.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package kubemodel
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type PersistentVolumeClaim struct {
  7. // Version 1 fields
  8. UID string `json:"uid"`
  9. NamespaceUID string `json:"namespaceUid"`
  10. VolumeUID *string `json:"volumeUid,omitempty"`
  11. PodUID *string `json:"podUid,omitempty"`
  12. Name string `json:"name"`
  13. Labels map[string]string `json:"labels,omitempty"`
  14. Annotations map[string]string `json:"annotations,omitempty"`
  15. StorageClass string `json:"storageClass"`
  16. StorageByteSeconds Measurement `json:"storageByteSeconds"`
  17. RequestedBytes Measurement `json:"requestedBytes"`
  18. Size Measurement `json:"size"` // Size in bytes
  19. VolumeName string `json:"volumeName"`
  20. // ReadWriteOnce, ReadWriteMany, ReadOnlyMany
  21. AccessModes []string `json:"accessModes,omitempty"`
  22. ActualUsedByteSeconds Measurement `json:"actualUsedByteSeconds,omitempty"`
  23. Start time.Time `json:"start"` // PVC creation timestamp
  24. End time.Time `json:"end,omitempty"` // PVC deletion timestamp (nil if still active)
  25. BoundAt time.Time `json:"boundAt,omitempty"`
  26. DurationSeconds Measurement `json:"durationSeconds,omitempty"`
  27. }
  28. func (kms *KubeModelSet) RegisterPVC(uid, name, namespace string) error {
  29. if uid == "" {
  30. err := fmt.Errorf("UID is nil for PVC '%s'", name)
  31. kms.Error(err)
  32. return err
  33. }
  34. if _, ok := kms.PersistentVolumeClaims[uid]; !ok {
  35. namespaceUID := ""
  36. if ns, ok := kms.idx.namespaceByName[namespace]; !ok {
  37. kms.Warnf("RegisterPVC(%s, %s, %s): missing namespace '%s'", uid, name, namespace, namespace)
  38. } else {
  39. namespaceUID = ns.UID
  40. }
  41. kms.PersistentVolumeClaims[uid] = &PersistentVolumeClaim{
  42. UID: uid,
  43. Name: name,
  44. NamespaceUID: namespaceUID,
  45. }
  46. kms.Metadata.ObjectCount++
  47. }
  48. return nil
  49. }