resource.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package core
  14. import (
  15. "k8s.io/apimachinery/pkg/api/resource"
  16. )
  17. func (self ResourceName) String() string {
  18. return string(self)
  19. }
  20. // Returns the CPU limit if specified.
  21. func (self *ResourceList) Cpu() *resource.Quantity {
  22. if val, ok := (*self)[ResourceCPU]; ok {
  23. return &val
  24. }
  25. return &resource.Quantity{Format: resource.DecimalSI}
  26. }
  27. // Returns the Memory limit if specified.
  28. func (self *ResourceList) Memory() *resource.Quantity {
  29. if val, ok := (*self)[ResourceMemory]; ok {
  30. return &val
  31. }
  32. return &resource.Quantity{Format: resource.BinarySI}
  33. }
  34. func (self *ResourceList) Pods() *resource.Quantity {
  35. if val, ok := (*self)[ResourcePods]; ok {
  36. return &val
  37. }
  38. return &resource.Quantity{}
  39. }
  40. func (self *ResourceList) StorageEphemeral() *resource.Quantity {
  41. if val, ok := (*self)[ResourceEphemeralStorage]; ok {
  42. return &val
  43. }
  44. return &resource.Quantity{}
  45. }