move transformerconfig package to transformers/config

This commit is contained in:
Jingfang Liu
2018-10-10 14:30:31 -07:00
parent ca4a5d33f0
commit c33a97fcf2
27 changed files with 47 additions and 48 deletions

View File

@@ -30,7 +30,7 @@ import (
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/target" "sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
type buildOptions struct { type buildOptions struct {
@@ -159,14 +159,14 @@ func (o *buildOptions) RunBuild(
// makeTransformerConfig returns a complete TransformerConfig object from either files // makeTransformerConfig returns a complete TransformerConfig object from either files
// or the default configs // or the default configs
func makeTransformerconfig( func makeTransformerconfig(
fSys fs.FileSystem, paths []string) (*transformerconfig.TransformerConfig, error) { fSys fs.FileSystem, paths []string) (*config.TransformerConfig, error) {
if paths == nil || len(paths) == 0 { if paths == nil || len(paths) == 0 {
return transformerconfig.NewFactory(nil).DefaultConfig(), nil return config.NewFactory(nil).DefaultConfig(), nil
} }
ldr, err := loader.NewLoader(".", "", fSys) ldr, err := loader.NewLoader(".", "", fSys)
if err != nil { if err != nil {
return nil, errors.Wrap( return nil, errors.Wrap(
err, "cannot create transformer configuration loader") err, "cannot create transformer configuration loader")
} }
return transformerconfig.NewFactory(ldr).FromFiles(paths) return config.NewFactory(ldr).FromFiles(paths)
} }

View File

@@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/transformerconfig/defaultconfig" "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig"
) )
// NewCmdConfig returns an instance of 'config' subcommand. // NewCmdConfig returns an instance of 'config' subcommand.

View File

@@ -34,8 +34,8 @@ import (
patchtransformer "sigs.k8s.io/kustomize/pkg/patch/transformer" patchtransformer "sigs.k8s.io/kustomize/pkg/patch/transformer"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformerconfig"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
"sigs.k8s.io/kustomize/pkg/transformers/config"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
) )
@@ -45,7 +45,7 @@ type KustTarget struct {
ldr ifc.Loader ldr ifc.Loader
fSys fs.FileSystem fSys fs.FileSystem
rf *resmap.Factory rf *resmap.Factory
tcfg *transformerconfig.TransformerConfig tcfg *config.TransformerConfig
ptf transformer.Factory ptf transformer.Factory
} }
@@ -54,7 +54,7 @@ func NewKustTarget(
ldr ifc.Loader, fSys fs.FileSystem, ldr ifc.Loader, fSys fs.FileSystem,
rf *resmap.Factory, rf *resmap.Factory,
ptf transformer.Factory, ptf transformer.Factory,
tcfg *transformerconfig.TransformerConfig) (*KustTarget, error) { tcfg *config.TransformerConfig) (*KustTarget, error) {
content, err := ldr.Load(constants.KustomizationFileName) content, err := ldr.Load(constants.KustomizationFileName)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -132,8 +132,7 @@ func (kt *KustTarget) loadCustomizedResMap() (resmap.ResMap, error) {
if err != nil { if err != nil {
errs.Append(errors.Wrap(err, "loadResMapFromBasesAndResources")) errs.Append(errors.Wrap(err, "loadResMapFromBasesAndResources"))
} }
crdPathConfigs, err := transformerconfig. crdPathConfigs, err := config.NewFactory(kt.ldr).LoadCRDs(kt.kustomization.Crds)
NewFactory(kt.ldr).LoadCRDs(kt.kustomization.Crds)
kt.tcfg = kt.tcfg.Merge(crdPathConfigs) kt.tcfg = kt.tcfg.Merge(crdPathConfigs)
if err != nil { if err != nil {
errs.Append(errors.Wrap(err, "LoadCRDs")) errs.Append(errors.Wrap(err, "LoadCRDs"))

View File

@@ -32,7 +32,7 @@ import (
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
const ( const (
@@ -96,7 +96,7 @@ func makeKustTarget(t *testing.T, l ifc.Loader) *KustTarget {
fakeFs.Mkdir("/") fakeFs.Mkdir("/")
kt, err := NewKustTarget( kt, err := NewKustTarget(
l, fakeFs, rf, transformer.NewFactoryImpl(), l, fakeFs, rf, transformer.NewFactoryImpl(),
transformerconfig.NewFactory(l).DefaultConfig()) config.NewFactory(l).DefaultConfig())
if err != nil { if err != nil {
t.Fatalf("Unexpected construction error %v", err) t.Fatalf("Unexpected construction error %v", err)
} }

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
// Annotation is to mark a field as annotations. // Annotation is to mark a field as annotations.
// "x-kubernetes-annotation": "" // "x-kubernetes-annotation": ""

View File

@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"log" "log"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/transformerconfig/defaultconfig" "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig"
) )
// Factory makes instances of TransformerConfig. // Factory makes instances of TransformerConfig.

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"reflect" "reflect"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"encoding/json" "encoding/json"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"reflect" "reflect"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"strings" "strings"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"reflect" "reflect"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"

View File

@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package transformerconfig provides the functions to load default or user provided configurations // Package config provides the functions to load default or user provided configurations
// for different transformers // for different transformers
package transformerconfig package config
import ( import (
"sort" "sort"

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformerconfig package config
import ( import (
"testing" "testing"

View File

@@ -21,30 +21,30 @@ import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
// mapTransformer contains a map string->string and path configs // mapTransformer contains a map string->string and path configs
// The map will be applied to the fields specified in path configs. // The map will be applied to the fields specified in path configs.
type mapTransformer struct { type mapTransformer struct {
m map[string]string m map[string]string
pathConfigs []transformerconfig.PathConfig pathConfigs []config.PathConfig
} }
var _ Transformer = &mapTransformer{} var _ Transformer = &mapTransformer{}
// NewLabelsMapTransformer construct a mapTransformer with a given pathConfig slice // NewLabelsMapTransformer construct a mapTransformer with a given pathConfig slice
func NewLabelsMapTransformer(m map[string]string, p []transformerconfig.PathConfig) (Transformer, error) { func NewLabelsMapTransformer(m map[string]string, p []config.PathConfig) (Transformer, error) {
return NewMapTransformer(p, m) return NewMapTransformer(p, m)
} }
// NewAnnotationsMapTransformer construct a mapTransformer with a given pathConfig slice // NewAnnotationsMapTransformer construct a mapTransformer with a given pathConfig slice
func NewAnnotationsMapTransformer(m map[string]string, p []transformerconfig.PathConfig) (Transformer, error) { func NewAnnotationsMapTransformer(m map[string]string, p []config.PathConfig) (Transformer, error) {
return NewMapTransformer(p, m) return NewMapTransformer(p, m)
} }
// NewMapTransformer construct a mapTransformer. // NewMapTransformer construct a mapTransformer.
func NewMapTransformer(pc []transformerconfig.PathConfig, m map[string]string) (Transformer, error) { func NewMapTransformer(pc []config.PathConfig, m map[string]string) (Transformer, error) {
if m == nil { if m == nil {
return NewNoOpTransformer(), nil return NewNoOpTransformer(), nil
} }

View File

@@ -25,7 +25,7 @@ import (
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
var service = gvk.Gvk{Version: "v1", Kind: "Service"} var service = gvk.Gvk{Version: "v1", Kind: "Service"}
@@ -42,7 +42,7 @@ var crb = gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Clus
var sa = gvk.Gvk{Version: "v1", Kind: "ServiceAccount"} var sa = gvk.Gvk{Version: "v1", Kind: "ServiceAccount"}
var ingress = gvk.Gvk{Kind: "Ingress"} var ingress = gvk.Gvk{Kind: "Ingress"}
var rf = resource.NewFactory(k8sdeps.NewKunstructuredFactoryImpl()) var rf = resource.NewFactory(k8sdeps.NewKunstructuredFactoryImpl())
var defaultTransformerConfig = transformerconfig.NewFactory(nil).DefaultConfig() var defaultTransformerConfig = config.NewFactory(nil).DefaultConfig()
func TestLabelsRun(t *testing.T) { func TestLabelsRun(t *testing.T) {
m := resmap.ResMap{ m := resmap.ResMap{

View File

@@ -23,19 +23,19 @@ import (
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
// nameReferenceTransformer contains the referencing info between 2 GroupVersionKinds // nameReferenceTransformer contains the referencing info between 2 GroupVersionKinds
type nameReferenceTransformer struct { type nameReferenceTransformer struct {
pathConfigs []transformerconfig.ReferencePathConfig pathConfigs []config.ReferencePathConfig
} }
var _ Transformer = &nameReferenceTransformer{} var _ Transformer = &nameReferenceTransformer{}
// NewNameReferenceTransformer constructs a nameReferenceTransformer // NewNameReferenceTransformer constructs a nameReferenceTransformer
// with a given Reference PathConfig slice // with a given Reference PathConfig slice
func NewNameReferenceTransformer(pc []transformerconfig.ReferencePathConfig) (Transformer, error) { func NewNameReferenceTransformer(pc []config.ReferencePathConfig) (Transformer, error) {
if pc == nil { if pc == nil {
return nil, errors.New("pathConfigs is not expected to be nil") return nil, errors.New("pathConfigs is not expected to be nil")
} }

View File

@@ -19,16 +19,16 @@ package transformers
import ( import (
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
type namespaceTransformer struct { type namespaceTransformer struct {
namespace string namespace string
pathConfigs []transformerconfig.PathConfig pathConfigs []config.PathConfig
skipPathConfigs []transformerconfig.PathConfig skipPathConfigs []config.PathConfig
} }
var skipNamespacePathConfigs = []transformerconfig.PathConfig{ var skipNamespacePathConfigs = []config.PathConfig{
{ {
Gvk: gvk.Gvk{ Gvk: gvk.Gvk{
Kind: "Namespace", Kind: "Namespace",
@@ -54,7 +54,7 @@ var skipNamespacePathConfigs = []transformerconfig.PathConfig{
var _ Transformer = &namespaceTransformer{} var _ Transformer = &namespaceTransformer{}
// NewNamespaceTransformer construct a namespaceTransformer. // NewNamespaceTransformer construct a namespaceTransformer.
func NewNamespaceTransformer(ns string, cf []transformerconfig.PathConfig) Transformer { func NewNamespaceTransformer(ns string, cf []config.PathConfig) Transformer {
if len(ns) == 0 { if len(ns) == 0 {
return NewNoOpTransformer() return NewNoOpTransformer()
} }

View File

@@ -23,32 +23,32 @@ import (
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
// namePrefixTransformer contains the prefix and the path config for each field that // namePrefixTransformer contains the prefix and the path config for each field that
// the name prefix will be applied. // the name prefix will be applied.
type namePrefixTransformer struct { type namePrefixTransformer struct {
prefix string prefix string
pathConfigs []transformerconfig.PathConfig pathConfigs []config.PathConfig
skipPathConfigs []transformerconfig.PathConfig skipPathConfigs []config.PathConfig
} }
var _ Transformer = &namePrefixTransformer{} var _ Transformer = &namePrefixTransformer{}
var skipNamePrefixPathConfigs = []transformerconfig.PathConfig{ var skipNamePrefixPathConfigs = []config.PathConfig{
{ {
Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"}, Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"},
}, },
} }
// deprecateNamePrefixPathConfig will be moved into skipNamePrefixPathConfigs in next release // deprecateNamePrefixPathConfig will be moved into skipNamePrefixPathConfigs in next release
var deprecateNamePrefixPathConfig = transformerconfig.PathConfig{ var deprecateNamePrefixPathConfig = config.PathConfig{
Gvk: gvk.Gvk{Kind: "Namespace"}, Gvk: gvk.Gvk{Kind: "Namespace"},
} }
// NewNamePrefixTransformer construct a namePrefixTransformer. // NewNamePrefixTransformer construct a namePrefixTransformer.
func NewNamePrefixTransformer(np string, pc []transformerconfig.PathConfig) (Transformer, error) { func NewNamePrefixTransformer(np string, pc []config.PathConfig) (Transformer, error) {
if len(np) == 0 { if len(np) == 0 {
return NewNoOpTransformer(), nil return NewNoOpTransformer(), nil
} }

View File

@@ -5,16 +5,16 @@ import (
"sigs.k8s.io/kustomize/pkg/expansion" "sigs.k8s.io/kustomize/pkg/expansion"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformerconfig" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
type refvarTransformer struct { type refvarTransformer struct {
pathConfigs []transformerconfig.PathConfig pathConfigs []config.PathConfig
vars map[string]string vars map[string]string
} }
// NewRefVarTransformer returns a Trasformer that replaces $(VAR) style variables with values. // NewRefVarTransformer returns a Trasformer that replaces $(VAR) style variables with values.
func NewRefVarTransformer(vars map[string]string, p []transformerconfig.PathConfig) Transformer { func NewRefVarTransformer(vars map[string]string, p []config.PathConfig) Transformer {
return &refvarTransformer{ return &refvarTransformer{
vars: vars, vars: vars,
pathConfigs: p, pathConfigs: p,