From 66004cec8abdb145ba123a71c9ebd437298c3391 Mon Sep 17 00:00:00 2001 From: Raffael Sahli Date: Thu, 13 Jul 2023 14:16:30 +0000 Subject: [PATCH] fix: mutex protect krusty --- Makefile | 2 +- internal/build/kustomize.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index da83d45..d36061a 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ fmt: .PHONY: test test: - go test -coverprofile coverage.out -v ./... + go test -race -coverprofile coverage.out -v ./... .PHONY: e2e-test e2e-test: build diff --git a/internal/build/kustomize.go b/internal/build/kustomize.go index 9e7d4a3..fe3080f 100644 --- a/internal/build/kustomize.go +++ b/internal/build/kustomize.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sync" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/api/konfig" @@ -17,6 +18,8 @@ import ( "sigs.k8s.io/yaml" ) +var kustomizeBuildMutex sync.Mutex + type KustomizeOpts struct { Path string } @@ -95,6 +98,9 @@ func (k *Kustomize) buildKustomization(path string) (resmap.ResMap, error) { PluginConfig: krusty.MakeDefaultOptions().PluginConfig, } + kustomizeBuildMutex.Lock() + defer kustomizeBuildMutex.Unlock() + kustomizer := krusty.MakeKustomizer(buildOptions) return kustomizer.Run(fs, path) }