Skip to content

Commit f739e0e

Browse files
authored
Merge pull request #1258 from fluxcd/fix-flux2-5972
kustomize: support merging the input OpenAPI schemas with the built-in ones
2 parents 61592ec + add36fa commit f739e0e

5 files changed

Lines changed: 483 additions & 22 deletions

File tree

kustomize/go.mod

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ 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
1516
github.com/onsi/gomega v1.40.0
1617
github.com/otiai10/copy v1.14.1
18+
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af
1719
k8s.io/api v0.36.2
1820
k8s.io/apiextensions-apiserver v0.36.2
1921
k8s.io/apimachinery v0.36.2
2022
k8s.io/client-go v0.36.2
23+
k8s.io/kube-openapi v0.0.0-20260603220949-865597e52e25
2124
sigs.k8s.io/controller-runtime v0.24.1
2225
sigs.k8s.io/kustomize/api v0.21.1
2326
sigs.k8s.io/kustomize/kyaml v0.21.1
@@ -46,13 +49,21 @@ require (
4649
github.com/go-logr/logr v1.4.3 // indirect
4750
github.com/go-openapi/jsonpointer v0.21.0 // indirect
4851
github.com/go-openapi/jsonreference v0.21.0 // indirect
49-
github.com/go-openapi/swag v0.23.0 // indirect
50-
github.com/google/gnostic-models v0.7.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
5164
github.com/google/go-cmp v0.7.0 // indirect
5265
github.com/google/uuid v1.6.0 // indirect
53-
github.com/josharian/intern v1.0.0 // indirect
5466
github.com/json-iterator/go v1.1.12 // indirect
55-
github.com/mailru/easyjson v0.9.0 // indirect
5667
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5768
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
5869
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
@@ -63,7 +74,7 @@ require (
6374
github.com/prometheus/client_model v0.6.2 // indirect
6475
github.com/prometheus/common v0.67.5 // indirect
6576
github.com/prometheus/procfs v0.19.2 // indirect
66-
github.com/spf13/pflag v1.0.9 // indirect
77+
github.com/spf13/pflag v1.0.10 // indirect
6778
github.com/x448/float16 v0.8.4 // indirect
6879
github.com/xlab/treeprint v1.2.0 // indirect
6980
go.yaml.in/yaml/v2 v2.4.3 // indirect
@@ -75,12 +86,9 @@ require (
7586
golang.org/x/term v0.42.0 // indirect
7687
golang.org/x/text v0.36.0 // indirect
7788
golang.org/x/time v0.14.0 // indirect
78-
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect
7989
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
8090
gopkg.in/inf.v0 v0.9.1 // indirect
81-
gopkg.in/yaml.v3 v3.0.1 // indirect
8291
k8s.io/klog/v2 v2.140.0 // indirect
83-
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect
8492
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 // indirect
8593
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
8694
sigs.k8s.io/randfill v1.0.0 // indirect

kustomize/go.sum

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,36 @@ 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.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
32-
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
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=
3361
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
3462
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
3563
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
@@ -41,16 +69,12 @@ github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J
4169
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
4270
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4371
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=
4672
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
4773
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
4874
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
4975
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
5076
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
5177
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=
5478
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
5579
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
5680
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -84,8 +108,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t
84108
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
85109
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
86110
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
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=
111+
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
112+
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
89113
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
90114
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
91115
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
@@ -148,8 +172,8 @@ k8s.io/client-go v0.36.2 h1:bfgxmFKc9CgqsgX4xKLAAdmTQlWee7Ob/HlDOrJ5TBI=
148172
k8s.io/client-go v0.36.2/go.mod h1:1vgO4OAlfPnoLcb+Rze2GF5rAr14w8qjrYMoyXJzQj0=
149173
k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc=
150174
k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0=
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=
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=
153177
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0xi3g0ZcxxJ7vbWU=
154178
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk=
155179
sigs.k8s.io/controller-runtime v0.24.1 h1:miPEwrmirImAvgME1L9qebGHrOnGJoVmVdtOU9fRfo4=

kustomize/kustomize_generator.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ 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+
87108
// NewGenerator creates a new kustomize generator
88109
// It takes a root directory and a kustomization object
89110
// If the root is empty, no enforcement of the root directory will be done when handling paths.
@@ -630,12 +651,12 @@ func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) {
630651
// buildMutex protects against kustomize concurrent map read/write panic
631652
var kustomizeBuildMutex sync.Mutex
632653

633-
// Secure Build wraps krusty.MakeKustomizer with the following settings:
654+
// SecureBuild wraps krusty.MakeKustomizer with the following settings:
634655
// - secure on-disk FS denying operations outside root
635656
// - load files from outside the kustomization dir path
636657
// (but not outside root)
637658
// - disable plugins except for the builtin ones
638-
func SecureBuild(root, dirPath string, allowRemoteBases bool) (res resmap.ResMap, err error) {
659+
func SecureBuild(root, dirPath string, allowRemoteBases bool, opts ...BuildOption) (res resmap.ResMap, err error) {
639660
var fs filesys.FileSystem
640661

641662
// Create secure FS for root with or without remote base support
@@ -650,13 +671,13 @@ func SecureBuild(root, dirPath string, allowRemoteBases bool) (res resmap.ResMap
650671
return nil, err
651672
}
652673
}
653-
return Build(fs, dirPath)
674+
return Build(fs, dirPath, opts...)
654675
}
655676

656677
// Build wraps krusty.MakeKustomizer with the following settings:
657678
// - load files from outside the kustomization.yaml root
658679
// - disable plugins except for the builtin ones
659-
func Build(fs filesys.FileSystem, dirPath string) (res resmap.ResMap, err error) {
680+
func Build(fs filesys.FileSystem, dirPath string, opts ...BuildOption) (res resmap.ResMap, err error) {
660681
// temporary workaround for concurrent map read and map write bug
661682
// https://github.com/kubernetes-sigs/kustomize/issues/3659
662683
kustomizeBuildMutex.Lock()
@@ -676,12 +697,23 @@ func Build(fs filesys.FileSystem, dirPath string) (res resmap.ResMap, err error)
676697
PluginConfig: kustypes.DisabledPluginConfig(),
677698
}
678699

700+
buildOpts := defaultBuildOptions()
701+
for _, opt := range opts {
702+
opt(&buildOpts)
703+
}
704+
679705
// Reset the global OpenAPI schema to ensure each build is isolated.
680706
// This prevents a custom openapi configuration in one Kustomization
681707
// from affecting subsequent builds (e.g., causing strategic-merge
682708
// patches to fail for types omitted from the custom schema).
683709
openapi.ResetOpenAPI()
684710

711+
if buildOpts.mergeOpenAPIPathWithBuiltins {
712+
if err := mergeOpenAPIPathWithBuiltins(fs, dirPath); err != nil {
713+
return nil, err
714+
}
715+
}
716+
685717
k := krusty.MakeKustomizer(buildOptions)
686718
return k.Run(fs, dirPath)
687719
}

0 commit comments

Comments
 (0)