Skip to content

Emit Kubernetes Events - #155

Open
HarshwardhanPatil07 wants to merge 7 commits into
bootc-dev:mainfrom
HarshwardhanPatil07:issue-101-k8s-events
Open

Emit Kubernetes Events#155
HarshwardhanPatil07 wants to merge 7 commits into
bootc-dev:mainfrom
HarshwardhanPatil07:issue-101-k8s-events

Conversation

@HarshwardhanPatil07

@HarshwardhanPatil07 HarshwardhanPatil07 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Pool Events:

  • ImageUpdateAvailable
  • RolloutStarted
  • RolloutCompleted
  • Warning Events when the pool enters or changes a degraded state

Node Events:

  • Staging
  • Staged
  • Rebooting
  • DrainFailed
  • DrainTakingTooLong

Node 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 --watch

closes: #101

@HarshwardhanPatil07

Copy link
Copy Markdown
Collaborator Author

PTAL @Johan-Liebert1 @ptalgulk01 @alicefr

Comment thread test/e2e/bootcnode_test.go Outdated
Comment thread internal/controller/events.go Outdated
@HarshwardhanPatil07

Copy link
Copy Markdown
Collaborator Author

@ptalgulk01 Thanks. added the changes

@HarshwardhanPatil07

Copy link
Copy Markdown
Collaborator Author

rebase

Comment thread internal/controller/events.go Outdated
Comment thread internal/controller/events.go Outdated
Comment thread internal/controller/events.go Outdated
Comment thread internal/controller/events.go Outdated
Comment thread internal/controller/events.go Outdated
@alicefr

alicefr commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

@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.

Comment thread internal/controller/events.go Outdated
// 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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add when the node becomes idle again?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
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>
@HarshwardhanPatil07

Copy link
Copy Markdown
Collaborator Author

PTAL @alicefr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit Kubernetes Events

3 participants