diff --git a/pkg/transformers/prefixsuffixname.go b/pkg/transformers/prefixsuffix.go similarity index 62% rename from pkg/transformers/prefixsuffixname.go rename to pkg/transformers/prefixsuffix.go index d74da3c89..f020b0f32 100644 --- a/pkg/transformers/prefixsuffixname.go +++ b/pkg/transformers/prefixsuffix.go @@ -1,18 +1,5 @@ -/* -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. -*/ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 package transformers @@ -25,25 +12,26 @@ import ( "sigs.k8s.io/kustomize/pkg/transformers/config" ) -// namePrefixSuffixTransformer contains the prefix, suffix, and the FieldSpecs -// for each field needing a name prefix and suffix. -type namePrefixSuffixTransformer struct { +// prefixSuffixTransformer contains the prefix, suffix, and the FieldSpecs +// for each field needing a prefix and suffix. +type prefixSuffixTransformer struct { prefix string suffix string fieldSpecsToUse []config.FieldSpec fieldSpecsToSkip []config.FieldSpec } -var _ Transformer = &namePrefixSuffixTransformer{} +var _ Transformer = &prefixSuffixTransformer{} +// Not placed in a file yet due to lack of demand. var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{ { Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"}, }, } -// NewNamePrefixSuffixTransformer makes a namePrefixSuffixTransformer. -func NewNamePrefixSuffixTransformer( +// NewPrefixSuffixTransformer makes a prefixSuffixTransformer. +func NewPrefixSuffixTransformer( np, ns string, fieldSpecs []config.FieldSpec) (Transformer, error) { if len(np) == 0 && len(ns) == 0 { return NewNoOpTransformer(), nil @@ -51,17 +39,17 @@ func NewNamePrefixSuffixTransformer( if fieldSpecs == nil { return nil, errors.New("fieldSpecs is not expected to be nil") } - return &namePrefixSuffixTransformer{ + return &prefixSuffixTransformer{ prefix: np, suffix: ns, fieldSpecsToUse: fieldSpecs, fieldSpecsToSkip: prefixSuffixFieldSpecsToSkip}, nil } -// Transform prepends the name prefix and appends the name suffix. +// Transform prepends the prefix and appends the suffix to the field contents. // TODO: this transformer breaks internal // ordering and depends on Id hackery. Rewrite completely. -func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error { +func (o *prefixSuffixTransformer) Transform(m resmap.ResMap) error { // Fill map "mf" with entries subject to name modification, and // delete these entries from "m", so that for now m retains only // the entries whose names will not be modified. @@ -101,7 +89,7 @@ func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error { return nil } -func (o *namePrefixSuffixTransformer) addPrefixSuffix( +func (o *prefixSuffixTransformer) addPrefixSuffix( in interface{}) (interface{}, error) { s, ok := in.(string) if !ok { diff --git a/pkg/transformers/prefixsuffixname_test.go b/pkg/transformers/prefixsuffix_test.go similarity index 77% rename from pkg/transformers/prefixsuffixname_test.go rename to pkg/transformers/prefixsuffix_test.go index 64af91577..7f723ecd0 100644 --- a/pkg/transformers/prefixsuffixname_test.go +++ b/pkg/transformers/prefixsuffix_test.go @@ -1,18 +1,5 @@ -/* -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. -*/ +// Copyright 2019 The Kubernetes Authors. +// SPDX-License-Identifier: Apache-2.0 package transformers @@ -81,7 +68,7 @@ func TestPrefixSuffixNameRun(t *testing.T) { }), }) - npst, err := NewNamePrefixSuffixTransformer( + npst, err := NewPrefixSuffixTransformer( "someprefix-", "-somesuffix", defaultTransformerConfig.NamePrefix) if err != nil { t.Fatalf("unexpected error: %v", err) diff --git a/plugin/builtin/NameTransformer.go b/plugin/builtin/NameTransformer.go index b53859615..c0ab1194e 100644 --- a/plugin/builtin/NameTransformer.go +++ b/plugin/builtin/NameTransformer.go @@ -29,7 +29,7 @@ func (p *NameTransformerPlugin) Config( } func (p *NameTransformerPlugin) Transform(m resmap.ResMap) error { - t, err := transformers.NewNamePrefixSuffixTransformer( + t, err := transformers.NewPrefixSuffixTransformer( p.Prefix, p.Suffix, p.FieldSpecs, diff --git a/plugin/builtin/nametransformer/NameTransformer.go b/plugin/builtin/nametransformer/NameTransformer.go index e5f3f1fc7..577498876 100644 --- a/plugin/builtin/nametransformer/NameTransformer.go +++ b/plugin/builtin/nametransformer/NameTransformer.go @@ -12,7 +12,7 @@ import ( "sigs.k8s.io/yaml" ) -// Add the given prefix and suffix to the resource name. +// Add the given prefix and suffix to the field. type plugin struct { Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"` Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"` @@ -30,7 +30,7 @@ func (p *plugin) Config( } func (p *plugin) Transform(m resmap.ResMap) error { - t, err := transformers.NewNamePrefixSuffixTransformer( + t, err := transformers.NewPrefixSuffixTransformer( p.Prefix, p.Suffix, p.FieldSpecs, diff --git a/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer.go b/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer.go index b974a04a3..9f29b08b2 100644 --- a/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer.go +++ b/plugin/someteam.example.com/v1/dateprefixer/DatePrefixer.go @@ -28,7 +28,7 @@ func getDate() string { } func (p *plugin) Transform(m resmap.ResMap) error { - tr, err := transformers.NewNamePrefixSuffixTransformer( + tr, err := transformers.NewPrefixSuffixTransformer( getDate()+"-", "", config.MakeDefaultConfig().NamePrefix) if err != nil { diff --git a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go index f7a4ad268..879ab9d71 100644 --- a/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go +++ b/plugin/someteam.example.com/v1/stringprefixer/StringPrefixer.go @@ -27,7 +27,7 @@ func (p *plugin) Config( } func (p *plugin) Transform(m resmap.ResMap) error { - tr, err := transformers.NewNamePrefixSuffixTransformer( + tr, err := transformers.NewPrefixSuffixTransformer( p.Metadata.Name+"-", "", config.MakeDefaultConfig().NamePrefix) if err != nil {