From d25b6ff3dcb8c5348abb9785e11b7704ce81ebe2 Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Wed, 4 Dec 2019 11:24:54 -0800 Subject: [PATCH] Remove duplicates in `kinds` --- api/internal/crawl/doc/doc.go | 8 +++++++- api/internal/crawl/doc/doc_test.go | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/internal/crawl/doc/doc.go b/api/internal/crawl/doc/doc.go index 98a75c457..4c3eb1c6f 100644 --- a/api/internal/crawl/doc/doc.go +++ b/api/internal/crawl/doc/doc.go @@ -123,6 +123,8 @@ func (doc *KustomizationDocument) ParseYAML() error { identifierSet := make(set) valueSet := make(set) + kindSet := make(set) + getKind := func(m map[string]interface{}) string { const defaultStr = "Kustomization" kind, ok := m["kind"] @@ -141,10 +143,14 @@ func (doc *KustomizationDocument) ParseYAML() error { } for _, contents := range ks { - doc.Kinds = append(doc.Kinds, getKind(contents)) + kindSet[getKind(contents)] = struct{}{} createFlatStructure(identifierSet, valueSet, contents) } + for val := range kindSet { + doc.Kinds = append(doc.Kinds, val) + } + for val := range valueSet { doc.Values = append(doc.Values, val) } diff --git a/api/internal/crawl/doc/doc_test.go b/api/internal/crawl/doc/doc_test.go index 01705072e..6fef92d97 100644 --- a/api/internal/crawl/doc/doc_test.go +++ b/api/internal/crawl/doc/doc_test.go @@ -136,7 +136,6 @@ metadata: "metadata:name=app2", }, kinds: []string{ - "Deployment", "Deployment", "Service", },