interfaces.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. Copyright 2016 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 lifecycle
  14. import "k8s.io/kubernetes/pkg/api"
  15. // PodAdmitAttributes is the context for a pod admission decision.
  16. // The member fields of this struct should never be mutated.
  17. type PodAdmitAttributes struct {
  18. // the pod to evaluate for admission
  19. Pod *api.Pod
  20. // all pods bound to the kubelet excluding the pod being evaluated
  21. OtherPods []*api.Pod
  22. }
  23. // PodAdmitResult provides the result of a pod admission decision.
  24. type PodAdmitResult struct {
  25. // if true, the pod should be admitted.
  26. Admit bool
  27. // a brief single-word reason why the pod could not be admitted.
  28. Reason string
  29. // a brief message explaining why the pod could not be admitted.
  30. Message string
  31. }
  32. // PodAdmitHandler is notified during pod admission.
  33. type PodAdmitHandler interface {
  34. // Admit evaluates if a pod can be admitted.
  35. Admit(attrs *PodAdmitAttributes) PodAdmitResult
  36. }
  37. // PodAdmitTarget maintains a list of handlers to invoke.
  38. type PodAdmitTarget interface {
  39. // AddPodAdmitHandler adds the specified handler.
  40. AddPodAdmitHandler(a PodAdmitHandler)
  41. }
  42. // PodSyncLoopHandler is invoked during each sync loop iteration.
  43. type PodSyncLoopHandler interface {
  44. // ShouldSync returns true if the pod needs to be synced.
  45. // This operation must return immediately as its called for each pod.
  46. // The provided pod should never be modified.
  47. ShouldSync(pod *api.Pod) bool
  48. }
  49. // PodSyncLoopTarget maintains a list of handlers to pod sync loop.
  50. type PodSyncLoopTarget interface {
  51. // AddPodSyncLoopHandler adds the specified handler.
  52. AddPodSyncLoopHandler(a PodSyncLoopHandler)
  53. }
  54. // ShouldEvictResponse provides the result of a should evict request.
  55. type ShouldEvictResponse struct {
  56. // if true, the pod should be evicted.
  57. Evict bool
  58. // a brief CamelCase reason why the pod should be evicted.
  59. Reason string
  60. // a brief message why the pod should be evicted.
  61. Message string
  62. }
  63. // PodSyncHandler is invoked during each sync pod operation.
  64. type PodSyncHandler interface {
  65. // ShouldEvict is invoked during each sync pod operation to determine
  66. // if the pod should be evicted from the kubelet. If so, the pod status
  67. // is updated to mark its phase as failed with the provided reason and message,
  68. // and the pod is immediately killed.
  69. // This operation must return immediately as its called for each sync pod.
  70. // The provided pod should never be modified.
  71. ShouldEvict(pod *api.Pod) ShouldEvictResponse
  72. }
  73. // PodSyncTarget maintains a list of handlers to pod sync.
  74. type PodSyncTarget interface {
  75. // AddPodSyncHandler adds the specified handler
  76. AddPodSyncHandler(a PodSyncHandler)
  77. }
  78. // PodLifecycleTarget groups a set of lifecycle interfaces for convenience.
  79. type PodLifecycleTarget interface {
  80. PodAdmitTarget
  81. PodSyncLoopTarget
  82. PodSyncTarget
  83. }
  84. // PodAdmitHandlers maintains a list of handlers to pod admission.
  85. type PodAdmitHandlers []PodAdmitHandler
  86. // AddPodAdmitHandler adds the specified observer.
  87. func (handlers *PodAdmitHandlers) AddPodAdmitHandler(a PodAdmitHandler) {
  88. *handlers = append(*handlers, a)
  89. }
  90. // PodSyncLoopHandlers maintains a list of handlers to pod sync loop.
  91. type PodSyncLoopHandlers []PodSyncLoopHandler
  92. // AddPodSyncLoopHandler adds the specified observer.
  93. func (handlers *PodSyncLoopHandlers) AddPodSyncLoopHandler(a PodSyncLoopHandler) {
  94. *handlers = append(*handlers, a)
  95. }
  96. // PodSyncHandlers maintains a list of handlers to pod sync.
  97. type PodSyncHandlers []PodSyncHandler
  98. // AddPodSyncHandler adds the specified handler.
  99. func (handlers *PodSyncHandlers) AddPodSyncHandler(a PodSyncHandler) {
  100. *handlers = append(*handlers, a)
  101. }