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.

change.go 1022B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package v9
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/fluxcd/flux/image"
  6. )
  7. type ChangeKind string
  8. const (
  9. GitChange ChangeKind = "git"
  10. ImageChange ChangeKind = "image"
  11. )
  12. func (k ChangeKind) MarshalJSON() ([]byte, error) {
  13. return json.Marshal(string(k))
  14. }
  15. var ErrUnknownChange = errors.New("unknown kind of change")
  16. type Change struct {
  17. Kind ChangeKind // essentially a type tag
  18. Source interface{} // what changed
  19. }
  20. func (c *Change) UnmarshalJSON(bs []byte) error {
  21. type raw struct {
  22. Kind ChangeKind
  23. Source json.RawMessage
  24. }
  25. var r raw
  26. var err error
  27. if err = json.Unmarshal(bs, &r); err != nil {
  28. return err
  29. }
  30. c.Kind = r.Kind
  31. switch r.Kind {
  32. case GitChange:
  33. var git GitUpdate
  34. err = json.Unmarshal(r.Source, &git)
  35. c.Source = git
  36. case ImageChange:
  37. var image ImageUpdate
  38. err = json.Unmarshal(r.Source, &image)
  39. c.Source = image
  40. default:
  41. return ErrUnknownChange
  42. }
  43. return err
  44. }
  45. type ImageUpdate struct {
  46. Name image.Name
  47. }
  48. type GitUpdate struct {
  49. URL, Branch string
  50. }