Repository navigation
Emit Kubernetes Events - #155
HarshwardhanPatil07 merged 7 commits into
Conversation
b8f0464 to
75fbea9
Compare
75fbea9 to
1fc7d50
Compare
|
@ptalgulk01 Thanks. added the changes |
1fc7d50 to
4386b07
Compare
|
rebase |
|
@HarshwardhanPatil07 can we split the commit 161e5e7 into mulitple. At least one per event type, like one for the draining stalls, one for the node events and one for the degraded nodes. |
4386b07 to
595e81d
Compare
| // truncateEventNote keeps notes within the events.k8s.io/v1 1 KiB limit and | ||
| // never splits a UTF-8 sequence. Event templates are fixed, but interpolated | ||
| // image references, condition messages, and errors are not length-bounded. | ||
| func truncateEventNote(note string) string { |
There was a problem hiding this comment.
I'm really not a big fan of truncate the string. I think instead we should use an interface and struct with well defined fields and functions that can shorten the string. Something like:
// Event note types — each knows its own max rendered length.
type PoolImageUpdateNote struct {
ImageRef string // max ~255 (OCI spec)
NewDigest string // fixed 71 (sha256:64hex)
PreviousDigest string // fixed 71
}
func (n PoolImageUpdateNote) Note() string {
return fmt.Sprintf("Image tag %s resolved to new digest %s (previously %s)",
n.ImageRef, shortDigest(n.NewDigest), shortDigest(n.PreviousDigest))
}
type PoolRolloutStartedNote struct {
TargetDigest string
}
func (n PoolRolloutStartedNote) Note() string {
return fmt.Sprintf("Rollout started toward digest %s", shortDigest(n.TargetDigest))
}
// Interface all event notes implement.
type EventNote interface {
Note() string
}
func shortDigest(d string) string {
if len(d) > 19 { // "sha256:" + 12 hex
return d[:19]
}
return d
}and then the recordEventf becomes:
func (r *BootcNodePoolReconciler) recordEvent(
regarding, related runtime.Object,
eventType, reason, action string,
note EventNote,)
{
r.Recorder.Eventf(regarding, related, eventType, reason, action, "%s", note.Note())
}| } | ||
|
|
||
| observationWithImage := observation + ":" + node.Spec.DesiredImage | ||
| switch idle.Reason { |
There was a problem hiding this comment.
Should we also add when the node becomes idle again?
There was a problem hiding this comment.
added a nodeIdleNote "Node is up to date" event emitted when a node returns to idle
The controller may update BootcNode metadata while envtest simulates a daemon status update. Both operations advance resourceVersion, making a single Get followed by Status().Update susceptible to conflicts. Use client-go RetryOnConflict so the simulated daemon refetches the latest BootcNode before retrying its status update. Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
595e81d to
0ed183a
Compare
Expose image retargeting and rollout progress through Kubernetes Events so users can follow updates without reading controller logs. Record Events only after the corresponding pool status update succeeds, and grant the recorder access to the events.k8s.io API. Bound interpolated Event notes to the API's 1 KiB limit because image references and status messages are not fixed-length values. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Surface new and changed degraded pool conditions as Warning Events. Use the condition reason and message so users can identify invalid specs, node conflicts, and halted rollouts from standard Kubernetes tooling. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Report Staging, Staged, and Rebooting observations against each BootcNode, with the owning pool as the related object. Persist the last observation in controller-owned metadata so unrelated reconciles and controller restarts do not repeatedly emit the same transition. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Report failed drains immediately and warn once when an active drain exceeds five minutes. Requeue at the next stall deadline so a blocked drain is observable even when no other watched object changes. Keep Event reporting supplemental to rollout control: drain failures continue through the existing retry path and stalled-drain bookkeeping does not drive desired state. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Exercise pool, degraded, node, and drain Event behavior with exact reason, action, relationship, and note assertions. Cover transition deduplication, annotation write failures, tag resolution, drain scheduling, and UTF-8-safe note truncation. Use envtest Event objects filtered by regarding UID so retained Events from an earlier object with the same name cannot satisfy the integration assertions. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Envtest does not exercise the deployed RBAC, Event broadcaster, daemon, or real reboot path. Extend the existing bink update and tag-resolution scenarios to assert the Events produced by a deployed operator. Filter Events by the regarding object UID and verify exact types, reasons, actions, notes, and related pool identity. Related: bootc-dev#101 Assisted-by: AI Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
0ed183a to
2279e10
Compare
|
PTAL @alicefr |
| modified.Annotations = map[string]string{} | ||
| } | ||
| modified.Annotations[bootcv1alpha1.AnnotationLastObservedState] = observation | ||
| if err := r.Patch(ctx, modified, client.MergeFrom(node)); err != nil { |
There was a problem hiding this comment.
Don't we need to check if the observation has changed before patching?
There was a problem hiding this comment.
it's already present on line 264
|
Thank you @alicefr for the review! |
Pool Events:
ImageUpdateAvailableRolloutStartedRolloutCompletedNode Events:
StagingStagedRebootingDrainFailedDrainTakingTooLongNode Events reference the BootcNode as the primary object and the owning BootcNodePool as the related object.
Testing
Completed: Manual Event verification on a bink cluster
make buildimg make deploy-bink make e2e V=1 RUN='TestUpdateReboot\|TestTagResolution'watch events in second terminal:
kubectl get events.events.k8s.io -A --watchcloses: #101