Skip to content

Commit

Permalink
debug(events): log event namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hspedro committed Sep 2, 2024
1 parent 785a118 commit 404be51
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/adapters/runtime/kubernetes/game_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"github.com/topfreegames/maestro/internal/core/entities"
"github.com/topfreegames/maestro/internal/core/entities/game_room"
"github.com/topfreegames/maestro/internal/core/ports/errors"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -64,6 +66,7 @@ func (k *kubernetes) CreateGameRoomInstance(ctx context.Context, scheduler *enti
}

func (k *kubernetes) DeleteGameRoomInstance(ctx context.Context, gameRoomInstance *game_room.Instance, reason string) error {
k.logger.Debug("deleting game room instance", zap.String("gameRoomID", gameRoomInstance.ID), zap.String("schedulerID", gameRoomInstance.SchedulerID), zap.String("reason", reason))
_ = k.createKubernetesEvent(ctx, gameRoomInstance.SchedulerID, gameRoomInstance.ID, reason, "GameRoomDeleted")

err := k.clientSet.CoreV1().Pods(gameRoomInstance.SchedulerID).Delete(ctx, gameRoomInstance.ID, metav1.DeleteOptions{})
Expand Down Expand Up @@ -101,12 +104,25 @@ func (k *kubernetes) createKubernetesEvent(ctx context.Context, schedulerID stri
return errors.NewErrUnexpected("error getting game room instance: %s", err)
}

k.logger.Debug("Getting event recorder", zap.String("pod", pod.Name), zap.String("namespace", pod.Namespace))
k.getEventRecorder(pod).Event(pod, corev1.EventTypeNormal, reason, message)

return nil
}

func (k *kubernetes) getEventRecorder(pod *corev1.Pod) record.EventRecorder {
k.logger.Debug(
"deleting game room instance",
zap.String("pod", pod.Name),
zap.String("namespace", pod.Namespace),
zap.Array("event recorders", zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error {
for namespace, recorder := range k.eventRecorders {
enc.AppendString(fmt.Sprintf("%s: %v", namespace, recorder))
}
return nil
})),
)

if recorder, ok := k.eventRecorders[pod.Namespace]; ok {
return recorder
}
Expand Down

0 comments on commit 404be51

Please sign in to comment.