resource.go 871 B

123456789101112131415161718192021222324252627282930313233
  1. package kubemodel
  2. // @bingen:generate:Resource
  3. type Resource string
  4. const (
  5. ResourceCPU Resource = "cpu"
  6. ResourceMemory Resource = "memory"
  7. ResourceGPU Resource = "gpu"
  8. ResourceStorage Resource = "storage"
  9. )
  10. // @bingen:generate:ResourceQuantity
  11. type ResourceQuantity struct {
  12. Resource Resource `json:"resource"` // @bingen:field[version=1]
  13. Unit Unit `json:"unit"` // @bingen:field[version=1]
  14. Values Stats `json:"values"` // @bingen:field[version=1]
  15. }
  16. // @bingen:generate:ResourceQuantities
  17. type ResourceQuantities map[Resource]ResourceQuantity
  18. func (rqs ResourceQuantities) Set(resource Resource, unit Unit, statType StatType, value float64) {
  19. if _, ok := rqs[resource]; !ok {
  20. rqs[resource] = ResourceQuantity{
  21. Resource: resource,
  22. Unit: unit,
  23. Values: NewStats(),
  24. }
  25. }
  26. rqs[resource].Values[statType] = value
  27. }