Sort the string slice fields of a document to avoid updating the index

unnecessarily
This commit is contained in:
Haiyan Meng
2019-12-16 15:13:59 -08:00
parent 272b7a6fcd
commit 1eb713157c

View File

@@ -2,6 +2,7 @@ package doc
import (
"fmt"
"sort"
"strings"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
@@ -161,6 +162,13 @@ func (doc *KustomizationDocument) ParseYAML() error {
doc.Identifiers = append(doc.Identifiers, key)
}
// Without sorting these fields, every time when the string order in these fields changes,
// the document in the index will be updated.
// Sorting these fields are necessary to avoid a document being updated unnecessarily.
sort.Strings(doc.Kinds)
sort.Strings(doc.Values)
sort.Strings(doc.Identifiers)
return nil
}