pv.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package kubemodel
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type PersistentVolume struct {
  7. // Version 1 fields
  8. UID string `json:"uid"`
  9. ClusterUID string `json:"clusterUid"`
  10. Name string `json:"name"`
  11. Namespace string `json:"namespace"`
  12. Labels map[string]string `json:"labels,omitempty"`
  13. Annotations map[string]string `json:"annotations,omitempty"`
  14. StorageClass string `json:"storageClass"`
  15. SizeBytes Measurement `json:"size"`
  16. // awsElasticBlockStore, azureDisk, gcePersistentDisk, csi, nfs, local, etc.
  17. Type string `json:"type,omitempty"`
  18. // ebs.csi.aws.com, disk.csi.azure.com, etc.
  19. CSIDriver string `json:"csiDriver,omitempty"`
  20. // Cloud provider's volume identifier
  21. ProviderVolumeID string `json:"providerVolumeId,omitempty"`
  22. // ReadWriteOnce, ReadWriteMany, ReadOnlyMany
  23. AccessModes []string `json:"accessModes,omitempty"`
  24. // Retain, Delete, Recycle
  25. ReclaimPolicy string `json:"reclaimPolicy,omitempty"`
  26. // Cloud region for cross-region cost tracking
  27. Region string `json:"region,omitempty"`
  28. // Availability zone for cross-AZ cost tracking
  29. Zone string `json:"zone,omitempty"`
  30. // Volume lifecycle timestamps
  31. Start time.Time `json:"start"` // Volume creation timestamp
  32. End time.Time `json:"end,omitempty"` // Volume deletion timestamp (nil if still active)
  33. // Duration volume existed within measurement window
  34. DurationSeconds Measurement `json:"durationSeconds"`
  35. // JSON-encoded node affinity for local volumes
  36. NodeAffinity string `json:"nodeAffinity,omitempty"`
  37. // Storage performance characteristics
  38. ProvisionedIOPS Measurement `json:"provisionedIops,omitempty"` // Provisioned IOPS (AWS io1/io2, Azure Premium)
  39. ProvisionedThroughput Measurement `json:"provisionedThroughput,omitempty"` // Provisioned throughput in MB/s
  40. PerformanceMode string `json:"performanceMode,omitempty"` // "generalPurpose", "maxIO", "provisioned"
  41. }
  42. func (kms *KubeModelSet) RegisterVolume(uid, name string) error {
  43. if uid == "" {
  44. err := fmt.Errorf("UID is nil for PersistentVolume '%s'", name)
  45. kms.Error(err)
  46. return err
  47. }
  48. if _, ok := kms.Volumes[uid]; !ok {
  49. clusterUID := ""
  50. if kms.Cluster == nil {
  51. kms.Warnf("RegisterVolume(%s, %s): Cluster is nil", uid, name)
  52. } else {
  53. clusterUID = kms.Cluster.UID
  54. }
  55. kms.Volumes[uid] = &PersistentVolume{
  56. UID: uid,
  57. ClusterUID: clusterUID,
  58. Name: name,
  59. }
  60. kms.Metadata.ObjectCount++
  61. }
  62. return nil
  63. }