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