fix: surface unknown eviction conditions in draincluster - #767
fix: surface unknown eviction conditions in draincluster#767Akshita kumari (akshita317) wants to merge 5 commits into
Conversation
The draincluster command waits for each eviction to reach a terminal state but then only handled True/False Valid and Executed conditions. A missing or Unknown condition fell through and was reported as a successful drain, masking an uncertain eviction (addressing the pre-existing TODO in draincluster.go). Add safeguards so a missing or Unknown Valid or Executed condition marks the drain unsuccessful and logs that the drain could not be confirmed, instead of silently proceeding. Fixes kubefleet-dev#659 Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR tightens draincluster’s eviction-condition handling so that drains are no longer reported as successful when eviction Valid/Executed conditions are missing or Unknown, aligning behavior with the intent in Issue #659 and the existing TODO.
Changes:
- Treat missing/
UnknownValidcondition as an unsuccessful drain and surface it via logging. - Treat missing/
UnknownExecutedcondition as an unsuccessful drain and surface it via logging.
Comments suppressed due to low confidence (1)
tools/fleet/cmd/draincluster/draincluster.go:202
- The invalid-eviction special-casing is comparing
validCondition.Reasonagainstcondition.EvictionInvalid*Messageconstants, but those constants are used as the Condition.Message when the controller marks an eviction invalid (the Reason isClusterResourcePlacementEvictionInvalid). As a result, this branch won’t match and an invalid eviction can fall through to the Executed check and be reported as a successful drain. Also, whenValidisFalsefor any other message, the drain should be marked unsuccessful instead of proceeding.
if validCondition.Status == metav1.ConditionFalse {
// check to see if CRP is missing or CRP is being deleted or CRB is missing.
if validCondition.Reason == condition.EvictionInvalidMissingCRPMessage ||
validCondition.Reason == condition.EvictionInvalidDeletingCRPMessage ||
validCondition.Reason == condition.EvictionInvalidMissingCRBMessage {
Address review feedback by extracting the eviction Valid/Executed condition evaluation into a pure evaluateEviction helper, and cover the True/False/Unknown/missing combinations (including the invalid-but-drained reasons) with table-driven unit tests. No behavior change. Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
|
Thanks for the review! Good call — I've extracted the Valid/Executed evaluation into a pure Note: the failing |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
tools/fleet/cmd/draincluster/draincluster.go:245
evaluateEvictioncurrently treats any condition status other thanFalse/Unknownas success (e.g., an empty/invalidStatusvalue will be classified as executed). Since the intent is to avoid masking uncertainty, it would be safer to only treat explicitConditionTrueas success and treat any other non-False value as indeterminate.
validCondition := eviction.GetCondition(string(placementv1beta1.PlacementEvictionConditionTypeValid))
if validCondition == nil || validCondition.Status == metav1.ConditionUnknown {
return evictionResultIndeterminate
}
// An invalid eviction whose reason is a missing/deleting CRP or a missing CRB
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
tools/fleet/cmd/draincluster/draincluster.go:251
- The invalid-but-drained shortcut is matching against
validCondition.Reason, but the eviction controller sets these constants in the condition Message (Reason is a genericClusterResourcePlacementEvictionInvalidReason). As written, real evictions that are invalid due to missing/deleting CRP or missing CRB will be misclassified and could be treated as indeterminate/failed instead of the intended success path.
// An invalid eviction whose reason is a missing/deleting CRP or a missing CRB
// still means the cluster is drained.
if validCondition.Status == metav1.ConditionFalse &&
(validCondition.Reason == condition.EvictionInvalidMissingCRPMessage ||
validCondition.Reason == condition.EvictionInvalidDeletingCRPMessage ||
validCondition.Reason == condition.EvictionInvalidMissingCRBMessage) {
return evictionResultInvalidButDrained
Address review feedback: - add an explicit evictionResultExecuted case and a default to the drain switch, so an unexpected classification is treated as unconfirmed rather than a successful drain - evaluateEviction now treats only an explicit True/False status as definitive; Unknown, empty, or unexpected statuses map to indeterminate - add a test case for an empty/invalid Executed status Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
|
Thanks — both good catches, addressed in the latest push:
On the red |
markEvictionInvalid sets Reason to the generic ClusterResourcePlacementEvictionInvalidReason and stores the specific detail in Message, so comparing Reason against the EvictionInvalid*Message constants never matched and the invalid-but-drained branch was unreachable. Compare against Message instead, and log Message rather than the generic Reason when reporting an invalid eviction that still drained. Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Following up on this one, as it has been sitting on a red check since early August. The failing The branch is now ~27 commits behind |
|
Yetkin Timocin (@ytimocin) as raiser of original issue can you please review. Thanks. |
Description of your changes
Fixes #659.
The
drainclustercommand waits for each eviction to reach a terminal state and then inspects its conditions, but it only handled theTrue/Falsecases of theValidandExecutedconditions. A missing orUnknowncondition fell through:UnknownExecutedcondition was neithernilnorFalse, so the loop treated the eviction as successfully executed and reported the drain as complete;UnknownValidcondition was likewise not surfaced.This masked uncertain evictions as successful drains. This change implements the pre-existing
// TODO: add safeguards to check if eviction conditions are set to unknown.Now a missing or
UnknownValidorExecutedcondition marks the drain unsuccessful and logs that the drain could not be confirmed, instead of silently proceeding. The existingTrue/Falsehandling is unchanged.I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
go build ./tools/fleet/...,go vet, and the existinggo test ./tools/fleet/cmd/draincluster/...all pass.Note on tests: the existing suite covers the drain helper functions (
fetchClusterResourcePlacementNamesToEvict,cordon, etc.), but not the main drain loop, because it creates an eviction and waits for it to reach a terminal state — which the fake client cannot drive without a refactor. If you'd like, I'm happy to extract the eviction-condition evaluation into a small pure helper in a follow-up so this safeguard (and the surrounding True/False handling) can be unit-tested directly.Special notes for your reviewer
Behavior change is limited to previously-unhandled missing/
Unknownconditions;True/Falsepaths are untouched.