Skip to content

Commit

Permalink
Merge pull request #338 from Liujingfang1/cr-crd
Browse files Browse the repository at this point in the history
Don't emit Prune event for NoMatchError
  • Loading branch information
k8s-ci-robot authored Mar 22, 2021
2 parents 70426d6 + 4b71653 commit 6e08985
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apply/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (po *PruneOptions) Prune(localInv inventory.InventoryInfo,
obj, err := po.getObject(pruneObj)
if err != nil {
// Object not found in cluster, so no need to delete it; skip to next object.
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
klog.V(5).Infof("%s/%s not found in cluster--skipping",
pruneObj.Namespace, pruneObj.Name)
continue
Expand Down
21 changes: 21 additions & 0 deletions pkg/apply/prune/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ var role = &unstructured.Unstructured{
},
}

var unknownCR = &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "cli-utils.test/v1",
"kind": "Unknown",
"metadata": map[string]interface{}{
"name": "test",
"namespace": "default",
"annotations": map[string]interface{}{
"config.k8s.io/owning-inventory": testInventoryLabel,
},
},
},
}

// Returns a inventory object with the inventory set from
// the passed "children".
func createInventoryInfo(children ...*unstructured.Unstructured) inventory.InventoryInfo {
Expand Down Expand Up @@ -231,6 +245,13 @@ func TestPrune(t *testing.T) {
finalClusterObjs: []*unstructured.Unstructured{namespace, pod},
pruneEventObjs: []*unstructured.Unstructured{pdb, namespace},
},
"unknown type doesn't emit prune failed event": {
pastObjs: []*unstructured.Unstructured{unknownCR},
currentObjs: []*unstructured.Unstructured{},
prunedObjs: []*unstructured.Unstructured{unknownCR},
finalClusterObjs: []*unstructured.Unstructured{},
pruneEventObjs: []*unstructured.Unstructured{},
},
}
for name, tc := range tests {
for i := range common.Strategies {
Expand Down

0 comments on commit 6e08985

Please sign in to comment.