fixed panic on patch delete for objects

This commit is contained in:
Natasha Sarkar
2021-02-18 10:47:13 -08:00
parent 4a35bfa84c
commit 6361c3b1b7
3 changed files with 58 additions and 1 deletions

View File

@@ -64,7 +64,7 @@ func (fltr Filter) filter(obj *yaml.RNode) error {
// found the field -- set its value
return fltr.SetValue(obj)
}
if obj.IsTaggedNull() {
if obj.IsTaggedNull() || obj.IsNil() {
return nil
}
switch obj.YNode().Kind {

View File

@@ -42,6 +42,14 @@ func (o *multiTransformer) transform(m resmap.ResMap) error {
return err
}
}
for _, r := range m.Resources() {
if r.IsEmpty() {
err := m.Remove(r.CurId())
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -1213,3 +1213,52 @@ spec:
name: server
`)
}
// test for #3616
func TestSmpDeleteOnResource(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- workloads.yaml
patches:
- patch: |
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: rule1
$patch: delete
`)
th.WriteF("workloads.yaml", `
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
role: alert-rules
name: rule1
spec:
groups:
- name: rabbitmq.rules
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
role: alert-rules
name: rule2
spec:
groups:
- name: rabbitmq.rules
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
role: alert-rules
name: rule2
spec:
groups:
- name: rabbitmq.rules
`)
}