Gist

Catalogue
  1. 1. 为Kube Object增加Type信息

为Kube Object增加Type信息

因为 Client-GO 返回的 TypeMeta 永远为 Null,因此需要自己添加

addTypeInformationToObjectsource_code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func addTypeInformationToObject(obj runtime.Object) error {
gvks, _, err := scheme.Scheme.ObjectKinds(obj)
if err != nil {
return fmt.Errorf("missing apiVersion or kind and cannot assign it; %w", err)
}

for _, gvk := range gvks {
if len(gvk.Kind) == 0 {
continue
}
if len(gvk.Version) == 0 || gvk.Version == runtime.APIVersionInternal {
continue
}
obj.GetObjectKind().SetGroupVersionKind(gvk)
break
}

return nil
}