state.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 state
  14. import (
  15. "k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
  16. )
  17. // ContainerCPUAssignments type used in cpu manager state
  18. type ContainerCPUAssignments map[string]map[string]cpuset.CPUSet
  19. // Clone returns a copy of ContainerCPUAssignments
  20. func (as ContainerCPUAssignments) Clone() ContainerCPUAssignments {
  21. ret := make(ContainerCPUAssignments)
  22. for pod := range as {
  23. ret[pod] = make(map[string]cpuset.CPUSet)
  24. for container, cset := range as[pod] {
  25. ret[pod][container] = cset
  26. }
  27. }
  28. return ret
  29. }
  30. // Reader interface used to read current cpu/pod assignment state
  31. type Reader interface {
  32. GetCPUSet(podUID string, containerName string) (cpuset.CPUSet, bool)
  33. GetDefaultCPUSet() cpuset.CPUSet
  34. GetCPUSetOrDefault(podUID string, containerName string) cpuset.CPUSet
  35. GetCPUAssignments() ContainerCPUAssignments
  36. }
  37. type writer interface {
  38. SetCPUSet(podUID string, containerName string, cpuset cpuset.CPUSet)
  39. SetDefaultCPUSet(cpuset cpuset.CPUSet)
  40. SetCPUAssignments(ContainerCPUAssignments)
  41. Delete(podUID string, containerName string)
  42. ClearState()
  43. }
  44. // State interface provides methods for tracking and setting cpu/pod assignment
  45. type State interface {
  46. Reader
  47. writer
  48. }