Skip to content

Commit 6e08985

Browse files
authored
Merge pull request #338 from Liujingfang1/cr-crd
Don't emit Prune event for NoMatchError
2 parents 70426d6 + 4b71653 commit 6e08985

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/apply/prune/prune.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (po *PruneOptions) Prune(localInv inventory.InventoryInfo,
130130
obj, err := po.getObject(pruneObj)
131131
if err != nil {
132132
// Object not found in cluster, so no need to delete it; skip to next object.
133-
if apierrors.IsNotFound(err) {
133+
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
134134
klog.V(5).Infof("%s/%s not found in cluster--skipping",
135135
pruneObj.Namespace, pruneObj.Name)
136136
continue

pkg/apply/prune/prune_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ var role = &unstructured.Unstructured{
138138
},
139139
}
140140

141+
var unknownCR = &unstructured.Unstructured{
142+
Object: map[string]interface{}{
143+
"apiVersion": "cli-utils.test/v1",
144+
"kind": "Unknown",
145+
"metadata": map[string]interface{}{
146+
"name": "test",
147+
"namespace": "default",
148+
"annotations": map[string]interface{}{
149+
"config.k8s.io/owning-inventory": testInventoryLabel,
150+
},
151+
},
152+
},
153+
}
154+
141155
// Returns a inventory object with the inventory set from
142156
// the passed "children".
143157
func createInventoryInfo(children ...*unstructured.Unstructured) inventory.InventoryInfo {
@@ -231,6 +245,13 @@ func TestPrune(t *testing.T) {
231245
finalClusterObjs: []*unstructured.Unstructured{namespace, pod},
232246
pruneEventObjs: []*unstructured.Unstructured{pdb, namespace},
233247
},
248+
"unknown type doesn't emit prune failed event": {
249+
pastObjs: []*unstructured.Unstructured{unknownCR},
250+
currentObjs: []*unstructured.Unstructured{},
251+
prunedObjs: []*unstructured.Unstructured{unknownCR},
252+
finalClusterObjs: []*unstructured.Unstructured{},
253+
pruneEventObjs: []*unstructured.Unstructured{},
254+
},
234255
}
235256
for name, tc := range tests {
236257
for i := range common.Strategies {

0 commit comments

Comments
 (0)