Skip to content

Introduce kustomize build options #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions charts/fleet-crd/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -546,6 +549,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -1053,6 +1059,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -1196,6 +1205,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -2850,6 +2862,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -3217,6 +3232,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -3725,6 +3743,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down Expand Up @@ -3868,6 +3889,9 @@ spec:
kustomize:
nullable: true
properties:
buildOptions:
nullable: true
type: string
dir:
nullable: true
type: string
Expand Down
3 changes: 3 additions & 0 deletions docs/gitrepo-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ kustomize:
# Use a custom folder for kustomize resources. This folder must contain
# a kustomization.yaml file.
dir: ./kustomize
# Specify build options for kustomize build.
# Default: ""
buildOptions: --load-restrictor LoadRestrictionsNone

helm:
# Use a custom location for the Helm chart. This can refer to any go-getter URL.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/cli-utils v0.23.1
sigs.k8s.io/kustomize/api v0.8.8
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2
sigs.k8s.io/kustomize/kyaml v0.10.17
sigs.k8s.io/yaml v1.2.0
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@ sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5
sigs.k8s.io/kustomize/api v0.8.8 h1:G2z6JPSSjtWWgMeWSoHdXqyftJNmMmyxXpwENGoOtGE=
sigs.k8s.io/kustomize/api v0.8.8/go.mod h1:He1zoK0nk43Pc6NlV085xDXDXTNprtcyKZVm3swsdNY=
sigs.k8s.io/kustomize/cmd/config v0.9.10/go.mod h1:Mrby0WnRH7hA6OwOYnYpfpiY0WJIMgYrEDfwOeFdMK0=
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2 h1:iP3ckqMIftwsIKnMqtztReSkkPJvhqNc5QiOpMoFpbY=
sigs.k8s.io/kustomize/kustomize/v4 v4.1.2/go.mod h1:PxBvo4WGYlCLeRPL+ziT64wBXqbgfcalOS/SXa/tcyo=
sigs.k8s.io/kustomize/kyaml v0.4.0/go.mod h1:XJL84E6sOFeNrQ7CADiemc1B0EjIxHo3OhW4o1aJYNw=
sigs.k8s.io/kustomize/kyaml v0.10.7/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/fleet.cattle.io/v1alpha1/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ type YAMLOptions struct {
}

type KustomizeOptions struct {
Dir string `json:"dir,omitempty"`
Dir string `json:"dir,omitempty"`
BuildOptions string `json:"buildOptions,omitempty"`
}

type HelmOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/helmdeployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (p *postRender) Run(renderedManifests *bytes.Buffer) (modifiedManifests *by
data = nil
}

newObjs, processed, err := kustomize.Process(p.manifest, data, p.opts.Kustomize.Dir)
newObjs, processed, err := kustomize.Process(p.manifest, data, *p.opts.Kustomize)
if err != nil {
return nil, err
}
Expand Down
29 changes: 19 additions & 10 deletions pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package kustomize

import (
"bytes"
"path/filepath"
"strings"

fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"

"github.com/rancher/fleet/pkg/content"
"github.com/rancher/fleet/pkg/manifest"
Expand All @@ -11,7 +15,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kustomize/v4/commands/build"
"sigs.k8s.io/yaml"
)

Expand All @@ -20,7 +24,8 @@ const (
ManifestsYAML = "fleet-manifests.yaml"
)

func Process(m *manifest.Manifest, content []byte, dir string) ([]runtime.Object, bool, error) {
func Process(m *manifest.Manifest, content []byte, options fleet.KustomizeOptions) ([]runtime.Object, bool, error) {
dir := options.Dir
if dir == "" {
dir = "."
}
Expand All @@ -41,7 +46,7 @@ func Process(m *manifest.Manifest, content []byte, dir string) ([]runtime.Object
}
}

objs, err := kustomize(fs, dir)
objs, err := kustomize(fs, dir, options.BuildOptions)
return objs, true, err
}

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

func kustomize(fs filesys.FileSystem, dir string) (result []runtime.Object, err error) {
pcfg := types.DisabledPluginConfig()
kust := krusty.MakeKustomizer(&krusty.Options{
LoadRestrictions: types.LoadRestrictionsRootOnly,
PluginConfig: pcfg,
})
resMap, err := kust.Run(fs, dir)
func kustomize(fs filesys.FileSystem, dir string, buildOptions string) (result []runtime.Object, err error) {
buildOpts := strings.Split(buildOptions, " ")
cmd := build.NewCmdBuild(fs, build.MakeHelp("kustomize", "build"), new(bytes.Buffer))
cmd.Flags().Parse(buildOpts)
if err := build.Validate([]string{dir}); err != nil {
return nil, err
}
k := krusty.MakeKustomizer(
build.HonorKustomizeFlags(krusty.MakeDefaultOptions()),
)
resMap, err := k.Run(fs, dir)
if err != nil {
return nil, err
}
Expand Down
Loading