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:
@@ -49,22 +49,40 @@ func (p *PrefixSuffixTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *PrefixSuffixTransformerPlugin) 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() {
|
for _, r := range m.Resources() {
|
||||||
if p.shouldSkip(r.OrgId()) {
|
if p.shouldSkip(r.OrgId()) {
|
||||||
|
// Don't change the actual definition
|
||||||
|
// of a CRD.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
id := r.OrgId()
|
id := r.OrgId()
|
||||||
|
// current default configuration contains
|
||||||
|
// only one entry: "metadata/name" with no GVK
|
||||||
for _, path := range p.FieldSpecs {
|
for _, path := range p.FieldSpecs {
|
||||||
if !id.IsSelected(&path.Gvk) {
|
if !id.IsSelected(&path.Gvk) {
|
||||||
|
// With the currrent default configuration,
|
||||||
|
// because no Gvk is specified, so a wild
|
||||||
|
// card
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if smellsLikeANameChange(&path) {
|
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.AddNamePrefix(p.Prefix)
|
||||||
r.AddNameSuffix(p.Suffix)
|
r.AddNameSuffix(p.Suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the addPrefixSuffix method will not
|
||||||
|
// change the name if both the prefix and suffix
|
||||||
|
// are empty.
|
||||||
err := transformers.MutateField(
|
err := transformers.MutateField(
|
||||||
r.Map(),
|
r.Map(),
|
||||||
path.PathSlice(),
|
path.PathSlice(),
|
||||||
|
|||||||
@@ -50,22 +50,40 @@ func (p *plugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
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() {
|
for _, r := range m.Resources() {
|
||||||
if p.shouldSkip(r.OrgId()) {
|
if p.shouldSkip(r.OrgId()) {
|
||||||
|
// Don't change the actual definition
|
||||||
|
// of a CRD.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
id := r.OrgId()
|
id := r.OrgId()
|
||||||
|
// current default configuration contains
|
||||||
|
// only one entry: "metadata/name" with no GVK
|
||||||
for _, path := range p.FieldSpecs {
|
for _, path := range p.FieldSpecs {
|
||||||
if !id.IsSelected(&path.Gvk) {
|
if !id.IsSelected(&path.Gvk) {
|
||||||
|
// With the currrent default configuration,
|
||||||
|
// because no Gvk is specified, so a wild
|
||||||
|
// card
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if smellsLikeANameChange(&path) {
|
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.AddNamePrefix(p.Prefix)
|
||||||
r.AddNameSuffix(p.Suffix)
|
r.AddNameSuffix(p.Suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the addPrefixSuffix method will not
|
||||||
|
// change the name if both the prefix and suffix
|
||||||
|
// are empty.
|
||||||
err := transformers.MutateField(
|
err := transformers.MutateField(
|
||||||
r.Map(),
|
r.Map(),
|
||||||
path.PathSlice(),
|
path.PathSlice(),
|
||||||
|
|||||||
Reference in New Issue
Block a user