mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
added IsEmpty() method
This commit is contained in:
@@ -33,7 +33,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
if len(r.Map()) == 0 {
|
if r.IsEmpty() {
|
||||||
// Don't mutate empty objects?
|
// Don't mutate empty objects?
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,14 +94,14 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
|
|||||||
// Some unknown error, let it through.
|
// Some unknown error, let it through.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(target.Map()) != 0 {
|
if !target.IsEmpty() {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err, "with unexpectedly non-empty object map of size %d",
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
len(target.Map()))
|
len(target.Map()))
|
||||||
}
|
}
|
||||||
// Fall through to handle deleted object.
|
// 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 means all fields have been removed from the object.
|
||||||
// This can happen if a patch required deletion of the
|
// This can happen if a patch required deletion of the
|
||||||
// entire resource (not just a part of it). This means
|
// entire resource (not just a part of it). This means
|
||||||
|
|||||||
@@ -111,14 +111,14 @@ func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap, patch
|
|||||||
// Some unknown error, let it through.
|
// Some unknown error, let it through.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(res.Map()) != 0 {
|
if !res.IsEmpty() {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err, "with unexpectedly non-empty object map of size %d",
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
len(res.Map()))
|
len(res.Map()))
|
||||||
}
|
}
|
||||||
// Fall through to handle deleted object.
|
// 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 means all fields have been removed from the object.
|
||||||
// This can happen if a patch required deletion of the
|
// This can happen if a patch required deletion of the
|
||||||
// entire resource (not just a part of it). This means
|
// 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{
|
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||||
Patch: node,
|
Patch: node,
|
||||||
}, resource)
|
}, resource)
|
||||||
if len(resource.Map()) != 0 {
|
if !resource.IsEmpty() {
|
||||||
resource.SetName(n)
|
resource.SetName(n)
|
||||||
resource.SetNamespace(ns)
|
resource.SetNamespace(ns)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,10 @@ func (r *Resource) GetString(p string) (string, error) {
|
|||||||
return r.kunStr.GetString(p)
|
return r.kunStr.GetString(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resource) IsEmpty() bool {
|
||||||
|
return len(r.kunStr.Map()) == 0
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Resource) Map() map[string]interface{} {
|
func (r *Resource) Map() map[string]interface{} {
|
||||||
return r.kunStr.Map()
|
return r.kunStr.Map()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
if len(r.Map()) == 0 {
|
if r.IsEmpty() {
|
||||||
// Don't mutate empty objects?
|
// Don't mutate empty objects?
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,14 +98,14 @@ func (p *plugin) Transform(m resmap.ResMap) error {
|
|||||||
// Some unknown error, let it through.
|
// Some unknown error, let it through.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(target.Map()) != 0 {
|
if !target.IsEmpty() {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err, "with unexpectedly non-empty object map of size %d",
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
len(target.Map()))
|
len(target.Map()))
|
||||||
}
|
}
|
||||||
// Fall through to handle deleted object.
|
// 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 means all fields have been removed from the object.
|
||||||
// This can happen if a patch required deletion of the
|
// This can happen if a patch required deletion of the
|
||||||
// entire resource (not just a part of it). This means
|
// entire resource (not just a part of it). This means
|
||||||
|
|||||||
@@ -115,14 +115,14 @@ func (p *plugin) transformStrategicMerge(m resmap.ResMap, patch *resource.Resour
|
|||||||
// Some unknown error, let it through.
|
// Some unknown error, let it through.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(res.Map()) != 0 {
|
if !res.IsEmpty() {
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
err, "with unexpectedly non-empty object map of size %d",
|
err, "with unexpectedly non-empty object map of size %d",
|
||||||
len(res.Map()))
|
len(res.Map()))
|
||||||
}
|
}
|
||||||
// Fall through to handle deleted object.
|
// 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 means all fields have been removed from the object.
|
||||||
// This can happen if a patch required deletion of the
|
// This can happen if a patch required deletion of the
|
||||||
// entire resource (not just a part of it). This means
|
// entire resource (not just a part of it). This means
|
||||||
@@ -147,7 +147,7 @@ func (p *plugin) applySMPatch(resource, patch *resource.Resource) error {
|
|||||||
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
||||||
Patch: node,
|
Patch: node,
|
||||||
}, resource)
|
}, resource)
|
||||||
if len(resource.Map()) != 0 {
|
if !resource.IsEmpty() {
|
||||||
resource.SetName(n)
|
resource.SetName(n)
|
||||||
resource.SetNamespace(ns)
|
resource.SetNamespace(ns)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user