Skip to content

Commit

Permalink
handle destroy event
Browse files Browse the repository at this point in the history
  • Loading branch information
aajkl committed Jul 4, 2024
1 parent 718a905 commit 51b9689
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/eru/agent/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package agent

import (
"context"
"strings"
"time"

"github.com/projecteru2/yavirt/internal/eru/common"
intertypes "github.com/projecteru2/yavirt/internal/types"
"github.com/projecteru2/yavirt/internal/utils"
"google.golang.org/grpc/status"

"github.com/projecteru2/core/log"
corerpc "github.com/projecteru2/core/rpc"
)

func (m *Manager) initMonitor(ctx context.Context) (err error) {
Expand All @@ -30,6 +33,8 @@ func (m *Manager) initMonitor(ctx context.Context) (err error) {
m.handleWorkloadStart(ctx, event.ID)
case intertypes.DieOp:
m.handleWorkloadDie(ctx, event.ID)
case intertypes.DestroyOp:
m.handleWorkloadDestroy(ctx, event.ID)
}
})
case <-watcher.Done():
Expand Down Expand Up @@ -116,6 +121,22 @@ func (m *Manager) handleWorkloadDie(ctx context.Context, ID string) {
}

if err := m.store.SetWorkloadStatus(ctx, workloadStatus, m.config.GetHealthCheckStatusTTL()); err != nil {
e, ok := status.FromError(err)
// workload doesn't exist, ignore it
if ok && e.Code() == corerpc.SetWorkloadsStatus && strings.Contains(e.Message(), "entity count invalid") {
return
}

logger.Warnf(ctx, "failed to update deploy status: %s", err)
}
}

func (m *Manager) handleWorkloadDestroy(ctx context.Context, ID string) {
logger := log.WithFunc("handleWorkloadDestroy").WithField("ID", ID)
logger.Debug(ctx, "wrokload destroy")
m.wrkStatusCache.Delete(ID)
if t, ok := m.startingWorkloads.Get(ID); ok {
t.Stop(ctx)
}
m.startingWorkloads.Del(ID)
}

0 comments on commit 51b9689

Please sign in to comment.