Skip to content

Commit 25415c5

Browse files
committed
Remove -t flag in build and add configurations field in kustomization.yaml
1 parent 38b7f42 commit 25415c5

File tree

9 files changed

+30
-227
lines changed

9 files changed

+30
-227
lines changed

examples/transformerconfigs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ nameReference:
8989

9090
## cusotmizing transformer configurations
9191

92-
Kustomize has a default set of configurations. They can be saved to local directory through `kustomize config save -d`. Kustomize allows modifying those configuration files and using them in `kustomize build` through `-t`. This tutorial shows how to customize those configurations to
93-
- [support a crd type](crd/README.md)
92+
Kustomize has a default set of configurations. They can be saved to local directory through `kustomize config save -d`. Kustomize allows modifying those configuration files and using them in kustomization.yaml file. This tutorial shows how to customize those configurations to
93+
- support a crd type
9494
- disabling adding commonLabels to fields in some kind of resources
9595
- add extra fields for variable substitution
9696
- add extra fields for name reference

examples/transformerconfigs/crd/README.md

Lines changed: 0 additions & 171 deletions
This file was deleted.

pkg/commands/build/build.go

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package build
1818

1919
import (
2020
"io"
21-
"strings"
2221

2322
"github.com/pkg/errors"
2423
"github.com/spf13/cobra"
@@ -28,13 +27,11 @@ import (
2827
"sigs.k8s.io/kustomize/pkg/loader"
2928
"sigs.k8s.io/kustomize/pkg/resmap"
3029
"sigs.k8s.io/kustomize/pkg/target"
31-
"sigs.k8s.io/kustomize/pkg/transformers/config"
3230
)
3331

3432
type buildOptions struct {
35-
kustomizationPath string
36-
outputPath string
37-
transformerconfigPaths []string
33+
kustomizationPath string
34+
outputPath string
3835
}
3936

4037
var examples = `
@@ -50,11 +47,6 @@ url examples:
5047
sigs.k8s.io/kustomize//examples/multibases?ref=v1.0.6
5148
github.com/Liujingfang1/mysql
5249
github.com/Liujingfang1/kustomize//examples/helloWorld?ref=repoUrl2
53-
54-
Advanced usage:
55-
Use different transformer configurations by passing files to kustomize
56-
build somedir -t someconfigdir
57-
build somedir -t some-transformer-configfile,another-transformer-configfile
5850
`
5951

6052
// NewCmdBuild creates a new build command.
@@ -63,15 +55,14 @@ func NewCmdBuild(
6355
rf *resmap.Factory,
6456
ptf transformer.Factory) *cobra.Command {
6557
var o buildOptions
66-
var p string
6758

6859
cmd := &cobra.Command{
6960
Use: "build [path]",
7061
Short: "Print current configuration per contents of " + constants.KustomizationFileName,
7162
Example: examples,
7263
SilenceUsage: true,
7364
RunE: func(cmd *cobra.Command, args []string) error {
74-
err := o.Validate(args, p, fs)
65+
err := o.Validate(args)
7566
if err != nil {
7667
return err
7768
}
@@ -82,15 +73,11 @@ func NewCmdBuild(
8273
&o.outputPath,
8374
"output", "o", "",
8475
"If specified, write the build output to this path.")
85-
cmd.Flags().StringVarP(
86-
&p,
87-
"transformer-config", "t", "",
88-
"If specified, use the transformer configs load from these files.")
8976
return cmd
9077
}
9178

9279
// Validate validates build command.
93-
func (o *buildOptions) Validate(args []string, p string, fs fs.FileSystem) error {
80+
func (o *buildOptions) Validate(args []string) error {
9481
if len(args) > 1 {
9582
return errors.New("specify one path to " + constants.KustomizationFileName)
9683
}
@@ -100,20 +87,6 @@ func (o *buildOptions) Validate(args []string, p string, fs fs.FileSystem) error
10087
o.kustomizationPath = args[0]
10188
}
10289

103-
if p == "" {
104-
return nil
105-
}
106-
107-
if fs.IsDir(p) {
108-
paths, err := fs.Glob(p + "/*")
109-
if err != nil {
110-
return err
111-
}
112-
o.transformerconfigPaths = paths
113-
} else {
114-
o.transformerconfigPaths = strings.Split(p, ",")
115-
}
116-
11790
return nil
11891
}
11992

@@ -125,12 +98,8 @@ func (o *buildOptions) RunBuild(
12598
if err != nil {
12699
return err
127100
}
128-
tc, err := makeTransformerconfig(fSys, o.transformerconfigPaths)
129-
if err != nil {
130-
return err
131-
}
132101
defer ldr.Cleanup()
133-
kt, err := target.NewKustTarget(ldr, fSys, rf, ptf, tc)
102+
kt, err := target.NewKustTarget(ldr, fSys, rf, ptf)
134103
if err != nil {
135104
return err
136105
}
@@ -149,13 +118,3 @@ func (o *buildOptions) RunBuild(
149118
_, err = out.Write(res)
150119
return err
151120
}
152-
153-
// makeTransformerConfig returns a complete TransformerConfig object from either files
154-
// or the default configs
155-
func makeTransformerconfig(
156-
fSys fs.FileSystem, paths []string) (*config.TransformerConfig, error) {
157-
if paths == nil || len(paths) == 0 {
158-
return config.NewFactory(nil).DefaultConfig(), nil
159-
}
160-
return config.NewFactory(loader.NewFileLoaderAtCwd(fSys)).FromFiles(paths)
161-
}

pkg/commands/build/build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestBuildValidate(t *testing.T) {
5656
}
5757
for _, mycase := range cases {
5858
opts := buildOptions{}
59-
e := opts.Validate(mycase.args, "", nil)
59+
e := opts.Validate(mycase.args)
6060
if len(mycase.erMsg) > 0 {
6161
if e == nil {
6262
t.Errorf("%s: Expected an error %v", mycase.name, mycase.erMsg)

pkg/commands/kustfile/kustomizationfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func determineFieldOrder() []string {
6666
"GeneratorOptions",
6767
"Vars",
6868
"ImageTags",
69+
"Configurations",
6970
}
7071

7172
// Add deprecated fields here.

pkg/commands/kustfile/kustomizationfile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestFieldOrder(t *testing.T) {
4444
"GeneratorOptions",
4545
"Vars",
4646
"ImageTags",
47+
"Configurations",
4748
}
4849
actual := determineFieldOrder()
4950
if len(expected) != len(actual) {

pkg/target/kusttarget.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ type KustTarget struct {
5454
func NewKustTarget(
5555
ldr ifc.Loader, fSys fs.FileSystem,
5656
rFactory *resmap.Factory,
57-
tFactory transformer.Factory,
58-
tConfig *config.TransformerConfig) (*KustTarget, error) {
57+
tFactory transformer.Factory) (*KustTarget, error) {
5958
content, err := loadKustFile(ldr)
6059
if err != nil {
6160
return nil, err
@@ -67,6 +66,10 @@ func NewKustTarget(
6766
return nil, err
6867
}
6968
k.DealWithDeprecatedFields()
69+
tConfig, err := makeTransformerConfig(ldr, k.Configurations)
70+
if err != nil {
71+
return nil, err
72+
}
7073
return &KustTarget{
7174
kustomization: &k,
7275
ldr: ldr,
@@ -87,6 +90,15 @@ func unmarshal(y []byte, o interface{}) error {
8790
return dec.Decode(o)
8891
}
8992

93+
// makeTransformerConfig returns a complete TransformerConfig object from either files
94+
// or the default configs
95+
func makeTransformerConfig(ldr ifc.Loader, paths []string) (*config.TransformerConfig, error) {
96+
if paths == nil || len(paths) == 0 {
97+
return config.NewFactory(nil).DefaultConfig(), nil
98+
}
99+
return config.NewFactory(ldr).FromFiles(paths)
100+
}
101+
90102
// MakeCustomizedResMap creates a ResMap per kustomization instructions.
91103
// The Resources in the returned ResMap are fully customized.
92104
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
@@ -229,7 +241,7 @@ func (kt *KustTarget) loadCustomizedBases() (resmap.ResMap, *interror.Kustomizat
229241
}
230242
target, err := NewKustTarget(
231243
ldr, kt.fSys,
232-
kt.rFactory, kt.tFactory, kt.tConfig)
244+
kt.rFactory, kt.tFactory)
233245
if err != nil {
234246
errs.Append(errors.Wrap(err, "couldn't make target for "+path))
235247
continue
@@ -259,7 +271,7 @@ func (kt *KustTarget) loadBasesAsFlatList() ([]*KustTarget, error) {
259271
continue
260272
}
261273
target, err := NewKustTarget(
262-
ldr, kt.fSys, kt.rFactory, kt.tFactory, kt.tConfig)
274+
ldr, kt.fSys, kt.rFactory, kt.tFactory)
263275
if err != nil {
264276
errs.Append(err)
265277
continue

pkg/target/kusttarget_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"sigs.k8s.io/kustomize/pkg/resid"
3333
"sigs.k8s.io/kustomize/pkg/resmap"
3434
"sigs.k8s.io/kustomize/pkg/resource"
35-
"sigs.k8s.io/kustomize/pkg/transformers/config"
3635
"sigs.k8s.io/kustomize/pkg/types"
3736
)
3837

@@ -96,8 +95,7 @@ func makeKustTarget(t *testing.T, l ifc.Loader) *KustTarget {
9695
fakeFs := fs.MakeFakeFS()
9796
fakeFs.Mkdir("/")
9897
kt, err := NewKustTarget(
99-
l, fakeFs, rf, transformer.NewFactoryImpl(),
100-
config.NewFactory(l).DefaultConfig())
98+
l, fakeFs, rf, transformer.NewFactoryImpl())
10199
if err != nil {
102100
t.Fatalf("Unexpected construction error %v", err)
103101
}

0 commit comments

Comments
 (0)