resource.go 888 B

12345678910111213141516171819202122232425262728293031323334
  1. package kubemodel
  2. // @bingen:generate:Resource
  3. type Resource string
  4. const (
  5. ResourceCPU Resource = "cpu"
  6. ResourceMemory Resource = "memory"
  7. ResourceNvidia Resource = "nvidia.com/gpu"
  8. )
  9. var GPUResources = []Resource{ResourceNvidia}
  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. }