Skip to content

Commit

Permalink
fix(runtime): invert reason and msg on k8s events
Browse files Browse the repository at this point in the history
  • Loading branch information
hspedro committed Sep 2, 2024
1 parent 1788e34 commit 2913a14
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/adapters/runtime/kubernetes/game_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (
utilrand "k8s.io/apimachinery/pkg/util/rand"
)

const (
GameRoomDeletionEventID = "GameRoomDeleted"
)

func (k *kubernetes) CreateGameRoomInstance(ctx context.Context, scheduler *entities.Scheduler, gameRoomName string, gameRoomSpec game_room.Spec) (*game_room.Instance, error) {
pod, err := convertGameRoomSpec(*scheduler, gameRoomName, gameRoomSpec)
if err != nil {
Expand All @@ -61,7 +65,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.createKubernetesEvent(ctx, gameRoomInstance.SchedulerID, gameRoomInstance.ID, reason, "GameRoomDeleted")
_ = k.createKubernetesEvent(ctx, gameRoomInstance.SchedulerID, gameRoomInstance.ID, GameRoomDeletionEventID, reason)

err := k.clientSet.CoreV1().Pods(gameRoomInstance.SchedulerID).Delete(ctx, gameRoomInstance.ID, metav1.DeleteOptions{})
if err != nil {
Expand All @@ -88,7 +92,7 @@ func (k *kubernetes) CreateGameRoomName(ctx context.Context, scheduler entities.
return fmt.Sprintf("%s-%s", base, utilrand.String(randomLength)), nil
}

func (k *kubernetes) createKubernetesEvent(ctx context.Context, schedulerID string, gameRoomID string, reason string, message string) error {
func (k *kubernetes) createKubernetesEvent(ctx context.Context, schedulerID, gameRoomID, eventID, reason string) error {
pod, err := k.clientSet.CoreV1().Pods(schedulerID).Get(ctx, gameRoomID, metav1.GetOptions{})
if err != nil {
if kerrors.IsNotFound(err) {
Expand All @@ -98,7 +102,7 @@ func (k *kubernetes) createKubernetesEvent(ctx context.Context, schedulerID stri
return errors.NewErrUnexpected("error getting game room instance: %s", err)
}

k.eventRecorder.Event(pod, corev1.EventTypeNormal, reason, message)
k.eventRecorder.Event(pod, corev1.EventTypeNormal, eventID, reason)

return nil
}

0 comments on commit 2913a14

Please sign in to comment.