mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Drain pkg/transformers.
This commit is contained in:
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
package consts
|
||||
|
||||
const commonAnnotationFieldSpecs = `
|
||||
commonAnnotations:
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
package consts
|
||||
|
||||
const commonLabelFieldSpecs = `
|
||||
commonLabels:
|
||||
@@ -1,22 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package defaultconfig provides the default
|
||||
// transformer configurations
|
||||
package defaultconfig
|
||||
package consts
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
5
api/builtinconfig/consts/doc.go
Normal file
5
api/builtinconfig/consts/doc.go
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package consts provides builtin plugin configuration data.
|
||||
package consts
|
||||
10
api/builtinconfig/consts/images.go
Normal file
10
api/builtinconfig/consts/images.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package consts
|
||||
|
||||
const (
|
||||
// imageFieldSpecs is left empty since `containers` and `initContainers`
|
||||
// of *ANY* kind in *ANY* path are builtin supported in code
|
||||
imagesFieldSpecs = ``
|
||||
)
|
||||
11
api/builtinconfig/consts/nameprefix.go
Normal file
11
api/builtinconfig/consts/nameprefix.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package consts
|
||||
|
||||
const (
|
||||
namePrefixFieldSpecs = `
|
||||
namePrefix:
|
||||
- path: metadata/name
|
||||
`
|
||||
)
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
package consts
|
||||
|
||||
const (
|
||||
nameReferenceFieldSpecs = `
|
||||
16
api/builtinconfig/consts/namespace.go
Normal file
16
api/builtinconfig/consts/namespace.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package consts
|
||||
|
||||
const (
|
||||
namespaceFieldSpecs = `
|
||||
namespace:
|
||||
- path: metadata/namespace
|
||||
create: true
|
||||
- path: subjects
|
||||
kind: RoleBinding
|
||||
- path: subjects
|
||||
kind: ClusterRoleBinding
|
||||
`
|
||||
)
|
||||
@@ -1,4 +1,7 @@
|
||||
package defaultconfig
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package consts
|
||||
|
||||
const replicasFieldSpecs = `
|
||||
replicas:
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
package consts
|
||||
|
||||
const (
|
||||
varReferenceFieldSpecs = `
|
||||
8
api/builtinconfig/doc.go
Normal file
8
api/builtinconfig/doc.go
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package builtinconfig provides legacy methods for
|
||||
// configuring builting plugins from a common config file.
|
||||
// It's better to configure them individually if using
|
||||
// a custom configuration.
|
||||
package builtinconfig
|
||||
42
api/builtinconfig/loaddefaultconfig.go
Normal file
42
api/builtinconfig/loaddefaultconfig.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package builtinconfig
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// loadDefaultConfig returns a TranformerConfig
|
||||
// object from a list of files.
|
||||
func loadDefaultConfig(
|
||||
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
|
||||
result := &TransformerConfig{}
|
||||
for _, path := range paths {
|
||||
data, err := ldr.Load(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := makeTransformerConfigFromBytes(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err = result.Merge(t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// makeTransformerConfigFromBytes returns a TransformerConfig object from bytes
|
||||
func makeTransformerConfigFromBytes(data []byte) (*TransformerConfig, error) {
|
||||
var t TransformerConfig
|
||||
err := yaml.Unmarshal(data, &t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.sortFields()
|
||||
return &t, nil
|
||||
}
|
||||
@@ -1,31 +1,25 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package config
|
||||
package builtinconfig
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
||||
)
|
||||
|
||||
func TestMakeDefaultConfig(t *testing.T) {
|
||||
// Confirm default can be made without fatal error inside call.
|
||||
_ = MakeDefaultConfig()
|
||||
}
|
||||
|
||||
func TestFromFiles(t *testing.T) {
|
||||
|
||||
func TestLoadDefaultConfigsFromFiles(t *testing.T) {
|
||||
ldr := loadertest.NewFakeLoader("/app")
|
||||
ldr.AddFile("/app/config.yaml", []byte(`
|
||||
namePrefix:
|
||||
- path: nameprefix/path
|
||||
kind: SomeKind
|
||||
`))
|
||||
tcfg, err := NewFactory(ldr).FromFiles([]string{"/app/config.yaml"})
|
||||
tcfg, err := loadDefaultConfig(ldr, []string{"/app/config.yaml"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package builtinconfig
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package builtinconfig
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -1,29 +1,15 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package config provides the functions to load default or user provided configurations
|
||||
// for different transformers
|
||||
package config
|
||||
package builtinconfig
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sort"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig/consts"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
// TransformerConfig holds the data needed to perform transformations.
|
||||
@@ -47,13 +33,28 @@ func MakeEmptyConfig() *TransformerConfig {
|
||||
// MakeDefaultConfig returns a default TransformerConfig.
|
||||
func MakeDefaultConfig() *TransformerConfig {
|
||||
c, err := makeTransformerConfigFromBytes(
|
||||
defaultconfig.GetDefaultFieldSpecs())
|
||||
consts.GetDefaultFieldSpecs())
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to make default transformconfig: %v", err)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// MakeTransformerConfig returns a merger of custom config,
|
||||
// if any, with default config.
|
||||
func MakeTransformerConfig(
|
||||
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
|
||||
t1 := MakeDefaultConfig()
|
||||
if len(paths) == 0 {
|
||||
return t1, nil
|
||||
}
|
||||
t2, err := loadDefaultConfig(ldr, paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return t1.Merge(t2)
|
||||
}
|
||||
|
||||
// sortFields provides determinism in logging, tests, etc.
|
||||
func (t *TransformerConfig) sortFields() {
|
||||
sort.Sort(t.NamePrefix)
|
||||
@@ -1,29 +1,22 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package builtinconfig_test
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"reflect"
|
||||
. "sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
)
|
||||
|
||||
func TestMakeDefaultConfig(t *testing.T) {
|
||||
// Confirm default can be made without fatal error inside call.
|
||||
_ = MakeDefaultConfig()
|
||||
}
|
||||
|
||||
func TestAddNamereferenceFieldSpec(t *testing.T) {
|
||||
cfg := &TransformerConfig{}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig/consts"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
@@ -19,7 +20,6 @@ import (
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/target"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
@@ -101,7 +101,7 @@ func (th *KustTestHarness) FromMapAndOption(m map[string]interface{}, args *type
|
||||
}
|
||||
|
||||
func (th *KustTestHarness) WriteDefaultConfigs(fName string) {
|
||||
m := defaultconfig.GetDefaultFieldSpecsAsMap()
|
||||
m := consts.GetDefaultFieldSpecsAsMap()
|
||||
var content []byte
|
||||
for _, tCfg := range m {
|
||||
content = append(content, []byte(tCfg)...)
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
package transform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
)
|
||||
|
||||
@@ -32,23 +18,11 @@ type mapTransformer struct {
|
||||
|
||||
var _ resmap.Transformer = &mapTransformer{}
|
||||
|
||||
// NewLabelsMapTransformer constructs a mapTransformer.
|
||||
func NewLabelsMapTransformer(
|
||||
m map[string]string, fs []types.FieldSpec) (resmap.Transformer, error) {
|
||||
return NewMapTransformer(fs, m)
|
||||
}
|
||||
|
||||
// NewAnnotationsMapTransformer construct a mapTransformer.
|
||||
func NewAnnotationsMapTransformer(
|
||||
m map[string]string, fs []types.FieldSpec) (resmap.Transformer, error) {
|
||||
return NewMapTransformer(fs, m)
|
||||
}
|
||||
|
||||
// NewMapTransformer construct a mapTransformer.
|
||||
func NewMapTransformer(
|
||||
pc []types.FieldSpec, m map[string]string) (resmap.Transformer, error) {
|
||||
if m == nil {
|
||||
return NewNoOpTransformer(), nil
|
||||
return newNoOpTransformer(), nil
|
||||
}
|
||||
if pc == nil {
|
||||
return nil, errors.New("fieldSpecs is not expected to be nil")
|
||||
@@ -1,22 +1,22 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package transformers
|
||||
package transform_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
. "sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
)
|
||||
|
||||
var rf = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||
var defaultTransformerConfig = config.MakeDefaultConfig()
|
||||
var resourceFactory = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
|
||||
|
||||
func TestLabelsRun(t *testing.T) {
|
||||
m := resmaptest_test.NewRmBuilder(t, rf).
|
||||
m := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -161,7 +161,7 @@ func TestLabelsRun(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
expected := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -386,9 +386,9 @@ func TestLabelsRun(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
lt, err := NewLabelsMapTransformer(
|
||||
map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"},
|
||||
defaultTransformerConfig.CommonLabels)
|
||||
lt, err := NewMapTransformer(
|
||||
builtinconfig.MakeDefaultConfig().CommonLabels,
|
||||
map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -402,7 +402,7 @@ func TestLabelsRun(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAnnotationsRun(t *testing.T) {
|
||||
m := resmaptest_test.NewRmBuilder(t, rf).
|
||||
m := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -451,7 +451,7 @@ func TestAnnotationsRun(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
expected := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -515,9 +515,9 @@ func TestAnnotationsRun(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
at, err := NewAnnotationsMapTransformer(
|
||||
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"},
|
||||
defaultTransformerConfig.CommonAnnotations)
|
||||
at, err := NewMapTransformer(
|
||||
builtinconfig.MakeDefaultConfig().CommonAnnotations,
|
||||
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -531,7 +531,7 @@ func TestAnnotationsRun(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAnnotationsRunWithNullValue(t *testing.T) {
|
||||
m := resmaptest_test.NewRmBuilder(t, rf).
|
||||
m := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -541,7 +541,7 @@ func TestAnnotationsRunWithNullValue(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
expected := resmaptest_test.NewRmBuilder(t, resourceFactory).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -554,9 +554,9 @@ func TestAnnotationsRunWithNullValue(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
at, err := NewAnnotationsMapTransformer(
|
||||
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"},
|
||||
defaultTransformerConfig.CommonAnnotations)
|
||||
at, err := NewMapTransformer(
|
||||
builtinconfig.MakeDefaultConfig().CommonAnnotations,
|
||||
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
package transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,20 +1,7 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
package transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,27 +1,14 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
package transform_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
. "sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type noopMutator struct {
|
||||
21
api/transform/nooptransformer.go
Normal file
21
api/transform/nooptransformer.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package transform
|
||||
|
||||
import "sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
|
||||
// noOpTransformer contains a no-op transformer.
|
||||
type noOpTransformer struct{}
|
||||
|
||||
var _ resmap.Transformer = &noOpTransformer{}
|
||||
|
||||
// newNoOpTransformer constructs a noOpTransformer.
|
||||
func newNoOpTransformer() resmap.Transformer {
|
||||
return &noOpTransformer{}
|
||||
}
|
||||
|
||||
// Transform does nothing.
|
||||
func (o *noOpTransformer) Transform(_ resmap.ResMap) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package types
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
. "sigs.k8s.io/kustomize/v3/api/types"
|
||||
)
|
||||
|
||||
func TestPathSlice(t *testing.T) {
|
||||
|
||||
@@ -36,7 +36,7 @@ complete plugin argument specification.
|
||||
[types.GeneratorOptions]: ../../api/types/generatoroptions.go
|
||||
[types.SecretArgs]: ../../api/types/secretargs.go
|
||||
[types.ConfigMapArgs]: ../../api/types/configmapargs.go
|
||||
[config.FieldSpec]: ../../pkg/transformers/config/fieldspec.go
|
||||
[config.FieldSpec]: ../../api/builtinconfig/fieldspec.go
|
||||
[types.ObjectMeta]: ../../api/types/objectmeta.go
|
||||
[types.Selector]: ../../api/types/selector.go
|
||||
[types.Replica]: ../../api/types/replica.go
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[plugin]: ../docs/plugins
|
||||
[fields]: ../docs/fields.md
|
||||
[fields in a kustomization file]: ../docs/fields.md
|
||||
[TransformerConfig]: ../pkg/transformers/config/transformerconfig.go
|
||||
[TransformerConfig]: ../api/builtinconfig/transformerconfig.go
|
||||
[kustomization]: ../docs/glossary.md#kustomization
|
||||
|
||||
# Customizing kustomize
|
||||
|
||||
1
go.sum
1
go.sum
@@ -438,6 +438,7 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphD
|
||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
|
||||
sigs.k8s.io/kustomize/pluginator v1.0.0 h1:aeLqD8CIaqr++49YrcuRUcXl5vVKYLhCSfwXUi3ifQ4=
|
||||
sigs.k8s.io/kustomize/pluginator v1.0.0/go.mod h1:i8HdU5FdH1zDjCKiFf5CNl7slsc0QffyKsY2OuPynJ0=
|
||||
sigs.k8s.io/kustomize/v3 v3.2.0/go.mod h1:ztX4zYc/QIww3gSripwF7TBOarBTm5BvyAMem0kCzOE=
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig/consts"
|
||||
"sigs.k8s.io/kustomize/v3/api/filesys"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config/defaultconfig"
|
||||
)
|
||||
|
||||
// NewCmdConfig returns an instance of 'config' subcommand.
|
||||
@@ -89,7 +89,7 @@ func (o *saveOptions) Complete(fSys filesys.FileSystem) error {
|
||||
|
||||
// RunSave saves the default transformer configurations local directory
|
||||
func (o *saveOptions) RunSave(fSys filesys.FileSystem) error {
|
||||
m := defaultconfig.GetDefaultFieldSpecsAsMap()
|
||||
m := consts.GetDefaultFieldSpecsAsMap()
|
||||
for tname, tcfg := range m {
|
||||
filename := filepath.Join(o.saveDirectory, tname+".yaml")
|
||||
err := fSys.WriteFile(filename, []byte(tcfg))
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package accumulator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/spec"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/kube-openapi/pkg/common"
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@@ -34,8 +22,8 @@ type nameToApiMap map[string]common.OpenAPIDefinition
|
||||
|
||||
// LoadConfigFromCRDs parse CRD schemas from paths into a TransformerConfig
|
||||
func LoadConfigFromCRDs(
|
||||
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
|
||||
tc := MakeEmptyConfig()
|
||||
ldr ifc.Loader, paths []string) (*builtinconfig.TransformerConfig, error) {
|
||||
tc := builtinconfig.MakeEmptyConfig()
|
||||
for _, path := range paths {
|
||||
content, err := ldr.Load(path)
|
||||
if err != nil {
|
||||
@@ -66,13 +54,13 @@ func makeNameToApiMap(content []byte) (result nameToApiMap, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func makeConfigFromApiMap(m nameToApiMap) (*TransformerConfig, error) {
|
||||
result := MakeEmptyConfig()
|
||||
func makeConfigFromApiMap(m nameToApiMap) (*builtinconfig.TransformerConfig, error) {
|
||||
result := builtinconfig.MakeEmptyConfig()
|
||||
for name, api := range m {
|
||||
if !looksLikeAk8sType(api.Schema.SchemaProps.Properties) {
|
||||
continue
|
||||
}
|
||||
tc := MakeEmptyConfig()
|
||||
tc := builtinconfig.MakeEmptyConfig()
|
||||
err := loadCrdIntoConfig(
|
||||
tc, makeGvkFromTypeName(name), m, name, []string{})
|
||||
if err != nil {
|
||||
@@ -134,7 +122,7 @@ const (
|
||||
|
||||
// loadCrdIntoConfig loads a CRD spec into a TransformerConfig
|
||||
func loadCrdIntoConfig(
|
||||
theConfig *TransformerConfig, theGvk resid.Gvk, theMap nameToApiMap,
|
||||
theConfig *builtinconfig.TransformerConfig, theGvk resid.Gvk, theMap nameToApiMap,
|
||||
typeName string, path []string) (err error) {
|
||||
api, ok := theMap[typeName]
|
||||
if !ok {
|
||||
@@ -174,7 +162,7 @@ func loadCrdIntoConfig(
|
||||
nameKey = "name"
|
||||
}
|
||||
err = theConfig.AddNamereferenceFieldSpec(
|
||||
NameBackReferences{
|
||||
builtinconfig.NameBackReferences{
|
||||
Gvk: resid.Gvk{Kind: kind, Version: version},
|
||||
FieldSpecs: []types.FieldSpec{
|
||||
makeFs(theGvk, append(path, propName, nameKey))},
|
||||
@@ -1,28 +1,17 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
package accumulator_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/internal/loadertest"
|
||||
. "sigs.k8s.io/kustomize/v3/pkg/accumulator"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
@@ -156,7 +145,7 @@ func makeLoader(t *testing.T) ifc.Loader {
|
||||
}
|
||||
|
||||
func TestLoadCRDs(t *testing.T) {
|
||||
nbrs := []NameBackReferences{
|
||||
nbrs := []builtinconfig.NameBackReferences{
|
||||
{
|
||||
Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
|
||||
FieldSpecs: []types.FieldSpec{
|
||||
@@ -179,7 +168,7 @@ func TestLoadCRDs(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
expectedTc := &TransformerConfig{
|
||||
expectedTc := &builtinconfig.TransformerConfig{
|
||||
NameReference: nbrs,
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package transformers
|
||||
package accumulator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
type nameReferenceTransformer struct {
|
||||
backRefs []config.NameBackReferences
|
||||
backRefs []builtinconfig.NameBackReferences
|
||||
}
|
||||
|
||||
var _ resmap.Transformer = &nameReferenceTransformer{}
|
||||
|
||||
// NewNameReferenceTransformer constructs a nameReferenceTransformer
|
||||
// newNameReferenceTransformer constructs a nameReferenceTransformer
|
||||
// with a given slice of NameBackReferences.
|
||||
func NewNameReferenceTransformer(br []config.NameBackReferences) resmap.Transformer {
|
||||
func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.Transformer {
|
||||
if br == nil {
|
||||
log.Fatal("backrefs not expected to be nil")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
||||
if candidates == nil {
|
||||
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
|
||||
}
|
||||
err := MutateField(
|
||||
err := transform.MutateField(
|
||||
referrer.Map(),
|
||||
fSpec.PathSlice(),
|
||||
fSpec.CreateIfNotPresent,
|
||||
@@ -1,12 +1,13 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package transformers
|
||||
package accumulator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
@@ -462,7 +463,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
err := nrt.Transform(m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -522,7 +523,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
|
||||
expectedErr: "is expected to contain a name field"},
|
||||
}
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
for _, test := range tests {
|
||||
err := nrt.Transform(test.resMap)
|
||||
if err == nil {
|
||||
@@ -580,7 +581,7 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
|
||||
|
||||
m1 := resmaptest_test.NewRmBuilder(t, rf).AddR(v1).AddR(c1).ResMap()
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
if err := nrt.Transform(m1); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -719,7 +720,7 @@ func TestNameReferenceNamespace(t *testing.T) {
|
||||
ReplaceResource(deploymentMap(ns1, prefixedname, prefixedname, prefixedname)).
|
||||
ReplaceResource(deploymentMap(ns2, suffixedname, suffixedname, suffixedname)).ResMap()
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
err := nrt.Transform(m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -882,7 +883,7 @@ func TestNameReferenceClusterWide(t *testing.T) {
|
||||
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
|
||||
clusterRole.AppendRefBy(clusterRoleBindingId)
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
err := nrt.Transform(m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -1010,7 +1011,7 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
|
||||
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
|
||||
clusterRole.AppendRefBy(clusterRoleBindingId)
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
err := nrt.Transform(m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -1048,7 +1049,7 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
|
||||
ReplaceResource(deploymentMap("", "p1-deploy1", "p1-cm1-hash", "p1-secret1-hash")).
|
||||
ResMap()
|
||||
|
||||
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
|
||||
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
|
||||
err := nrt.Transform(m)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -1,42 +1,30 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
package accumulator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/expansion"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
)
|
||||
|
||||
type RefVarTransformer struct {
|
||||
type refVarTransformer struct {
|
||||
varMap map[string]interface{}
|
||||
replacementCounts map[string]int
|
||||
fieldSpecs []types.FieldSpec
|
||||
mappingFunc func(string) interface{}
|
||||
}
|
||||
|
||||
// NewRefVarTransformer returns a new RefVarTransformer
|
||||
// newRefVarTransformer returns a new refVarTransformer
|
||||
// that replaces $(VAR) style variables with values.
|
||||
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
||||
func NewRefVarTransformer(
|
||||
varMap map[string]interface{}, fs []types.FieldSpec) *RefVarTransformer {
|
||||
return &RefVarTransformer{
|
||||
func newRefVarTransformer(
|
||||
varMap map[string]interface{}, fs []types.FieldSpec) *refVarTransformer {
|
||||
return &refVarTransformer{
|
||||
varMap: varMap,
|
||||
fieldSpecs: fs,
|
||||
}
|
||||
@@ -46,7 +34,7 @@ func NewRefVarTransformer(
|
||||
// embedded instances of $VAR style variables, e.g. a container command string.
|
||||
// The function returns the string with the variables expanded to their final
|
||||
// values.
|
||||
func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
|
||||
func (rv *refVarTransformer) replaceVars(in interface{}) (interface{}, error) {
|
||||
switch vt := in.(type) {
|
||||
case []interface{}:
|
||||
var xs []interface{}
|
||||
@@ -90,7 +78,7 @@ func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
|
||||
|
||||
// UnusedVars returns slice of Var names that were unused
|
||||
// after a Transform run.
|
||||
func (rv *RefVarTransformer) UnusedVars() []string {
|
||||
func (rv *refVarTransformer) UnusedVars() []string {
|
||||
var unused []string
|
||||
for k := range rv.varMap {
|
||||
_, ok := rv.replacementCounts[k]
|
||||
@@ -102,14 +90,14 @@ func (rv *RefVarTransformer) UnusedVars() []string {
|
||||
}
|
||||
|
||||
// Transform replaces $(VAR) style variables with values.
|
||||
func (rv *RefVarTransformer) Transform(m resmap.ResMap) error {
|
||||
func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
|
||||
rv.replacementCounts = make(map[string]int)
|
||||
rv.mappingFunc = expansion.MappingFuncFor(
|
||||
rv.replacementCounts, rv.varMap)
|
||||
for _, res := range m.Resources() {
|
||||
for _, fieldSpec := range rv.fieldSpecs {
|
||||
if res.OrgId().IsSelected(&fieldSpec.Gvk) {
|
||||
if err := MutateField(
|
||||
if err := transform.MutateField(
|
||||
res.Map(), fieldSpec.PathSlice(),
|
||||
false, rv.replaceVars); err != nil {
|
||||
return err
|
||||
@@ -1,19 +1,21 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package transformers
|
||||
package accumulator
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
func TestVarRef(t *testing.T) {
|
||||
func TestRefVarTransformer(t *testing.T) {
|
||||
type given struct {
|
||||
varMap map[string]interface{}
|
||||
fs []types.FieldSpec
|
||||
@@ -44,7 +46,8 @@ func TestVarRef(t *testing.T) {
|
||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
|
||||
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
|
||||
},
|
||||
res: resmaptest_test.NewRmBuilder(t, rf).
|
||||
res: resmaptest_test.NewRmBuilder(
|
||||
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -75,7 +78,8 @@ func TestVarRef(t *testing.T) {
|
||||
}}).ResMap(),
|
||||
},
|
||||
expected: expected{
|
||||
res: resmaptest_test.NewRmBuilder(t, rf).
|
||||
res: resmaptest_test.NewRmBuilder(
|
||||
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
@@ -112,7 +116,7 @@ func TestVarRef(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
// arrange
|
||||
tr := NewRefVarTransformer(tc.given.varMap, tc.given.fs)
|
||||
tr := newRefVarTransformer(tc.given.varMap, tc.given.fs)
|
||||
|
||||
// act
|
||||
err := tr.Transform(tc.given.res)
|
||||
@@ -8,11 +8,10 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
)
|
||||
|
||||
// ResAccumulator accumulates resources and the rules
|
||||
@@ -20,14 +19,14 @@ import (
|
||||
// plus stuff needed to modify the ResMap.
|
||||
type ResAccumulator struct {
|
||||
resMap resmap.ResMap
|
||||
tConfig *config.TransformerConfig
|
||||
tConfig *builtinconfig.TransformerConfig
|
||||
varSet types.VarSet
|
||||
}
|
||||
|
||||
func MakeEmptyAccumulator() *ResAccumulator {
|
||||
ra := &ResAccumulator{}
|
||||
ra.resMap = resmap.New()
|
||||
ra.tConfig = &config.TransformerConfig{}
|
||||
ra.tConfig = &builtinconfig.TransformerConfig{}
|
||||
ra.varSet = types.NewVarSet()
|
||||
return ra
|
||||
}
|
||||
@@ -53,12 +52,12 @@ func (ra *ResAccumulator) AbsorbAll(
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) MergeConfig(
|
||||
tConfig *config.TransformerConfig) (err error) {
|
||||
tConfig *builtinconfig.TransformerConfig) (err error) {
|
||||
ra.tConfig, err = ra.tConfig.Merge(tConfig)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig {
|
||||
func (ra *ResAccumulator) GetTransformerConfig() *builtinconfig.TransformerConfig {
|
||||
return ra.tConfig
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ func (ra *ResAccumulator) ResolveVars() error {
|
||||
if len(replacementMap) == 0 {
|
||||
return nil
|
||||
}
|
||||
t := transformers.NewRefVarTransformer(
|
||||
t := newRefVarTransformer(
|
||||
replacementMap, ra.tConfig.VarReference)
|
||||
err = ra.Transform(t)
|
||||
if len(t.UnusedVars()) > 0 {
|
||||
@@ -162,6 +161,6 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
|
||||
if ra.tConfig.NameReference == nil {
|
||||
return nil
|
||||
}
|
||||
return ra.Transform(transformers.NewNameReferenceTransformer(
|
||||
return ra.Transform(newNameReferenceTransformer(
|
||||
ra.tConfig.NameReference))
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
@@ -17,12 +18,11 @@ import (
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
)
|
||||
|
||||
func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory) {
|
||||
ra := MakeEmptyAccumulator()
|
||||
err := ra.MergeConfig(config.MakeDefaultConfig())
|
||||
err := ra.MergeConfig(builtinconfig.MakeDefaultConfig())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
|
||||
@@ -10,17 +10,17 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/accumulator"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
@@ -216,7 +216,7 @@ func (kt *KustTarget) AccumulateTarget() (
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "accumulating resources")
|
||||
}
|
||||
tConfig, err := config.MakeTransformerConfig(
|
||||
tConfig, err := builtinconfig.MakeTransformerConfig(
|
||||
kt.ldr, kt.kustomization.Configurations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -226,7 +226,7 @@ func (kt *KustTarget) AccumulateTarget() (
|
||||
return nil, errors.Wrapf(
|
||||
err, "merging config %v", tConfig)
|
||||
}
|
||||
crdTc, err := config.LoadConfigFromCRDs(kt.ldr, kt.kustomization.Crds)
|
||||
crdTc, err := accumulator.LoadConfigFromCRDs(kt.ldr, kt.kustomization.Crds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(
|
||||
err, "loading CRDs %v", kt.kustomization.Crds)
|
||||
@@ -300,7 +300,7 @@ func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error {
|
||||
return err
|
||||
}
|
||||
r = append(r, lts...)
|
||||
t := transformers.NewMultiTransformer(r)
|
||||
t := transform.NewMultiTransformer(r)
|
||||
return ra.Transform(t)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
package target
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/builtinconfig"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
)
|
||||
|
||||
// Functions dedicated to configuring the builtin
|
||||
@@ -42,7 +42,7 @@ func (kt *KustTarget) configureBuiltinGenerators() (
|
||||
}
|
||||
|
||||
func (kt *KustTarget) configureBuiltinTransformers(
|
||||
tc *config.TransformerConfig) (
|
||||
tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
for _, bpt := range []plugins.BuiltinPluginType{
|
||||
plugins.PatchStrategicMergeTransformer,
|
||||
@@ -120,9 +120,9 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
kt *KustTarget,
|
||||
bpt plugins.BuiltinPluginType,
|
||||
f tFactory,
|
||||
tc *config.TransformerConfig) (result []resmap.Transformer, err error){
|
||||
tc *builtinconfig.TransformerConfig) (result []resmap.Transformer, err error){
|
||||
plugins.NamespaceTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
|
||||
@@ -140,7 +140,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
},
|
||||
|
||||
plugins.PatchJson6902Transformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
|
||||
@@ -161,7 +161,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.PatchStrategicMergeTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
if len(kt.kustomization.PatchesStrategicMerge) == 0 {
|
||||
return
|
||||
@@ -180,7 +180,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.PatchTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, _ *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
if len(kt.kustomization.Patches) == 0 {
|
||||
return
|
||||
@@ -204,7 +204,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.LabelTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
Labels map[string]string
|
||||
@@ -221,7 +221,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.AnnotationsTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
Annotations map[string]string
|
||||
@@ -238,7 +238,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.PrefixSuffixTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
Prefix string
|
||||
@@ -257,7 +257,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.ImageTagTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
ImageTag types.Image
|
||||
@@ -276,7 +276,7 @@ var transformerConfigurators = map[plugins.BuiltinPluginType]func(
|
||||
return
|
||||
},
|
||||
plugins.ReplicaCountTransformer: func(
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *config.TransformerConfig) (
|
||||
kt *KustTarget, bpt plugins.BuiltinPluginType, f tFactory, tc *builtinconfig.TransformerConfig) (
|
||||
result []resmap.Transformer, err error) {
|
||||
var c struct {
|
||||
Replica types.Replica
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
|
||||
const (
|
||||
// imageFieldSpecs is left empty since `containers` and `initContainers`
|
||||
// of *ANY* kind in *ANY* path are builtin supported in code
|
||||
imagesFieldSpecs = ``
|
||||
)
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
|
||||
const (
|
||||
namePrefixFieldSpecs = `
|
||||
namePrefix:
|
||||
- path: metadata/name
|
||||
`
|
||||
)
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package defaultconfig
|
||||
|
||||
const (
|
||||
namespaceFieldSpecs = `
|
||||
namespace:
|
||||
- path: metadata/namespace
|
||||
create: true
|
||||
- path: subjects
|
||||
kind: RoleBinding
|
||||
- path: subjects
|
||||
kind: ClusterRoleBinding
|
||||
`
|
||||
)
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// Factory makes instances of TransformerConfig.
|
||||
type Factory struct {
|
||||
ldr ifc.Loader
|
||||
}
|
||||
|
||||
// MakeTransformerConfig returns a merger of custom config,
|
||||
// if any, with default config.
|
||||
func MakeTransformerConfig(
|
||||
ldr ifc.Loader, paths []string) (*TransformerConfig, error) {
|
||||
t1 := MakeDefaultConfig()
|
||||
if len(paths) == 0 {
|
||||
return t1, nil
|
||||
}
|
||||
t2, err := NewFactory(ldr).FromFiles(paths)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return t1.Merge(t2)
|
||||
}
|
||||
|
||||
func NewFactory(l ifc.Loader) *Factory {
|
||||
return &Factory{ldr: l}
|
||||
}
|
||||
|
||||
func (tf *Factory) loader() ifc.Loader {
|
||||
if tf.ldr.(ifc.Loader) == nil {
|
||||
log.Fatal("no loader")
|
||||
}
|
||||
return tf.ldr
|
||||
}
|
||||
|
||||
// FromFiles returns a TranformerConfig object from a list of files
|
||||
func (tf *Factory) FromFiles(
|
||||
paths []string) (*TransformerConfig, error) {
|
||||
result := &TransformerConfig{}
|
||||
for _, path := range paths {
|
||||
data, err := tf.loader().Load(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t, err := makeTransformerConfigFromBytes(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err = result.Merge(t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// makeTransformerConfigFromBytes returns a TransformerConfig object from bytes
|
||||
func makeTransformerConfigFromBytes(data []byte) (*TransformerConfig, error) {
|
||||
var t TransformerConfig
|
||||
err := yaml.Unmarshal(data, &t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.sortFields()
|
||||
return &t, nil
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Utilities to aid transformer plugins.
|
||||
//
|
||||
// TODO: Push remaining code down into the plugins
|
||||
// or into an appropriately named utility package.
|
||||
// This package made more sense in the pre-plugin days.
|
||||
package transformers
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package transformers
|
||||
|
||||
import "sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
|
||||
// noOpTransformer contains a no-op transformer.
|
||||
type noOpTransformer struct{}
|
||||
|
||||
var _ resmap.Transformer = &noOpTransformer{}
|
||||
|
||||
// NewNoOpTransformer constructs a noOpTransformer.
|
||||
func NewNoOpTransformer() resmap.Transformer {
|
||||
return &noOpTransformer{}
|
||||
}
|
||||
|
||||
// Transform does nothing.
|
||||
func (o *noOpTransformer) Transform(_ resmap.ResMap) error {
|
||||
return nil
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ func (p *AnnotationsTransformerPlugin) Config(
|
||||
}
|
||||
|
||||
func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
t, err := transformers.NewMapTransformer(
|
||||
t, err := transform.NewMapTransformer(
|
||||
p.FieldSpecs,
|
||||
p.Annotations,
|
||||
)
|
||||
|
||||
@@ -4,11 +4,11 @@ package builtin
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
if !r.OrgId().IsSelected(&path.Gvk) {
|
||||
continue
|
||||
}
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(), path.PathSlice(), false, p.mutateImage)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ func (p *LabelTransformerPlugin) Config(
|
||||
}
|
||||
|
||||
func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
t, err := transformers.NewMapTransformer(
|
||||
t, err := transform.NewMapTransformer(
|
||||
p.FieldSpecs,
|
||||
p.Labels,
|
||||
)
|
||||
|
||||
@@ -3,12 +3,12 @@ package builtin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
applicableFs := p.applicableFieldSpecs(id)
|
||||
|
||||
for _, fs := range applicableFs {
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
||||
p.changeNamespace(r))
|
||||
if err != nil {
|
||||
|
||||
@@ -4,11 +4,11 @@ package builtin
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
// the addPrefixSuffix method will not
|
||||
// change the name if both the prefix and suffix
|
||||
// are empty.
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(),
|
||||
path.PathSlice(),
|
||||
path.CreateIfNotPresent,
|
||||
|
||||
@@ -3,11 +3,11 @@ package builtin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
|
||||
for _, res := range append(matchOriginal, matchCurrent...) {
|
||||
found = true
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
res.Map(), replicaSpec.PathSlice(),
|
||||
replicaSpec.CreateIfNotPresent, p.addReplicas)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func (p *plugin) Config(
|
||||
}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
t, err := transformers.NewMapTransformer(
|
||||
t, err := transform.NewMapTransformer(
|
||||
p.FieldSpecs,
|
||||
p.Annotations,
|
||||
)
|
||||
|
||||
@@ -7,11 +7,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
if !r.OrgId().IsSelected(&path.Gvk) {
|
||||
continue
|
||||
}
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(), path.PathSlice(), false, p.mutateImage)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ func (p *plugin) Config(
|
||||
}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
t, err := transformers.NewMapTransformer(
|
||||
t, err := transform.NewMapTransformer(
|
||||
p.FieldSpecs,
|
||||
p.Labels,
|
||||
)
|
||||
|
||||
@@ -6,12 +6,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -45,7 +45,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
applicableFs := p.applicableFieldSpecs(id)
|
||||
|
||||
for _, fs := range applicableFs {
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(), fs.PathSlice(), fs.CreateIfNotPresent,
|
||||
p.changeNamespace(r))
|
||||
if err != nil {
|
||||
|
||||
@@ -7,11 +7,11 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -85,7 +85,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
// the addPrefixSuffix method will not
|
||||
// change the name if both the prefix and suffix
|
||||
// are empty.
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
r.Map(),
|
||||
path.PathSlice(),
|
||||
path.CreateIfNotPresent,
|
||||
|
||||
@@ -6,11 +6,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/api/transform"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/api/resid"
|
||||
"sigs.k8s.io/kustomize/v3/api/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
|
||||
for _, res := range append(matchOriginal, matchCurrent...) {
|
||||
found = true
|
||||
err := transformers.MutateField(
|
||||
err := transform.MutateField(
|
||||
res.Map(), replicaSpec.PathSlice(),
|
||||
replicaSpec.CreateIfNotPresent, p.addReplicas)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user