mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Iterate over fieldspecs for name tranformations
This commit is contained in:
@@ -56,23 +56,25 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
if p.shouldSkip(r.OrgId()) {
|
||||
continue
|
||||
}
|
||||
fs, ok := p.shouldInclude(r.OrgId())
|
||||
if !ok {
|
||||
id := r.OrgId()
|
||||
for _, path := range p.FieldSpecs {
|
||||
if !id.IsSelected(&path.Gvk) {
|
||||
continue
|
||||
}
|
||||
if smellsLikeANameChange(fs) {
|
||||
if smellsLikeANameChange(&path) {
|
||||
r.AddNamePrefix(p.Prefix)
|
||||
r.AddNameSuffix(p.Suffix)
|
||||
}
|
||||
err := transformers.MutateField(
|
||||
r.Map(),
|
||||
fs.PathSlice(),
|
||||
fs.CreateIfNotPresent,
|
||||
path.PathSlice(),
|
||||
path.CreateIfNotPresent,
|
||||
p.addPrefixSuffix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -80,16 +82,6 @@ func smellsLikeANameChange(fs *config.FieldSpec) bool {
|
||||
return fs.Path == "metadata/name"
|
||||
}
|
||||
|
||||
func (p *PrefixSuffixTransformerPlugin) shouldInclude(
|
||||
id resid.ResId) (*config.FieldSpec, bool) {
|
||||
for _, path := range p.FieldSpecs {
|
||||
if id.IsSelected(&path.Gvk) {
|
||||
return &path, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (p *PrefixSuffixTransformerPlugin) shouldSkip(
|
||||
id resid.ResId) bool {
|
||||
for _, path := range prefixSuffixFieldSpecsToSkip {
|
||||
|
||||
@@ -57,23 +57,25 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
if p.shouldSkip(r.OrgId()) {
|
||||
continue
|
||||
}
|
||||
fs, ok := p.shouldInclude(r.OrgId())
|
||||
if !ok {
|
||||
id := r.OrgId()
|
||||
for _, path := range p.FieldSpecs {
|
||||
if !id.IsSelected(&path.Gvk) {
|
||||
continue
|
||||
}
|
||||
if smellsLikeANameChange(fs) {
|
||||
if smellsLikeANameChange(&path) {
|
||||
r.AddNamePrefix(p.Prefix)
|
||||
r.AddNameSuffix(p.Suffix)
|
||||
}
|
||||
err := transformers.MutateField(
|
||||
r.Map(),
|
||||
fs.PathSlice(),
|
||||
fs.CreateIfNotPresent,
|
||||
path.PathSlice(),
|
||||
path.CreateIfNotPresent,
|
||||
p.addPrefixSuffix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -81,16 +83,6 @@ func smellsLikeANameChange(fs *config.FieldSpec) bool {
|
||||
return fs.Path == "metadata/name"
|
||||
}
|
||||
|
||||
func (p *plugin) shouldInclude(
|
||||
id resid.ResId) (*config.FieldSpec, bool) {
|
||||
for _, path := range p.FieldSpecs {
|
||||
if id.IsSelected(&path.Gvk) {
|
||||
return &path, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (p *plugin) shouldSkip(
|
||||
id resid.ResId) bool {
|
||||
for _, path := range prefixSuffixFieldSpecsToSkip {
|
||||
|
||||
Reference in New Issue
Block a user