mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
apimachinery: merge Scheme.AddKnownTypes and Scheme.AddKnownTypeWithName
This commit is contained in:
parent
6d9e2afeda
commit
6050f59b7b
@ -163,22 +163,13 @@ func (s *Scheme) AddUnversionedTypes(version schema.GroupVersion, types ...Objec
|
||||
// the struct becomes the "kind" field when encoding. Version may not be empty - use the
|
||||
// APIVersionInternal constant if you have a type that does not have a formal version.
|
||||
func (s *Scheme) AddKnownTypes(gv schema.GroupVersion, types ...Object) {
|
||||
if len(gv.Version) == 0 {
|
||||
panic(fmt.Sprintf("version is required on all types: %s %v", gv, types[0]))
|
||||
}
|
||||
for _, obj := range types {
|
||||
t := reflect.TypeOf(obj)
|
||||
if t.Kind() != reflect.Ptr {
|
||||
panic("All types must be pointers to structs.")
|
||||
}
|
||||
t = t.Elem()
|
||||
if t.Kind() != reflect.Struct {
|
||||
panic("All types must be pointers to structs.")
|
||||
}
|
||||
|
||||
gvk := gv.WithKind(t.Name())
|
||||
s.gvkToType[gvk] = t
|
||||
s.typeToGVK[t] = append(s.typeToGVK[t], gvk)
|
||||
s.AddKnownTypeWithName(gv.WithKind(t.Name()), obj)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user