strategicmerge.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. Copyright 2018 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 patch
  14. // StrategicMerge represents a relative path to a
  15. // stategic merge patch with the format
  16. // https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md
  17. type StrategicMerge string
  18. // Append appends a slice of patch paths to a StrategicMerge slice
  19. func Append(patches []StrategicMerge, paths ...string) []StrategicMerge {
  20. for _, p := range paths {
  21. patches = append(patches, StrategicMerge(p))
  22. }
  23. return patches
  24. }
  25. // Exist determines if a patch path exists in a slice of StrategicMerge
  26. func Exist(patches []StrategicMerge, path string) bool {
  27. for _, p := range patches {
  28. if p == StrategicMerge(path) {
  29. return true
  30. }
  31. }
  32. return false
  33. }