mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Fix namereference and stacked kustomization contexts (1/3)
- Update PrefixSuffixTransfomer to add empty prefix and suffix
This commit is contained in:
@@ -50,22 +50,40 @@ func (p *plugin) Config(
|
||||
}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
if len(p.Prefix) == 0 && len(p.Suffix) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Even if both the Prefix and Suffix are empty we want
|
||||
// to proceed with the transformation. This allows to add contextual
|
||||
// information to the resources (AddNamePrefix and AddNameSuffix).
|
||||
|
||||
for _, r := range m.Resources() {
|
||||
if p.shouldSkip(r.OrgId()) {
|
||||
// Don't change the actual definition
|
||||
// of a CRD.
|
||||
continue
|
||||
}
|
||||
id := r.OrgId()
|
||||
// current default configuration contains
|
||||
// only one entry: "metadata/name" with no GVK
|
||||
for _, path := range p.FieldSpecs {
|
||||
if !id.IsSelected(&path.Gvk) {
|
||||
// With the currrent default configuration,
|
||||
// because no Gvk is specified, so a wild
|
||||
// card
|
||||
continue
|
||||
}
|
||||
|
||||
if smellsLikeANameChange(&path) {
|
||||
// "metadata/name" is the only field.
|
||||
// this will add a prefix and a suffix
|
||||
// to the resource even if those are
|
||||
// empty
|
||||
r.AddNamePrefix(p.Prefix)
|
||||
r.AddNameSuffix(p.Suffix)
|
||||
}
|
||||
|
||||
// the addPrefixSuffix method will not
|
||||
// change the name if both the prefix and suffix
|
||||
// are empty.
|
||||
err := transformers.MutateField(
|
||||
r.Map(),
|
||||
path.PathSlice(),
|
||||
|
||||
Reference in New Issue
Block a user