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.

mock.go 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package mock
  2. import (
  3. "bytes"
  4. "context"
  5. "github.com/fluxcd/flux/cluster"
  6. "github.com/fluxcd/flux/image"
  7. "github.com/fluxcd/flux/manifests"
  8. "github.com/fluxcd/flux/resource"
  9. "github.com/fluxcd/flux/ssh"
  10. )
  11. // Doubles as a cluster.Cluster and cluster.Manifests implementation
  12. type Mock struct {
  13. AllWorkloadsFunc func(ctx context.Context, maybeNamespace string) ([]cluster.Workload, error)
  14. SomeWorkloadsFunc func(ctx context.Context, ids []resource.ID) ([]cluster.Workload, error)
  15. IsAllowedResourceFunc func(resource.ID) bool
  16. PingFunc func() error
  17. ExportFunc func(ctx context.Context) ([]byte, error)
  18. SyncFunc func(cluster.SyncSet) error
  19. PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
  20. SetWorkloadContainerImageFunc func(def []byte, id resource.ID, container string, newImageID image.Ref) ([]byte, error)
  21. LoadManifestsFunc func(base string, paths []string) (map[string]resource.Resource, error)
  22. ParseManifestFunc func(def []byte, source string) (map[string]resource.Resource, error)
  23. UpdateWorkloadPoliciesFunc func([]byte, resource.ID, resource.PolicyUpdate) ([]byte, error)
  24. CreateManifestPatchFunc func(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error)
  25. ApplyManifestPatchFunc func(originalManifests, patch []byte, originalSource, patchSource string) ([]byte, error)
  26. AppendManifestToBufferFunc func([]byte, *bytes.Buffer) error
  27. }
  28. var _ cluster.Cluster = &Mock{}
  29. var _ manifests.Manifests = &Mock{}
  30. func (m *Mock) AllWorkloads(ctx context.Context, maybeNamespace string) ([]cluster.Workload, error) {
  31. return m.AllWorkloadsFunc(ctx, maybeNamespace)
  32. }
  33. func (m *Mock) SomeWorkloads(ctx context.Context, ids []resource.ID) ([]cluster.Workload, error) {
  34. return m.SomeWorkloadsFunc(ctx, ids)
  35. }
  36. func (m *Mock) IsAllowedResource(id resource.ID) bool {
  37. return m.IsAllowedResourceFunc(id)
  38. }
  39. func (m *Mock) Ping() error {
  40. return m.PingFunc()
  41. }
  42. func (m *Mock) Export(ctx context.Context) ([]byte, error) {
  43. return m.ExportFunc(ctx)
  44. }
  45. func (m *Mock) Sync(c cluster.SyncSet) error {
  46. return m.SyncFunc(c)
  47. }
  48. func (m *Mock) PublicSSHKey(regenerate bool) (ssh.PublicKey, error) {
  49. return m.PublicSSHKeyFunc(regenerate)
  50. }
  51. func (m *Mock) SetWorkloadContainerImage(def []byte, id resource.ID, container string, newImageID image.Ref) ([]byte, error) {
  52. return m.SetWorkloadContainerImageFunc(def, id, container, newImageID)
  53. }
  54. func (m *Mock) LoadManifests(baseDir string, paths []string) (map[string]resource.Resource, error) {
  55. return m.LoadManifestsFunc(baseDir, paths)
  56. }
  57. func (m *Mock) ParseManifest(def []byte, source string) (map[string]resource.Resource, error) {
  58. return m.ParseManifestFunc(def, source)
  59. }
  60. func (m *Mock) UpdateWorkloadPolicies(def []byte, id resource.ID, p resource.PolicyUpdate) ([]byte, error) {
  61. return m.UpdateWorkloadPoliciesFunc(def, id, p)
  62. }
  63. func (m *Mock) CreateManifestPatch(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error) {
  64. return m.CreateManifestPatchFunc(originalManifests, modifiedManifests, originalSource, modifiedSource)
  65. }
  66. func (m *Mock) ApplyManifestPatch(originalManifests, patch []byte, originalSource, patchSource string) ([]byte, error) {
  67. return m.ApplyManifestPatch(originalManifests, patch, originalSource, patchSource)
  68. }
  69. func (m *Mock) AppendManifestToBuffer(b []byte, buf *bytes.Buffer) error {
  70. return m.AppendManifestToBuffer(b, buf)
  71. }