1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package merge
- import (
- "fmt"
- "sort"
- "strings"
- "sigs.k8s.io/structured-merge-diff/fieldpath"
- )
- type Conflict struct {
- Manager string
- Path fieldpath.Path
- }
- var _ error = Conflict{}
- func (c Conflict) Error() string {
- return fmt.Sprintf("conflict with %q: %v", c.Manager, c.Path)
- }
- type Conflicts []Conflict
- var _ error = Conflicts{}
- func (conflicts Conflicts) Error() string {
- if len(conflicts) == 1 {
- return conflicts[0].Error()
- }
- m := map[string][]fieldpath.Path{}
- for _, conflict := range conflicts {
- m[conflict.Manager] = append(m[conflict.Manager], conflict.Path)
- }
- managers := []string{}
- for manager := range m {
- managers = append(managers, manager)
- }
-
- sort.Strings(managers)
- messages := []string{}
- for _, manager := range managers {
- messages = append(messages, fmt.Sprintf("conflicts with %q:", manager))
- for _, path := range m[manager] {
- messages = append(messages, fmt.Sprintf("- %v", path))
- }
- }
- return strings.Join(messages, "\n")
- }
- func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts {
- conflicts := []Conflict{}
- for manager, set := range sets {
- set.Iterate(func(p fieldpath.Path) {
- conflicts = append(conflicts, Conflict{
- Manager: manager,
- Path: p,
- })
- })
- }
- return conflicts
- }
|