New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure invalid cluster-scoped children do not block cleanup of valid namespaced children #98068
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1956,6 +1956,270 @@ func TestConflictingData(t *testing.T) { | |
}), | ||
}, | ||
}, | ||
{ | ||
// https://github.com/kubernetes/kubernetes/issues/98040 | ||
name: "cluster-scoped bad child, namespaced good child, missing parent", | ||
steps: []step{ | ||
// setup | ||
createObjectInClient("", "v1", "pods", "ns1", makeMetadataObj(pod2ns1, pod1ns1)), // good child | ||
createObjectInClient("", "v1", "nodes", "", makeMetadataObj(node1, pod1nonamespace)), // bad child | ||
|
||
// 2,3: observe bad child | ||
processEvent(makeAddEvent(node1, pod1nonamespace)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual)}, // virtual parent queued for deletion | ||
}), | ||
|
||
// 4,5: observe good child | ||
processEvent(makeAddEvent(pod2ns1, pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual), // virtual parent queued for deletion | ||
makeNode(pod2ns1, withOwners(pod1ns1)), // mismatched child queued for deletion | ||
}, | ||
}), | ||
|
||
// 6,7: process attemptToDelete of bad virtual parent coordinates | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod2ns1, withOwners(pod1ns1))}, // mismatched child queued for deletion | ||
}), | ||
|
||
// 8,9: process attemptToDelete of good child | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=pods ns=ns1 name=podname2", // get good child, returns 200 | ||
"get /v1, Resource=pods ns=ns1 name=podname1", // get missing parent, returns 404 | ||
"delete /v1, Resource=pods ns=ns1 name=podname2", // delete good child | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
absentOwnerCache: []objectReference{pod1ns1}, // missing parent cached | ||
}), | ||
|
||
// 10,11: observe deletion of good child | ||
// steady-state is bad cluster child and bad virtual parent coordinates, with no retries | ||
processEvent(makeDeleteEvent(pod2ns1, pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
absentOwnerCache: []objectReference{pod1ns1}, | ||
}), | ||
}, | ||
}, | ||
{ | ||
// https://github.com/kubernetes/kubernetes/issues/98040 | ||
name: "cluster-scoped bad child, namespaced good child, late observed parent", | ||
steps: []step{ | ||
// setup | ||
createObjectInClient("", "v1", "pods", "ns1", makeMetadataObj(pod1ns1)), // good parent | ||
createObjectInClient("", "v1", "pods", "ns1", makeMetadataObj(pod2ns1, pod1ns1)), // good child | ||
createObjectInClient("", "v1", "nodes", "", makeMetadataObj(node1, pod1nonamespace)), // bad child | ||
|
||
// 3,4: observe bad child | ||
processEvent(makeAddEvent(node1, pod1nonamespace)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual)}, // virtual parent queued for deletion | ||
}), | ||
|
||
// 5,6: observe good child | ||
processEvent(makeAddEvent(pod2ns1, pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual), // virtual parent queued for deletion | ||
makeNode(pod2ns1, withOwners(pod1ns1))}, // mismatched child queued for deletion | ||
}), | ||
|
||
// 7,8: process attemptToDelete of bad virtual parent coordinates | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod2ns1, withOwners(pod1ns1))}, // mismatched child queued for deletion | ||
}), | ||
|
||
// 9,10: process attemptToDelete of good child | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=pods ns=ns1 name=podname2", // get good child, returns 200 | ||
"get /v1, Resource=pods ns=ns1 name=podname1", // get late-observed parent, returns 200 | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
}), | ||
|
||
// 11,12: late observe good parent | ||
processEvent(makeAddEvent(pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1ns1)}, | ||
// warn about bad node reference | ||
events: []string{`Warning OwnerRefInvalidNamespace ownerRef [v1/Pod, namespace: , name: podname1, uid: poduid1] does not exist in namespace "" involvedObject{kind=Node,apiVersion=v1}`}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace))}, // queue bad cluster-scoped child for delete attempt | ||
}), | ||
|
||
// 13,14: process attemptToDelete of bad child | ||
// steady state is bad cluster-scoped child remaining with no retries, good parent and good child in graph | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=nodes name=nodename", // get bad child, returns 200 | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1ns1)}, | ||
}), | ||
}, | ||
}, | ||
{ | ||
// https://github.com/kubernetes/kubernetes/issues/98040 | ||
name: "namespaced good child, cluster-scoped bad child, missing parent", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this is like "cluster-scoped bad child, namespaced good child, missing parent" except the order the children are observed/processed is swapped. I didn't realize when first reading the test names that ordering was important. |
||
steps: []step{ | ||
// setup | ||
createObjectInClient("", "v1", "pods", "ns1", makeMetadataObj(pod2ns1, pod1ns1)), // good child | ||
createObjectInClient("", "v1", "nodes", "", makeMetadataObj(node1, pod1nonamespace)), // bad child | ||
|
||
// 2,3: observe good child | ||
processEvent(makeAddEvent(pod2ns1, pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1ns1, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1ns1, virtual)}, // virtual parent queued for deletion | ||
}), | ||
|
||
// 4,5: observe bad child | ||
processEvent(makeAddEvent(node1, pod1nonamespace)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1ns1, virtual)}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1ns1, virtual), // virtual parent queued for deletion | ||
makeNode(node1, withOwners(pod1nonamespace)), // mismatched child queued for deletion | ||
}, | ||
}), | ||
|
||
// 6,7: process attemptToDelete of good virtual parent coordinates | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=pods ns=ns1 name=podname1", // lookup of missing parent, returns 404 | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1ns1, virtual)}, | ||
pendingGraphChanges: []*event{makeVirtualDeleteEvent(pod1ns1)}, // virtual parent not found, queued virtual delete event | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), // mismatched child still queued for deletion | ||
}, | ||
}), | ||
|
||
// 8,9: process attemptToDelete of bad cluster child | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=nodes name=nodename", // lookup of existing node | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1ns1, virtual)}, | ||
pendingGraphChanges: []*event{makeVirtualDeleteEvent(pod1ns1)}, // virtual parent virtual delete event still enqueued | ||
}), | ||
|
||
// 10,11: process virtual delete event for good virtual parent coordinates | ||
processPendingGraphChanges(1), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, // missing virtual parent replaced with alternate coordinates, still virtual | ||
absentOwnerCache: []objectReference{pod1ns1}, // cached absence of missing parent | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod2ns1, withOwners(pod1ns1)), // good child of missing parent enqueued for deletion | ||
makeNode(pod1nonamespace, virtual), // new virtual parent coordinates enqueued for deletion | ||
}, | ||
}), | ||
|
||
// 12,13: process attemptToDelete of good child | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
clientActions: []string{ | ||
"get /v1, Resource=pods ns=ns1 name=podname2", // lookup of good child | ||
"delete /v1, Resource=pods ns=ns1 name=podname2", // delete of good child | ||
}, | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod2ns1, withOwners(pod1ns1)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
absentOwnerCache: []objectReference{pod1ns1}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual), // new virtual parent coordinates enqueued for deletion | ||
}, | ||
}), | ||
|
||
// 14,15: observe deletion of good child | ||
processEvent(makeDeleteEvent(pod2ns1, pod1ns1)), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
absentOwnerCache: []objectReference{pod1ns1}, | ||
pendingAttemptToDelete: []*node{ | ||
makeNode(pod1nonamespace, virtual), // new virtual parent coordinates enqueued for deletion | ||
}, | ||
}), | ||
|
||
// 16,17: process attemptToDelete of bad virtual parent coordinates | ||
// steady-state is bad cluster child and bad virtual parent coordinates, with no retries | ||
processAttemptToDelete(1), | ||
assertState(state{ | ||
graphNodes: []*node{ | ||
makeNode(node1, withOwners(pod1nonamespace)), | ||
makeNode(pod1nonamespace, virtual)}, | ||
absentOwnerCache: []objectReference{pod1ns1}, | ||
}), | ||
}, | ||
}, | ||
} | ||
|
||
alwaysStarted := make(chan struct{}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these gets informational or are they required for the test? I'm curious because we don't check the response codes.