primitive_element.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. import "reflect"
  15. // PrimitiveElement contains the recorded, local and remote values for a field
  16. // of type primitive
  17. type PrimitiveElement struct {
  18. // FieldMetaImpl contains metadata about the field from openapi
  19. FieldMetaImpl
  20. // RawElementData contains the values the field was set to
  21. RawElementData
  22. }
  23. // Merge implements Element.Merge
  24. func (e PrimitiveElement) Merge(v Strategy) (Result, error) {
  25. return v.MergePrimitive(e)
  26. }
  27. var _ Element = &PrimitiveElement{}
  28. // HasConflict returns ConflictError if primitive element has conflict field.
  29. // Conflicts happen when either of the following conditions:
  30. // 1. A field is specified in both recorded and remote values, but does not match.
  31. // 2. A field is specified in recorded values, but missing in remote values.
  32. func (e PrimitiveElement) HasConflict() error {
  33. if e.HasRecorded() && e.HasRemote() {
  34. if !reflect.DeepEqual(e.GetRecorded(), e.GetRemote()) {
  35. return NewConflictError(e)
  36. }
  37. }
  38. if e.HasRecorded() && !e.HasRemote() {
  39. return NewConflictError(e)
  40. }
  41. return nil
  42. }
  43. var _ ConflictDetector = &PrimitiveElement{}