Skip to content

Commit 8d30b85

Browse files
committed
Introduce kustomize build options
1 parent 2a4da5f commit 8d30b85

File tree

9 files changed

+299
-12
lines changed

9 files changed

+299
-12
lines changed

charts/fleet-crd/templates/crds.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ spec:
179179
kustomize:
180180
nullable: true
181181
properties:
182+
buildOptions:
183+
nullable: true
184+
type: string
182185
dir:
183186
nullable: true
184187
type: string
@@ -546,6 +549,9 @@ spec:
546549
kustomize:
547550
nullable: true
548551
properties:
552+
buildOptions:
553+
nullable: true
554+
type: string
549555
dir:
550556
nullable: true
551557
type: string
@@ -1053,6 +1059,9 @@ spec:
10531059
kustomize:
10541060
nullable: true
10551061
properties:
1062+
buildOptions:
1063+
nullable: true
1064+
type: string
10561065
dir:
10571066
nullable: true
10581067
type: string
@@ -1196,6 +1205,9 @@ spec:
11961205
kustomize:
11971206
nullable: true
11981207
properties:
1208+
buildOptions:
1209+
nullable: true
1210+
type: string
11991211
dir:
12001212
nullable: true
12011213
type: string
@@ -2850,6 +2862,9 @@ spec:
28502862
kustomize:
28512863
nullable: true
28522864
properties:
2865+
buildOptions:
2866+
nullable: true
2867+
type: string
28532868
dir:
28542869
nullable: true
28552870
type: string
@@ -3217,6 +3232,9 @@ spec:
32173232
kustomize:
32183233
nullable: true
32193234
properties:
3235+
buildOptions:
3236+
nullable: true
3237+
type: string
32203238
dir:
32213239
nullable: true
32223240
type: string
@@ -3725,6 +3743,9 @@ spec:
37253743
kustomize:
37263744
nullable: true
37273745
properties:
3746+
buildOptions:
3747+
nullable: true
3748+
type: string
37283749
dir:
37293750
nullable: true
37303751
type: string
@@ -3868,6 +3889,9 @@ spec:
38683889
kustomize:
38693890
nullable: true
38703891
properties:
3892+
buildOptions:
3893+
nullable: true
3894+
type: string
38713895
dir:
38723896
nullable: true
38733897
type: string

docs/gitrepo-structure.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ kustomize:
5757
# Use a custom folder for kustomize resources. This folder must contain
5858
# a kustomization.yaml file.
5959
dir: ./kustomize
60+
# Specify build options for kustomize build.
61+
# Default: ""
62+
buildOptions: --load-restrictor LoadRestrictionsNone
6063

6164
helm:
6265
# Use a custom location for the Helm chart. This can refer to any go-getter URL.

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ require (
6363
rsc.io/letsencrypt v0.0.3 // indirect
6464
sigs.k8s.io/cli-utils v0.23.1
6565
sigs.k8s.io/kustomize/api v0.8.8
66+
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2
6667
sigs.k8s.io/kustomize/kyaml v0.10.17
6768
sigs.k8s.io/yaml v1.2.0
6869
)

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,7 @@ sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5
20632063
sigs.k8s.io/kustomize/api v0.8.8 h1:G2z6JPSSjtWWgMeWSoHdXqyftJNmMmyxXpwENGoOtGE=
20642064
sigs.k8s.io/kustomize/api v0.8.8/go.mod h1:He1zoK0nk43Pc6NlV085xDXDXTNprtcyKZVm3swsdNY=
20652065
sigs.k8s.io/kustomize/cmd/config v0.9.10/go.mod h1:Mrby0WnRH7hA6OwOYnYpfpiY0WJIMgYrEDfwOeFdMK0=
2066+
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2 h1:iP3ckqMIftwsIKnMqtztReSkkPJvhqNc5QiOpMoFpbY=
20662067
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2/go.mod h1:PxBvo4WGYlCLeRPL+ziT64wBXqbgfcalOS/SXa/tcyo=
20672068
sigs.k8s.io/kustomize/kyaml v0.4.0/go.mod h1:XJL84E6sOFeNrQ7CADiemc1B0EjIxHo3OhW4o1aJYNw=
20682069
sigs.k8s.io/kustomize/kyaml v0.10.7/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=

pkg/apis/fleet.cattle.io/v1alpha1/bundle.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ type YAMLOptions struct {
218218
}
219219

220220
type KustomizeOptions struct {
221-
Dir string `json:"dir,omitempty"`
221+
Dir string `json:"dir,omitempty"`
222+
BuildOptions string `json:"buildOptions,omitempty"`
222223
}
223224

224225
type HelmOptions struct {

pkg/helmdeployer/deployer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (p *postRender) Run(renderedManifests *bytes.Buffer) (modifiedManifests *by
9999
data = nil
100100
}
101101

102-
newObjs, processed, err := kustomize.Process(p.manifest, data, p.opts.Kustomize.Dir)
102+
newObjs, processed, err := kustomize.Process(p.manifest, data, *p.opts.Kustomize)
103103
if err != nil {
104104
return nil, err
105105
}

pkg/kustomize/kustomize.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package kustomize
22

33
import (
4+
"bytes"
45
"path/filepath"
6+
"strings"
7+
8+
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
59

610
"github.com/rancher/fleet/pkg/content"
711
"github.com/rancher/fleet/pkg/manifest"
@@ -11,7 +15,7 @@ import (
1115
"k8s.io/apimachinery/pkg/runtime"
1216
"sigs.k8s.io/kustomize/api/filesys"
1317
"sigs.k8s.io/kustomize/api/krusty"
14-
"sigs.k8s.io/kustomize/api/types"
18+
"sigs.k8s.io/kustomize/kustomize/v4/commands/build"
1519
"sigs.k8s.io/yaml"
1620
)
1721

@@ -20,7 +24,8 @@ const (
2024
ManifestsYAML = "fleet-manifests.yaml"
2125
)
2226

23-
func Process(m *manifest.Manifest, content []byte, dir string) ([]runtime.Object, bool, error) {
27+
func Process(m *manifest.Manifest, content []byte, options fleet.KustomizeOptions) ([]runtime.Object, bool, error) {
28+
dir := options.Dir
2429
if dir == "" {
2530
dir = "."
2631
}
@@ -41,7 +46,7 @@ func Process(m *manifest.Manifest, content []byte, dir string) ([]runtime.Object
4146
}
4247
}
4348

44-
objs, err := kustomize(fs, dir)
49+
objs, err := kustomize(fs, dir, options.BuildOptions)
4550
return objs, true, err
4651
}
4752

@@ -90,13 +95,17 @@ func toFilesystem(m *manifest.Manifest, dir string, manifestsContent []byte) (fi
9095
return f, err
9196
}
9297

93-
func kustomize(fs filesys.FileSystem, dir string) (result []runtime.Object, err error) {
94-
pcfg := types.DisabledPluginConfig()
95-
kust := krusty.MakeKustomizer(&krusty.Options{
96-
LoadRestrictions: types.LoadRestrictionsRootOnly,
97-
PluginConfig: pcfg,
98-
})
99-
resMap, err := kust.Run(fs, dir)
98+
func kustomize(fs filesys.FileSystem, dir string, buildOptions string) (result []runtime.Object, err error) {
99+
buildOpts := strings.Split(buildOptions, " ")
100+
cmd := build.NewCmdBuild(fs, build.MakeHelp("kustomize", "build"), new(bytes.Buffer))
101+
cmd.Flags().Parse(buildOpts)
102+
if err := build.Validate([]string{dir}); err != nil {
103+
return nil, err
104+
}
105+
k := krusty.MakeKustomizer(
106+
build.HonorKustomizeFlags(krusty.MakeDefaultOptions()),
107+
)
108+
resMap, err := k.Run(fs, dir)
100109
if err != nil {
101110
return nil, err
102111
}

0 commit comments

Comments
 (0)