From 1eb713157ccc0fee511aa2089ba5cd5e32854770 Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Mon, 16 Dec 2019 15:13:59 -0800 Subject: [PATCH] Sort the string slice fields of a document to avoid updating the index unnecessarily --- api/internal/crawl/doc/doc.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/internal/crawl/doc/doc.go b/api/internal/crawl/doc/doc.go index 50241e5ad..6ab581458 100644 --- a/api/internal/crawl/doc/doc.go +++ b/api/internal/crawl/doc/doc.go @@ -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 }