visitor.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright 2017 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 apply
  14. // Strategy implements a strategy for merging recorded, local and remote values contained
  15. // in an element and returns the merged result.
  16. // Follows the visitor pattern
  17. type Strategy interface {
  18. // MergeList is invoked by ListElements when Merge is called
  19. MergeList(ListElement) (Result, error)
  20. // MergeMap is invoked by MapElements when Merge is called
  21. MergeMap(MapElement) (Result, error)
  22. // MergeType is invoked by TypeElements when Merge is called
  23. MergeType(TypeElement) (Result, error)
  24. // MergePrimitive is invoked by PrimitiveElements when Merge is called
  25. MergePrimitive(PrimitiveElement) (Result, error)
  26. // MergeEmpty is invoked by EmptyElements when Merge is called
  27. MergeEmpty(EmptyElement) (Result, error)
  28. }
  29. // Operation records whether a field should be set or dropped
  30. type Operation int
  31. const (
  32. // ERROR is an error during merge
  33. ERROR Operation = iota
  34. // SET sets the field on an object
  35. SET
  36. // DROP drops the field from an object
  37. DROP
  38. )
  39. // Result is the result of merging fields
  40. type Result struct {
  41. // Operation is the operation that should be performed for the merged field
  42. Operation Operation
  43. // MergedResult is the new merged value
  44. MergedResult interface{}
  45. }
  46. const (
  47. // MergeStrategy is the strategy to merge the local and remote values
  48. MergeStrategy = "merge"
  49. // RetainKeysStrategy is the strategy to merge the local and remote values, but drop any fields not defined locally
  50. RetainKeysStrategy = "retainKeys"
  51. // ReplaceStrategy is the strategy to replace the remote value with the local value
  52. ReplaceStrategy = "replace"
  53. )