mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Reduce indirection.
This commit is contained in:
@@ -49,11 +49,9 @@ func NewNameReferenceTransformer(pc []referencePathConfig) (Transformer, error)
|
||||
// The old name is in the key in the map and the new name is in the object
|
||||
// associated with the key. e.g. if <k, v> is one of the key-value pair in the map,
|
||||
// then the old name is k.Name and the new name is v.GetName()
|
||||
func (o *nameReferenceTransformer) Transform(
|
||||
m resmap.ResMap) error {
|
||||
func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
||||
for id := range m {
|
||||
obj := m[id].Unstruct()
|
||||
objMap := obj.UnstructuredContent()
|
||||
objMap := m[id].UnstructuredContent()
|
||||
for _, referencePathConfig := range o.pathConfigs {
|
||||
for _, path := range referencePathConfig.pathConfigs {
|
||||
if !selectByGVK(id.Gvk(), path.GroupVersionKind) {
|
||||
@@ -71,21 +69,19 @@ func (o *nameReferenceTransformer) Transform(
|
||||
}
|
||||
|
||||
func (o *nameReferenceTransformer) updateNameReference(
|
||||
GVK schema.GroupVersionKind,
|
||||
m resmap.ResMap,
|
||||
) func(in interface{}) (interface{}, error) {
|
||||
GVK schema.GroupVersionKind, m resmap.ResMap) func(in interface{}) (interface{}, error) {
|
||||
return func(in interface{}) (interface{}, error) {
|
||||
s, ok := in.(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%#v is expectd to be %T", in, s)
|
||||
}
|
||||
|
||||
for id, obj := range m {
|
||||
for id, res := range m {
|
||||
if !selectByGVK(id.Gvk(), &GVK) {
|
||||
continue
|
||||
}
|
||||
if id.Name() == s {
|
||||
return obj.Unstruct().GetName(), nil
|
||||
return res.GetName(), nil
|
||||
}
|
||||
}
|
||||
return in, nil
|
||||
|
||||
Reference in New Issue
Block a user