Skip to content

Commit 164216c

Browse files
committed
Check multiple GVKs in AddObjectsToTemplate
1 parent 5dd6cae commit 164216c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/template/api/helpers.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ func AddObjectsToTemplate(template *Template, objects []runtime.Object, targetVe
1717
return errors.New("cannot add a nil object to a template")
1818
}
1919

20-
kind, _, err := kapi.Scheme.ObjectKind(obj)
20+
// We currently add legacy types first to the scheme, followed by the types in the new api
21+
// groups. We have to check all ObjectKinds and not just use the first one returned by
22+
// ObjectKind().
23+
gvks, _, err := kapi.Scheme.ObjectKinds(obj)
2124
if err != nil {
2225
return err
2326
}
2427

2528
var targetVersion *unversioned.GroupVersion
29+
outerLoop:
2630
for j := range targetVersions {
2731
possibleVersion := targetVersions[j]
28-
if kind.Group == possibleVersion.Group {
29-
targetVersion = &possibleVersion
30-
break
32+
for _, kind := range gvks {
33+
if kind.Group == possibleVersion.Group {
34+
targetVersion = &possibleVersion
35+
break outerLoop
36+
}
3137
}
3238
}
3339
if targetVersion == nil {
34-
return fmt.Errorf("no target version found for object[%d], kind %v in %v", i, kind, targetVersions)
40+
return fmt.Errorf("no target version found for object[%d], gvks %v in %v", i, gvks, targetVersions)
3541
}
3642

3743
wrappedObject := runtime.NewEncodable(kapi.Codecs.LegacyCodec(*targetVersion), obj)

0 commit comments

Comments
 (0)