Add kubernetes events - #348
Conversation
Reviewer's GuideThis PR adds Kubernetes event emission across the registration, attestation, key provisioning, and reference value computation flows, introduces a shared event-recording helper, wires recorders into controllers and HTTP services, and adds tests and utilities to validate the new events end‑to‑end. Sequence diagram for machine registration eventssequenceDiagram
participant User
participant RegisterServer
participant KubernetesAPI
participant Recorder
participant Machine
User->>RegisterServer: GET register endpoint
RegisterServer->>KubernetesAPI: create Machine
KubernetesAPI-->>RegisterServer: created Machine
RegisterServer->>Recorder: record_event MachineRegistered
Recorder->>KubernetesAPI: publish Event for Machine
Sequence diagram for attestation key registration and approval eventssequenceDiagram
participant Client
participant KeyRegister as attestation-key-register
participant KubernetesAPI
participant Recorder
participant AKController as ak-controller
participant Machine
participant AttestationKey
Client->>KeyRegister: PUT attestation key
KeyRegister->>KubernetesAPI: create AttestationKey
KubernetesAPI-->>KeyRegister: created AttestationKey
KeyRegister->>Recorder: record_event AttestationKeyRegistered
Recorder->>KubernetesAPI: publish Event for AttestationKey
AKController->>Recorder: record_event AttestationKeyApproved
Recorder->>KubernetesAPI: publish Event for AttestationKey
AKController->>Recorder: record_event AttestationKeyApproved
Recorder->>KubernetesAPI: publish Event for Machine
Sequence diagram for key provisioning eventssequenceDiagram
participant MachineController as keygen-controller
participant KubernetesAPI
participant Trustee
participant Recorder
participant Machine
MachineController->>Trustee: generate_secret
MachineController->>Trustee: send_secret
Trustee-->>MachineController: provisioning result
alt provisioning succeeds
MachineController->>Recorder: record_event KeyProvisioned
Recorder->>KubernetesAPI: publish Event for Machine
else provisioning fails
MachineController->>Recorder: record_event KeyProvisioningFailed
Recorder->>KubernetesAPI: publish Warning Event for Machine
end
Sequence diagram for reference value computation eventssequenceDiagram
participant ImageController as rv-controller
participant KubernetesAPI
participant ComputationJob
participant Recorder
participant ApprovedImage
ImageController->>ImageController: handle_new_image
ImageController->>Recorder: record_event ComputationStarted
Recorder->>KubernetesAPI: publish Event for ApprovedImage
ComputationJob->>ImageController: job_reconcile
ImageController->>KubernetesAPI: delete completed Job
ImageController->>Recorder: record_event ComputationCompleted
Recorder->>KubernetesAPI: publish Event for ApprovedImage
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="api/v1alpha1/crds.go" line_range="36" />
<code_context>
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters;machines;approvedimages;attestationkeys,verbs=create;delete;get;list;patch;update;watch
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/finalizers;machines/finalizers;attestationkeys/finalizers;approvedimages/finalizers,verbs=update
// +kubebuilder:rbac:groups=trusted-execution-clusters.io,resources=trustedexecutionclusters/status;machines/status;approvedimages/status;attestationkeys/status,verbs=get;patch;update
+// +kubebuilder:rbac:groups=events.k8s.io,resources=events,verbs=create;patch
// TrustedExecutionClusterSpec defines the desired state of TrustedExecutionCluster
</code_context>
<issue_to_address>
**issue (bug_risk):** The event recorder publishes `events.k8s.io` Events, but the checked-in operator RBAC grants `create;patch` only for core `events` (`apiGroups: [""]`), not `events.k8s.io`. Every `record_event` call therefore receives a Kubernetes authorization error in deployed clusters, which is only logged and leaves the new events absent.
**Triggers:** When the checked-in RBAC manifests are deployed without regenerating them to add the `events.k8s.io` rule.
**Suggested fix:** Add `apiGroups: ["events.k8s.io"]` with `resources: ["events"]` and `verbs: ["create", "patch"]` to the deployed operator RBAC, and regenerate all packaged manifests.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the event logic is wrong, Kubernetes Event objects can be emitted with incorrect or overly frequent messages and remain after the code is reverted, though they are bounded and can be deleted. The added RBAC grant also changes what these workloads may write in the cluster, but it does not grant access to application data or alter the underlying provisioning decisions.
Blocking findings: api/v1alpha1/crds.go:36
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
144447f to
051366e
Compare
| } | ||
|
|
||
| pub struct ControllerContext { | ||
| pub client: Client, |
There was a problem hiding this comment.
Why not use cache(aka AkContextData) here insted of client?
There was a problem hiding this comment.
AkContextData is Holds 4 reflector Stores, these are not needed where ControllerContext is used,
It will be a waste to create them and not use them.
We could change AkContextData to extend ControllerContext as it hold 2 of the 6 fields of AkContextData, but I don't think it's worth it.
051366e to
abfe429
Compare
| } | ||
|
|
||
| pub struct ControllerContext { | ||
| pub client: Client, |
b72f86d to
e9bc4e8
Compare
|
/retest |
e9bc4e8 to
c041b7f
Compare
c041b7f to
a743c98
Compare
| wait_for_event(client, namespace, APPROVED_IMAGE_NAME, "ComputationStarted", scaled_timeout(30)).await?; | ||
| test_ctx.info("Event ComputationStarted verified"); | ||
|
|
||
| // 3x the controller error policy requeue (60s) to survive a retry |
There was a problem hiding this comment.
the assumption was that only CI networks were unstable enough to actually witness such events, where this is instead handled by timeout multipliers. did you observe this elsewhere?
There was a problem hiding this comment.
Some delays were witnessed in the integration tests.
The timeout multipliers was added to handle these isses.
There was a problem hiding this comment.
Hmm. From GHA on this PR:
2026-09-02T07:31:40Z INFO: test_attestation_events: Event ComputationStarted verified
2026-09-02T07:31:40Z INFO: test_attestation_events: Event ComputationCompleted verified
I'd rather keep this at 60 (keeping the CI multiplier) and see if it is a real problem.
On a different note, the multiplier in #330 assumes all timeouts to be at least 60 seconds so that there can be a retry with 5 minutes read timeout and a multiplier of 6. If that remains to be how we work, we could enforce that better, but just for this PR, would you mind setting all to 60?
There was a problem hiding this comment.
I will test that it works well on my testing env (which has high INTEGRATION_TEST_THREADS capabilitys and finds many testing race conditions), if it passes i will change it
There was a problem hiding this comment.
thanks for the update! with regards to my last paragraph, could we keep all timeout bases at 60 for now?
There was a problem hiding this comment.
By all "timeout bases" do you mean just all timeout numbers (before scaling) in the tests?
There was a problem hiding this comment.
Sure, Should I start with the rest of the timeouts in this PR?
There was a problem hiding this comment.
yes, all existing timeout bases are 60 or greater afaict
a743c98 to
6b17d78
Compare
c2467f9 to
67d40d4
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Jakob-Naucke, yairpod The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/test azure-integration-test |
|
@yairpod your first commit isn't signed, could you check on that? btw the Azure run that just failed had this in the Trustee log: which I haven't seen before, but is not likely to be your fault |
Adding Kubernetes events to make CoCl flows more visable for admins. Signed-off-by: Yair Podemsky <ypodemsk@redhat.com> Assisted-by: AI
Add a test for the attastation basic events. Signed-off-by: Yair Podemsky <ypodemsk@redhat.com> Assisted-by: AI
67d40d4 to
d639aa6
Compare
|
New changes are detected. LGTM label has been removed. |
Vary strange, but fixed |
f15320b
into
trusted-execution-clusters:main
Emitting kubernetes events on major registration/attestation flow points.
This will allow cluster admins to follow and debug what happens in confidential clusters.
Summary by Sourcery
Add Kubernetes event reporting throughout the confidential-cluster registration and attestation workflows to improve operational visibility and debugging.
New Features:
Enhancements:
Tests:
Chores: