pleg.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 Yunion
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package pleg
  15. // PodLifecycleEventType define the event type of pod life cycle events.
  16. type PodLifecycleEventType string
  17. const (
  18. // ContainerStarted - event type when the new state of container is running
  19. ContainerStarted PodLifecycleEventType = "ContainerStarted"
  20. // ContainerDied - event type when the new state of container is exited.
  21. ContainerDied PodLifecycleEventType = "ContainerDied"
  22. // ContainerRemoved - event type when the old state of container is exited.
  23. ContainerRemoved PodLifecycleEventType = "ContainerRemoved"
  24. // PodSync is used to trigger syncing of a pod when the observed change of
  25. // the state of the pod cannot be captured by any single event above.
  26. PodSync PodLifecycleEventType = "PodSync"
  27. // ContainerChanged - event type when the new state of container is unknown.
  28. ContainerChanged PodLifecycleEventType = "ContainerChanged"
  29. )
  30. // PodLifecycleEvent is an event that reflects the change of the pod state.
  31. type PodLifecycleEvent struct {
  32. // The pod ID.
  33. Id string
  34. // The type of the event.
  35. Type PodLifecycleEventType
  36. // The accompanied data which varies based on the event type.
  37. // - ContainerStarted/ContainerStopped: the container name (string).
  38. // - All other event types: unused.
  39. Data interface{}
  40. }
  41. // PodLifecycleEventGenerator contains functions for generating pod life cycle events.
  42. type PodLifecycleEventGenerator interface {
  43. Start()
  44. Watch() chan *PodLifecycleEvent
  45. }