Skip to content

Commit

Permalink
Workaround for kustomize build panic
Browse files Browse the repository at this point in the history
Serialize kustomize build runs to avoid kyaml OpenAPI concurrent map read/write panic
kubernetes-sigs/kustomize#3659

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed May 11, 2021
1 parent fff3310 commit f01e64b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/kustomization_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kustomize/api/filesys"
Expand Down Expand Up @@ -333,11 +334,19 @@ func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) {
return
}

// TODO: remove mutex when kustomize fixes the concurrent map read/write panic
var kustomizeBuildMutex sync.Mutex

// buildKustomization wraps krusty.MakeKustomizer with the following settings:
// - reorder the resources just before output (Namespaces and Cluster roles/role bindings first, CRDs before CRs, Webhooks last)
// - load files from outside the kustomization.yaml root
// - disable plugins except for the builtin ones
func buildKustomization(fs filesys.FileSystem, dirPath string) (resmap.ResMap, error) {
// temporary workaround for concurrent map read and map write bug
// https://github.com/kubernetes-sigs/kustomize/issues/3659
kustomizeBuildMutex.Lock()
defer kustomizeBuildMutex.Unlock()

buildOptions := &krusty.Options{
DoLegacyResourceSort: true,
LoadRestrictions: kustypes.LoadRestrictionsNone,
Expand Down

0 comments on commit f01e64b

Please sign in to comment.