2
0

pv.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package kubemodel
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. // @bingen:generate:PersistentVolume
  7. type PersistentVolume struct {
  8. UID string `json:"uid"`
  9. Name string `json:"name"`
  10. StorageClass string `json:"storageClass"`
  11. CSIVolumeHandle string `json:"csiVolumeHandle,omitempty"`
  12. SizeBytes float64 `json:"size"`
  13. Start time.Time `json:"start"`
  14. End time.Time `json:"end"`
  15. }
  16. func (p *PersistentVolume) ValidatePersistentVolume(window Window) error {
  17. if p.UID == "" {
  18. return fmt.Errorf("UID is missing for PersistentVolume with name '%s'", p.Name)
  19. }
  20. if p.Name == "" {
  21. return fmt.Errorf("Name is missing for PersistentVolume '%s'", p.UID)
  22. }
  23. if err := checkWindow(window, p.Start, p.End); err != nil {
  24. return err
  25. }
  26. return nil
  27. }
  28. func (kms *KubeModelSet) RegisterPersistentVolume(pv *PersistentVolume) error {
  29. if err := pv.ValidatePersistentVolume(kms.Window); err != nil {
  30. err = fmt.Errorf("RegisterPersistentVolume: invalid persistent volume: %w", err)
  31. kms.Error(err)
  32. return err
  33. }
  34. if _, ok := kms.PersistentVolumes[pv.UID]; !ok {
  35. kms.PersistentVolumes[pv.UID] = pv
  36. kms.Metadata.ObjectCount++
  37. }
  38. return nil
  39. }