mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Rename the prefix/suffix transformer.
This commit is contained in:
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 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 transformers
|
||||||
|
|
||||||
@@ -25,25 +12,26 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// namePrefixSuffixTransformer contains the prefix, suffix, and the FieldSpecs
|
// prefixSuffixTransformer contains the prefix, suffix, and the FieldSpecs
|
||||||
// for each field needing a name prefix and suffix.
|
// for each field needing a prefix and suffix.
|
||||||
type namePrefixSuffixTransformer struct {
|
type prefixSuffixTransformer struct {
|
||||||
prefix string
|
prefix string
|
||||||
suffix string
|
suffix string
|
||||||
fieldSpecsToUse []config.FieldSpec
|
fieldSpecsToUse []config.FieldSpec
|
||||||
fieldSpecsToSkip []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{
|
var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{
|
||||||
{
|
{
|
||||||
Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"},
|
Gvk: gvk.Gvk{Kind: "CustomResourceDefinition"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNamePrefixSuffixTransformer makes a namePrefixSuffixTransformer.
|
// NewPrefixSuffixTransformer makes a prefixSuffixTransformer.
|
||||||
func NewNamePrefixSuffixTransformer(
|
func NewPrefixSuffixTransformer(
|
||||||
np, ns string, fieldSpecs []config.FieldSpec) (Transformer, error) {
|
np, ns string, fieldSpecs []config.FieldSpec) (Transformer, error) {
|
||||||
if len(np) == 0 && len(ns) == 0 {
|
if len(np) == 0 && len(ns) == 0 {
|
||||||
return NewNoOpTransformer(), nil
|
return NewNoOpTransformer(), nil
|
||||||
@@ -51,17 +39,17 @@ func NewNamePrefixSuffixTransformer(
|
|||||||
if fieldSpecs == nil {
|
if fieldSpecs == nil {
|
||||||
return nil, errors.New("fieldSpecs is not expected to be nil")
|
return nil, errors.New("fieldSpecs is not expected to be nil")
|
||||||
}
|
}
|
||||||
return &namePrefixSuffixTransformer{
|
return &prefixSuffixTransformer{
|
||||||
prefix: np,
|
prefix: np,
|
||||||
suffix: ns,
|
suffix: ns,
|
||||||
fieldSpecsToUse: fieldSpecs,
|
fieldSpecsToUse: fieldSpecs,
|
||||||
fieldSpecsToSkip: prefixSuffixFieldSpecsToSkip}, nil
|
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
|
// TODO: this transformer breaks internal
|
||||||
// ordering and depends on Id hackery. Rewrite completely.
|
// 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
|
// Fill map "mf" with entries subject to name modification, and
|
||||||
// delete these entries from "m", so that for now m retains only
|
// delete these entries from "m", so that for now m retains only
|
||||||
// the entries whose names will not be modified.
|
// the entries whose names will not be modified.
|
||||||
@@ -101,7 +89,7 @@ func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *namePrefixSuffixTransformer) addPrefixSuffix(
|
func (o *prefixSuffixTransformer) addPrefixSuffix(
|
||||||
in interface{}) (interface{}, error) {
|
in interface{}) (interface{}, error) {
|
||||||
s, ok := in.(string)
|
s, ok := in.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
Copyright 2018 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 transformers
|
||||||
|
|
||||||
@@ -81,7 +68,7 @@ func TestPrefixSuffixNameRun(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
npst, err := NewNamePrefixSuffixTransformer(
|
npst, err := NewPrefixSuffixTransformer(
|
||||||
"someprefix-", "-somesuffix", defaultTransformerConfig.NamePrefix)
|
"someprefix-", "-somesuffix", defaultTransformerConfig.NamePrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
@@ -29,7 +29,7 @@ func (p *NameTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *NameTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *NameTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
t, err := transformers.NewNamePrefixSuffixTransformer(
|
t, err := transformers.NewPrefixSuffixTransformer(
|
||||||
p.Prefix,
|
p.Prefix,
|
||||||
p.Suffix,
|
p.Suffix,
|
||||||
p.FieldSpecs,
|
p.FieldSpecs,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"sigs.k8s.io/yaml"
|
"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 {
|
type plugin struct {
|
||||||
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
|
||||||
Suffix string `json:"suffix,omitempty" yaml:"suffix,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 {
|
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||||
t, err := transformers.NewNamePrefixSuffixTransformer(
|
t, err := transformers.NewPrefixSuffixTransformer(
|
||||||
p.Prefix,
|
p.Prefix,
|
||||||
p.Suffix,
|
p.Suffix,
|
||||||
p.FieldSpecs,
|
p.FieldSpecs,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func getDate() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||||
tr, err := transformers.NewNamePrefixSuffixTransformer(
|
tr, err := transformers.NewPrefixSuffixTransformer(
|
||||||
getDate()+"-", "",
|
getDate()+"-", "",
|
||||||
config.MakeDefaultConfig().NamePrefix)
|
config.MakeDefaultConfig().NamePrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (p *plugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||||
tr, err := transformers.NewNamePrefixSuffixTransformer(
|
tr, err := transformers.NewPrefixSuffixTransformer(
|
||||||
p.Metadata.Name+"-", "",
|
p.Metadata.Name+"-", "",
|
||||||
config.MakeDefaultConfig().NamePrefix)
|
config.MakeDefaultConfig().NamePrefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user