pv.go 2.5 KB

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