Skip to content

Commit e2882a1

Browse files
authored
Merge pull request #1260 from fluxcd/fix-flux2-5981
kustomize: load builtin schemas after reset
2 parents f739e0e + 4ccc4a6 commit e2882a1

5 files changed

Lines changed: 94 additions & 405 deletions

File tree

kustomize/go.mod

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ require (
1212
github.com/fluxcd/pkg/apis/kustomize v1.20.0
1313
github.com/fluxcd/pkg/envsubst v1.7.0
1414
github.com/fluxcd/pkg/sourceignore v0.18.0
15-
github.com/google/gnostic-models v0.7.0
1615
github.com/onsi/gomega v1.40.0
1716
github.com/otiai10/copy v1.14.1
18-
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af
1917
k8s.io/api v0.36.2
2018
k8s.io/apiextensions-apiserver v0.36.2
2119
k8s.io/apimachinery v0.36.2
2220
k8s.io/client-go v0.36.2
23-
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25
2421
sigs.k8s.io/controller-runtime v0.24.1
2522
sigs.k8s.io/kustomize/api v0.21.1
2623
sigs.k8s.io/kustomize/kyaml v0.21.1
@@ -49,21 +46,13 @@ require (
4946
github.com/go-logr/logr v1.4.3 // indirect
5047
github.com/go-openapi/jsonpointer v0.21.0 // indirect
5148
github.com/go-openapi/jsonreference v0.21.0 // indirect
52-
github.com/go-openapi/swag v0.25.4 // indirect
53-
github.com/go-openapi/swag/cmdutils v0.25.4 // indirect
54-
github.com/go-openapi/swag/conv v0.25.4 // indirect
55-
github.com/go-openapi/swag/fileutils v0.25.4 // indirect
56-
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
57-
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
58-
github.com/go-openapi/swag/loading v0.25.4 // indirect
59-
github.com/go-openapi/swag/mangling v0.25.4 // indirect
60-
github.com/go-openapi/swag/netutils v0.25.4 // indirect
61-
github.com/go-openapi/swag/stringutils v0.25.4 // indirect
62-
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
63-
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
49+
github.com/go-openapi/swag v0.23.0 // indirect
50+
github.com/google/gnostic-models v0.7.0 // indirect
6451
github.com/google/go-cmp v0.7.0 // indirect
6552
github.com/google/uuid v1.6.0 // indirect
53+
github.com/josharian/intern v1.0.0 // indirect
6654
github.com/json-iterator/go v1.1.12 // indirect
55+
github.com/mailru/easyjson v0.9.0 // indirect
6756
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6857
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
6958
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
@@ -74,7 +63,7 @@ require (
7463
github.com/prometheus/client_model v0.6.2 // indirect
7564
github.com/prometheus/common v0.67.5 // indirect
7665
github.com/prometheus/procfs v0.19.2 // indirect
77-
github.com/spf13/pflag v1.0.10 // indirect
66+
github.com/spf13/pflag v1.0.9 // indirect
7867
github.com/x448/float16 v0.8.4 // indirect
7968
github.com/xlab/treeprint v1.2.0 // indirect
8069
go.yaml.in/yaml/v2 v2.4.3 // indirect
@@ -86,9 +75,12 @@ require (
8675
golang.org/x/term v0.42.0 // indirect
8776
golang.org/x/text v0.36.0 // indirect
8877
golang.org/x/time v0.14.0 // indirect
78+
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect
8979
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
9080
gopkg.in/inf.v0 v0.9.1 // indirect
81+
gopkg.in/yaml.v3 v3.0.1 // indirect
9182
k8s.io/klog/v2 v2.140.0 // indirect
83+
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect
9284
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 // indirect
9385
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
9486
sigs.k8s.io/randfill v1.0.0 // indirect

kustomize/go.sum

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,8 @@ github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1
2828
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
2929
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
3030
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
31-
github.com/go-openapi/swag v0.25.4 h1:OyUPUFYDPDBMkqyxOTkqDYFnrhuhi9NR6QVUvIochMU=
32-
github.com/go-openapi/swag v0.25.4/go.mod h1:zNfJ9WZABGHCFg2RnY0S4IOkAcVTzJ6z2Bi+Q4i6qFQ=
33-
github.com/go-openapi/swag/cmdutils v0.25.4 h1:8rYhB5n6WawR192/BfUu2iVlxqVR9aRgGJP6WaBoW+4=
34-
github.com/go-openapi/swag/cmdutils v0.25.4/go.mod h1:pdae/AFo6WxLl5L0rq87eRzVPm/XRHM3MoYgRMvG4A0=
35-
github.com/go-openapi/swag/conv v0.25.4 h1:/Dd7p0LZXczgUcC/Ikm1+YqVzkEeCc9LnOWjfkpkfe4=
36-
github.com/go-openapi/swag/conv v0.25.4/go.mod h1:3LXfie/lwoAv0NHoEuY1hjoFAYkvlqI/Bn5EQDD3PPU=
37-
github.com/go-openapi/swag/fileutils v0.25.4 h1:2oI0XNW5y6UWZTC7vAxC8hmsK/tOkWXHJQH4lKjqw+Y=
38-
github.com/go-openapi/swag/fileutils v0.25.4/go.mod h1:cdOT/PKbwcysVQ9Tpr0q20lQKH7MGhOEb6EwmHOirUk=
39-
github.com/go-openapi/swag/jsonname v0.25.4 h1:bZH0+MsS03MbnwBXYhuTttMOqk+5KcQ9869Vye1bNHI=
40-
github.com/go-openapi/swag/jsonname v0.25.4/go.mod h1:GPVEk9CWVhNvWhZgrnvRA6utbAltopbKwDu8mXNUMag=
41-
github.com/go-openapi/swag/jsonutils v0.25.4 h1:VSchfbGhD4UTf4vCdR2F4TLBdLwHyUDTd1/q4i+jGZA=
42-
github.com/go-openapi/swag/jsonutils v0.25.4/go.mod h1:7OYGXpvVFPn4PpaSdPHJBtF0iGnbEaTk8AvBkoWnaAY=
43-
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4 h1:IACsSvBhiNJwlDix7wq39SS2Fh7lUOCJRmx/4SN4sVo=
44-
github.com/go-openapi/swag/jsonutils/fixtures_test v0.25.4/go.mod h1:Mt0Ost9l3cUzVv4OEZG+WSeoHwjWLnarzMePNDAOBiM=
45-
github.com/go-openapi/swag/loading v0.25.4 h1:jN4MvLj0X6yhCDduRsxDDw1aHe+ZWoLjW+9ZQWIKn2s=
46-
github.com/go-openapi/swag/loading v0.25.4/go.mod h1:rpUM1ZiyEP9+mNLIQUdMiD7dCETXvkkC30z53i+ftTE=
47-
github.com/go-openapi/swag/mangling v0.25.4 h1:2b9kBJk9JvPgxr36V23FxJLdwBrpijI26Bx5JH4Hp48=
48-
github.com/go-openapi/swag/mangling v0.25.4/go.mod h1:6dxwu6QyORHpIIApsdZgb6wBk/DPU15MdyYj/ikn0Hg=
49-
github.com/go-openapi/swag/netutils v0.25.4 h1:Gqe6K71bGRb3ZQLusdI8p/y1KLgV4M/k+/HzVSqT8H0=
50-
github.com/go-openapi/swag/netutils v0.25.4/go.mod h1:m2W8dtdaoX7oj9rEttLyTeEFFEBvnAx9qHd5nJEBzYg=
51-
github.com/go-openapi/swag/stringutils v0.25.4 h1:O6dU1Rd8bej4HPA3/CLPciNBBDwZj9HiEpdVsb8B5A8=
52-
github.com/go-openapi/swag/stringutils v0.25.4/go.mod h1:GTsRvhJW5xM5gkgiFe0fV3PUlFm0dr8vki6/VSRaZK0=
53-
github.com/go-openapi/swag/typeutils v0.25.4 h1:1/fbZOUN472NTc39zpa+YGHn3jzHWhv42wAJSN91wRw=
54-
github.com/go-openapi/swag/typeutils v0.25.4/go.mod h1:Ou7g//Wx8tTLS9vG0UmzfCsjZjKhpjxayRKTHXf2pTE=
55-
github.com/go-openapi/swag/yamlutils v0.25.4 h1:6jdaeSItEUb7ioS9lFoCZ65Cne1/RZtPBZ9A56h92Sw=
56-
github.com/go-openapi/swag/yamlutils v0.25.4/go.mod h1:MNzq1ulQu+yd8Kl7wPOut/YHAAU/H6hL91fF+E2RFwc=
57-
github.com/go-openapi/testify/enable/yaml/v2 v2.0.2 h1:0+Y41Pz1NkbTHz8NngxTuAXxEodtNSI1WG1c/m5Akw4=
58-
github.com/go-openapi/testify/enable/yaml/v2 v2.0.2/go.mod h1:kme83333GCtJQHXQ8UKX3IBZu6z8T5Dvy5+CW3NLUUg=
59-
github.com/go-openapi/testify/v2 v2.0.2 h1:X999g3jeLcoY8qctY/c/Z8iBHTbwLz7R2WXd6Ub6wls=
60-
github.com/go-openapi/testify/v2 v2.0.2/go.mod h1:HCPmvFFnheKK2BuwSA0TbbdxJ3I16pjwMkYkP4Ywn54=
31+
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
32+
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
6133
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
6234
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
6335
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
@@ -69,12 +41,16 @@ github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J
6941
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
7042
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
7143
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
44+
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
45+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
7246
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
7347
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
7448
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7549
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
7650
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
7751
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
52+
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
53+
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
7854
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
7955
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
8056
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -108,8 +84,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
10884
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
10985
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
11086
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
111-
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
112-
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
87+
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
88+
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
11389
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
11490
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
11591
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
@@ -172,8 +148,8 @@ k8s.io/client-go v0.36.2 h1:bfgxmFKc9CgqsgX4xKLAAdmTQlWee7Ob/HlDOrJ5TBI=
172148
k8s.io/client-go v0.36.2/go.mod h1:1vgO4OAlfPnoLcb+Rze2GF5rAr14w8qjrYMoyXJzQj0=
173149
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
174150
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
175-
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25 h1:mPMaPMpBij2V1Wv/fR+HW124vVGXXvOSS9ver/9yjWs=
176-
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25/go.mod h1:V/QaCUYDa+0QpcHhVVc5l99Uz56wEMEXBSj9oCDkNDY=
151+
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a h1:xCeOEAOoGYl2jnJoHkC3hkbPJgdATINPMAxaynU2Ovg=
152+
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a/go.mod h1:uGBT7iTA6c6MvqUvSXIaYZo9ukscABYi2btjhvgKGZ0=
177153
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0xi3g0ZcxxJ7vbWU=
178154
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
179155
sigs.k8s.io/controller-runtime v0.24.1 h1:miPEwrmirImAvgME1L9qebGHrOnGJoVmVdtOU9fRfo4=

kustomize/kustomize_generator.go

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,6 @@ type Generator struct {
8484
// SavingOptions is a function that can be used to apply saving options to a kustomization
8585
type SavingOptions func(dirPath, file string, action Action) error
8686

87-
// BuildOption configures Kustomize builds.
88-
type BuildOption func(*buildOptions)
89-
90-
type buildOptions struct {
91-
mergeOpenAPIPathWithBuiltins bool
92-
}
93-
94-
func defaultBuildOptions() buildOptions {
95-
return buildOptions{
96-
mergeOpenAPIPathWithBuiltins: true,
97-
}
98-
}
99-
100-
// WithMergeOpenAPIPathWithBuiltins controls whether openapi.path schemas are
101-
// merged with Kustomize's embedded Kubernetes schema before builds.
102-
func WithMergeOpenAPIPathWithBuiltins(enabled bool) BuildOption {
103-
return func(o *buildOptions) {
104-
o.mergeOpenAPIPathWithBuiltins = enabled
105-
}
106-
}
107-
10887
// NewGenerator creates a new kustomize generator
10988
// It takes a root directory and a kustomization object
11089
// If the root is empty, no enforcement of the root directory will be done when handling paths.
@@ -651,12 +630,17 @@ func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) {
651630
// buildMutex protects against kustomize concurrent map read/write panic
652631
var kustomizeBuildMutex sync.Mutex
653632

654-
// SecureBuild wraps krusty.MakeKustomizer with the following settings:
633+
func resetOpenAPIWithBuiltins() {
634+
openapi.ResetOpenAPI()
635+
_ = openapi.Schema()
636+
}
637+
638+
// Secure Build wraps krusty.MakeKustomizer with the following settings:
655639
// - secure on-disk FS denying operations outside root
656640
// - load files from outside the kustomization dir path
657641
// (but not outside root)
658642
// - disable plugins except for the builtin ones
659-
func SecureBuild(root, dirPath string, allowRemoteBases bool, opts ...BuildOption) (res resmap.ResMap, err error) {
643+
func SecureBuild(root, dirPath string, allowRemoteBases bool) (res resmap.ResMap, err error) {
660644
var fs filesys.FileSystem
661645

662646
// Create secure FS for root with or without remote base support
@@ -671,13 +655,13 @@ func SecureBuild(root, dirPath string, allowRemoteBases bool, opts ...BuildOptio
671655
return nil, err
672656
}
673657
}
674-
return Build(fs, dirPath, opts...)
658+
return Build(fs, dirPath)
675659
}
676660

677661
// Build wraps krusty.MakeKustomizer with the following settings:
678662
// - load files from outside the kustomization.yaml root
679663
// - disable plugins except for the builtin ones
680-
func Build(fs filesys.FileSystem, dirPath string, opts ...BuildOption) (res resmap.ResMap, err error) {
664+
func Build(fs filesys.FileSystem, dirPath string) (res resmap.ResMap, err error) {
681665
// temporary workaround for concurrent map read and map write bug
682666
// https://github.com/kubernetes-sigs/kustomize/issues/3659
683667
kustomizeBuildMutex.Lock()
@@ -697,22 +681,12 @@ func Build(fs filesys.FileSystem, dirPath string, opts ...BuildOption) (res resm
697681
PluginConfig: kustypes.DisabledPluginConfig(),
698682
}
699683

700-
buildOpts := defaultBuildOptions()
701-
for _, opt := range opts {
702-
opt(&buildOpts)
703-
}
704-
705684
// Reset the global OpenAPI schema to ensure each build is isolated.
706-
// This prevents a custom openapi configuration in one Kustomization
707-
// from affecting subsequent builds (e.g., causing strategic-merge
708-
// patches to fail for types omitted from the custom schema).
709-
openapi.ResetOpenAPI()
710-
711-
if buildOpts.mergeOpenAPIPathWithBuiltins {
712-
if err := mergeOpenAPIPathWithBuiltins(fs, dirPath); err != nil {
713-
return nil, err
714-
}
715-
}
685+
// Preload the embedded Kubernetes schema so openapi.path schemas add to
686+
// built-ins within the same build, matching the historical non-empty global
687+
// schema behavior without leaking schemas across builds.
688+
resetOpenAPIWithBuiltins()
689+
defer openapi.ResetOpenAPI()
716690

717691
k := krusty.MakeKustomizer(buildOptions)
718692
return k.Run(fs, dirPath)

0 commit comments

Comments
 (0)