Refactor getGvk to use document.Document methods

* GetGroup(), GetVerion() is already added as member method of document.Document
  Use that to get group, version, kind on a resource object

Change-Id: Ib75229647461cdaad832c8c1c32af5bcaa9c9c37
This commit is contained in:
Yasin, Siraj (SY495P) 2020-05-27 17:18:20 -05:00
parent 1e6c449a8c
commit dace8ba6ec

View File

@ -76,10 +76,7 @@ func NewStatusMap(client client.Interface) (*StatusMap, error) {
// GetStatusForResource iterates over all of the stored conditions for the
// resource and returns the first status whose conditions are met.
func (sm *StatusMap) GetStatusForResource(resource document.Document) (Status, error) {
gvk, err := getGVK(resource)
if err != nil {
return "", err
}
gvk := getGVK(resource)
restMapping, err := sm.restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
@ -150,20 +147,13 @@ func getGVRs(crd apiextensions.CustomResourceDefinition) []schema.GroupVersionRe
}
// getGVK constructs a schema.GroupVersionKind for a document
//
// TODO(howell): This should probably be a member method of the
// document.Document interface.
func getGVK(doc document.Document) (schema.GroupVersionKind, error) {
apiVersion, err := doc.GetString("apiVersion")
if err != nil {
return schema.GroupVersionKind{}, err
func getGVK(doc document.Document) schema.GroupVersionKind {
toSchemaGvk := schema.GroupVersionKind{
Group: doc.GetGroup(),
Version: doc.GetVersion(),
Kind: doc.GetKind(),
}
gv, err := schema.ParseGroupVersion(apiVersion)
if err != nil {
return schema.GroupVersionKind{}, err
}
return gv.WithKind(doc.GetKind()), nil
return toSchemaGvk
}
// parseStatusChecks takes a string containing a map of status names (e.g.