GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filter.go 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package update
  2. import (
  3. "github.com/weaveworks/flux"
  4. "github.com/weaveworks/flux/image"
  5. )
  6. const (
  7. Locked = "locked"
  8. NotIncluded = "not included"
  9. Excluded = "excluded"
  10. DifferentImage = "a different image"
  11. NotInCluster = "not running in cluster"
  12. NotInRepo = "not found in repository"
  13. ImageNotFound = "cannot find one or more images"
  14. ImageUpToDate = "image(s) up to date"
  15. DoesNotUseImage = "does not use image(s)"
  16. )
  17. type SpecificImageFilter struct {
  18. Img image.Ref
  19. }
  20. func (f *SpecificImageFilter) Filter(u ControllerUpdate) ControllerResult {
  21. // If there are no containers, then we can't check the image.
  22. if len(u.Controller.Containers.Containers) == 0 {
  23. return ControllerResult{
  24. Status: ReleaseStatusIgnored,
  25. Error: NotInCluster,
  26. }
  27. }
  28. // For each container in update
  29. for _, c := range u.Controller.Containers.Containers {
  30. if c.Image.CanonicalName() == f.Img.CanonicalName() {
  31. // We want to update this
  32. return ControllerResult{}
  33. }
  34. }
  35. return ControllerResult{
  36. Status: ReleaseStatusIgnored,
  37. Error: DifferentImage,
  38. }
  39. }
  40. type ExcludeFilter struct {
  41. IDs []flux.ResourceID
  42. }
  43. func (f *ExcludeFilter) Filter(u ControllerUpdate) ControllerResult {
  44. for _, id := range f.IDs {
  45. if u.ResourceID == id {
  46. return ControllerResult{
  47. Status: ReleaseStatusIgnored,
  48. Error: Excluded,
  49. }
  50. }
  51. }
  52. return ControllerResult{}
  53. }
  54. type IncludeFilter struct {
  55. IDs []flux.ResourceID
  56. }
  57. func (f *IncludeFilter) Filter(u ControllerUpdate) ControllerResult {
  58. for _, id := range f.IDs {
  59. if u.ResourceID == id {
  60. return ControllerResult{}
  61. }
  62. }
  63. return ControllerResult{
  64. Status: ReleaseStatusIgnored,
  65. Error: NotIncluded,
  66. }
  67. }
  68. type LockedFilter struct {
  69. IDs []flux.ResourceID
  70. }
  71. func (f *LockedFilter) Filter(u ControllerUpdate) ControllerResult {
  72. for _, id := range f.IDs {
  73. if u.ResourceID == id {
  74. return ControllerResult{
  75. Status: ReleaseStatusSkipped,
  76. Error: Locked,
  77. }
  78. }
  79. }
  80. return ControllerResult{}
  81. }