← Back to Pull requests

fix(controller): pass message format as the event note, not the action #3311

Closed
unknown closed this pull request without merging on Nov 25, 2026 18:33 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 13:09 UTC
Author

Purpose of this PR

Since v2.6.0 every event the SparkApplication controller records has the wrong message: the message is only the app or pod name, and executor events contain %!(EXTRA ...). This PR passes an action to each Eventf call so the message format string goes back into note, where it belongs.

Fixes #3308

Proposed changes:

  • Add an action argument ("Reconcile") to the 20 Eventf calls in controller.go: recordSparkApplicationEvent, recordDriverEvent, recordExecutorEvent, and the driver-not-found event in updateDriverState.

  • Add an action argument ("Update") to the 2 Eventf calls in event_filter.go.

  • Remove the extra app.Name argument in recordExecutorEvent, so "Executor %s ..." is filled with the executor pod name again.

  • Add table tests for the three record helpers and assert the driver-not-found event message in the existing envtest spec.
  • Change Category

  • Bugfix (non-breaking change which fixes an issue)

  • Feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that could affect existing functionality)

  • Documentation update
  • Rationale

    Root cause

    #2946 moved the controller from record.EventRecorder to events.EventRecorder. The two Eventf signatures differ:

    // k8s.io/client-go/tools/record
    Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{})
    // k8s.io/client-go/tools/events
    Eventf(regarding runtime.Object, related runtime.Object, eventtype, reason, action, note string, args ...interface{})
    

    The call sites gained the related argument (nil) but no action. The old message format string is therefore passed as action, and the first format argument (the app or pod name) becomes note. The recorder builds the message with fmt.Sprintf(note, args...), so the message is just the name, and any remaining arguments are reported as %!(EXTRA ...).

    In the same change recordExecutorEvent started passing app.Name before args...:

    // before #2946
    r.recorder.Eventf(app, corev1.EventTypeNormal, common.EventSparkExecutorPending, "Executor %s is pending", args...)
    // master
    r.recorder.Eventf(app, nil, corev1.EventTypeNormal, common.EventSparkExecutorPending, "Executor %s is pending", app.Name, args...)
    

    https://github.com/kubeflow/spark-operator/blob/5a95d6877f48a7130f57c79aab223ffef0558188/internal/controller/sparkapplication/controller.go#L1495-L1508

    Reproduction

    events.FakeRecorder formats the note the same way as the real recorder, so the new tests show the problem directly. On master:

    expected: "Normal SparkApplicationSubmitted SparkApplication spark-pi was submitted successfully"
    actual  : "Normal SparkApplicationSubmitted spark-pi"
    
    expected: "Normal SparkExecutorRunning Executor spark-pi-exec-1 is running"
    actual  : "Normal SparkExecutorRunning spark-pi%!(EXTRA string=spark-pi-exec-1)"
    
    expected: "Warning SparkExecutorFailed Executor spark-pi-exec-1 failed with ExitCode: 137, Reason: OOMKilled, Pod Message: evicted"
    actual  : "Warning SparkExecutorFailed spark-pi%!(EXTRA string=spark-pi-exec-1, int32=137, string=OOMKilled, string=evicted)"
    

    Fix

    Insert one action string at each call site and leave every message format string unchanged. action must be non-empty, machine-readable and at most 128 characters (k8s.io/api/events/v1). I used Reconcile for events recorded by the reconciler and Update for the two events recorded while the event filter handles an update event, as proposed in #3308. If you prefer other names, they are easy to change.

    Alternatives considered:

  • Going back to mgr.GetEventRecorderFor (the old API). It is deprecated in controller-runtime v0.23 and would undo #2946.

  • A wrapper such as recordEvent(app, type, reason, format, args...) that fills in the action. It adds an abstraction and a larger diff for the same result.
  • Checklist

  • I have conducted a self-review of my own code.

  • I have updated documentation accordingly. (Not needed: no docs refer to event messages.)

  • I have added tests that prove my changes are effective or that my feature works.

  • Existing unit tests pass locally with my changes.
  • Additional Notes

    Impact on existing users

    Event messages go back to the text they had before v2.6.0, for example SparkApplication spark-pi was submitted successfully instead of spark-pi. The action field changes from the raw format string to Reconcile or Update. Event types and reasons do not change. Anyone who started matching on the broken v2.6.0 messages would notice; I could not find anything in this repo that depends on the message text. No API, CRD or RBAC change (events.k8s.io is already granted).

    Testing

  • Added TestRecordSparkApplicationEvent, TestRecordDriverEvent and TestRecordExecutorEvent (controller_events_test.go, 19 cases covering every state of the three helpers). All 19 cases fail on master with output like the above, and pass with this change.

  • Extended the existing envtest spec "Should fail a SparkApplication when driver pod not found outside the grace period" to assert the recorded message. It fails on master ("...ound non-ex..." vs "...ound Driver...") and passes with this change.

  • Ran: make go-fmt → formatted, make go-vet → pass, golangci-lint run (root module) → 0 issues, make unit-test → all packages ok.
  • Not tested

  • The two event_filter.go events have no direct test. Reaching them needs the PartialRestart gate or a failing status update in the filter, and the change there is the same one-argument insertion as the others.

  • I did not check the events with kubectl describe on a live cluster or run the e2e suite (needs Kind).

  • I did not run golangci-lint on the test/e2e module, because this change does not touch it.
  • I used an AI assistant while working on this. I reviewed every change and ran the tests myself.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: nabuskey Review duration: 14723m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3311"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%