Reduce indirection.

This commit is contained in:
jregan
2018-06-07 21:34:54 -07:00
parent a82bd23f8f
commit a42c72b2e0
16 changed files with 221 additions and 211 deletions

View File

@@ -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