Skip to content

Commit

Permalink
Fixes bug when validating ResourceGroup after storing zero inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Nov 12, 2020
1 parent d59063c commit a37430d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/live/inventoryrg.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ func (icm *InventoryResourceGroup) GetObject() (*unstructured.Unstructured, erro
}
// Create the inventory object by copying the template.
invCopy := icm.inv.DeepCopy()
// Adds the inventory ObjMetadata to the ResourceGroup "spec.resources" section
klog.V(4).Infof("storing inventory resources")
err := unstructured.SetNestedSlice(invCopy.UnstructuredContent(),
objs, "spec", "resources")
if err != nil {
return nil, err
// Adds or clears the inventory ObjMetadata to the ResourceGroup "spec.resources" section
if len(objs) == 0 {
klog.V(4).Infoln("clearing inventory resources")
unstructured.RemoveNestedField(invCopy.UnstructuredContent(),
"spec", "resources")
} else {
klog.V(4).Infof("storing inventory (%d) resources", len(objs))
err := unstructured.SetNestedSlice(invCopy.UnstructuredContent(),
objs, "spec", "resources")
if err != nil {
return nil, err
}
}
return invCopy, nil
}
Expand Down

0 comments on commit a37430d

Please sign in to comment.