From 87f1a0531e5c704c12b849ec79a4f14419a0dd9f Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sat, 30 May 2020 20:17:04 +0200 Subject: [PATCH] run across multiple workers --- Readme.md | 8 +++++++ main.go | 66 +++++++++++++++++++++++++++++++++---------------------- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/Readme.md b/Readme.md index 21b5537..fa337f0 100644 --- a/Readme.md +++ b/Readme.md @@ -2,6 +2,10 @@ A Kubernetes manifests validation tool, inspired by & similar to [Kubeval](https://github.com/instrumenta/kubeval) +Notable features: + * high performance: will validate & download manifests over multiple routines + * support for Kubernetes CRDs + ``` $ ./bin/kubeconform -h Usage of ./bin/kubeconform: @@ -13,8 +17,12 @@ Usage of ./bin/kubeconform: version of Kubernetes to test against (default "1.18.0") -output string output format - text, json (default "text") + -printsummary + print a summary at the end -schema value file containing an additional Schema (can be specified multiple times) -skipKinds string comma-separated list of kinds to ignore + -workers int + number of routines to run in parallel (default 4) ``` diff --git a/main.go b/main.go index 0275235..282cffd 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "log" "os" "strings" + "sync" "github.com/yannh/kubeconform/pkg/cache" "github.com/yannh/kubeconform/pkg/fsutils" @@ -75,10 +76,13 @@ func realMain() int { var files, dirs, schemas arrayFiles var skipKinds, k8sVersion, outputFormat string var printSummary bool + var nWorkers int + flag.BoolVar(&printSummary, "printsummary", false, "print a summary at the end") flag.Var(&files, "file", "file to validate (can be specified multiple times)") flag.Var(&dirs, "dir", "directory to validate (can be specified multiple times)") - flag.Var(&schemas, "schema", "file containing an additional Schema") + flag.Var(&schemas, "schema", "file containing an additional Schema (can be specified multiple times)") + flag.IntVar(&nWorkers, "workers", 4, "number of routines to run in parallel") flag.StringVar(&k8sVersion, "k8sversion", "1.18.0", "version of Kubernetes to test against") flag.StringVar(&skipKinds, "skipKinds", "", "comma-separated list of kinds to ignore") flag.StringVar(&outputFormat, "output", "text", "output format - text, json") @@ -104,6 +108,16 @@ func realMain() int { return false } + registries := []registry.Registry{} + registries = append(registries, registry.NewKubernetesRegistry(false)) + if len(schemas) > 0 { + localRegistry, err := registry.NewLocalSchemas(schemas) + if err != nil { + log.Fatalf("%s", err) + } + registries = append(registries, localRegistry) + } + fileBatches := make(chan []string) go func() { @@ -120,33 +134,33 @@ func realMain() int { close(fileBatches) }() - registries := []registry.Registry{} - registries = append(registries, registry.NewKubernetesRegistry(false)) - if len(schemas) > 0 { - localRegistry, err := registry.NewLocalSchemas(schemas) - if err != nil { - log.Fatalf("%s", err) - } - registries = append(registries, localRegistry) + var wg sync.WaitGroup + for i:=0; i