pvc.go 2.0 KB

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