added IsEmpty() method

This commit is contained in:
Natasha Sarkar
2020-09-30 12:17:14 -07:00
parent dd8edb1b01
commit 7c8c827a88
7 changed files with 16 additions and 12 deletions

View File

@@ -33,7 +33,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
return nil
}
for _, r := range m.Resources() {
if len(r.Map()) == 0 {
if r.IsEmpty() {
// Don't mutate empty objects?
continue
}

View File

@@ -94,14 +94,14 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
// Some unknown error, let it through.
return err
}
if len(target.Map()) != 0 {
if !target.IsEmpty() {
return errors.Wrapf(
err, "with unexpectedly non-empty object map of size %d",
len(target.Map()))
}
// Fall through to handle deleted object.
}
if len(target.Map()) == 0 {
if target.IsEmpty() {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means

View File

@@ -111,14 +111,14 @@ func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap, patch
// Some unknown error, let it through.
return err
}
if len(res.Map()) != 0 {
if !res.IsEmpty() {
return errors.Wrapf(
err, "with unexpectedly non-empty object map of size %d",
len(res.Map()))
}
// Fall through to handle deleted object.
}
if len(res.Map()) == 0 {
if res.IsEmpty() {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means
@@ -143,7 +143,7 @@ func (p *PatchTransformerPlugin) applySMPatch(resource, patch *resource.Resource
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
Patch: node,
}, resource)
if len(resource.Map()) != 0 {
if !resource.IsEmpty() {
resource.SetName(n)
resource.SetNamespace(ns)
}