Skip to content

Commit

Permalink
recording events for sleepcycles and runners
Browse files Browse the repository at this point in the history
  • Loading branch information
akyriako committed May 28, 2024
1 parent d802680 commit 48f13d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions controllers/sleepcycle_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (r *SleepCycleReconciler) generateToken() (string, error) {

func (r *SleepCycleReconciler) recordEvent(sleepCycle *corev1alpha1.SleepCycle, message string, isError bool) {
eventType := corev1.EventTypeNormal
reason := "SleepCycleOpSuccess"
reason := "SuccessfulSleepCycleReconcile"

if isError {
eventType = corev1.EventTypeWarning
reason = "SleepCycleOpFailure"
reason = "FailedSleepCycleReconcile"
}

r.Recorder.Event(sleepCycle, eventType, reason, strings.ToLower(message))
Expand Down
10 changes: 6 additions & 4 deletions runners/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"strconv"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -77,14 +78,14 @@ func main() {
clientSet = cs

scheme := runtime.NewScheme()
_ = corev1.AddToScheme(scheme)
_ = batchv1.AddToScheme(scheme)

eventBroadcaster := record.NewBroadcaster()
defer eventBroadcaster.Shutdown()

eventBroadcaster.StartStructuredLogging(4)
eventBroadcaster.StartRecordingToSink(&typedv1core.EventSinkImpl{Interface: clientSet.CoreV1().Events("")})
eventRecorder = eventBroadcaster.NewRecorder(scheme, corev1.EventSource{})
eventRecorder = eventBroadcaster.NewRecorder(scheme, corev1.EventSource{Component: "rekuberate-io/sleepcycles-runner"})

cronjob, err := clientSet.BatchV1().CronJobs(ns).Get(ctx, cj, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -312,12 +313,13 @@ func scaleHorizontalPodAutoscalers(ctx context.Context, namespace string, cronjo

func recordEvent(cronjob *batchv1.CronJob, message string, isError bool) {
eventType := corev1.EventTypeNormal
reason := "SleepCycleOpSuccess"
reason := "SuccessfulSleepCycleScale"

if isError {
eventType = corev1.EventTypeWarning
reason = "SleepCycleOpFailure"
reason = "FailedSleepCycleScale"
}

eventRecorder.Event(cronjob, eventType, reason, strings.ToLower(message))
time.Sleep(2 * time.Second)
}

0 comments on commit 48f13d6

Please sign in to comment.