Skip to content

Commit

Permalink
Merge pull request kubev2v#133 from AvielSegev/flow-disconnected-env
Browse files Browse the repository at this point in the history
Solution for handling the disconnected environment scenario
  • Loading branch information
tupyy authored Feb 5, 2025
2 parents 6cefbe4 + 346ced6 commit 126a63b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (a *Agent) start(ctx context.Context, plannerClient client.Planner) {

// TODO refactor health checker to call it from the main goroutine
healthChecker.Start(ctx, a.healtCheckStopCh)
statusUpdater.HealthChecker = healthChecker

collector := service.NewCollector(a.config.DataDir)
collector.Collect(ctx)
Expand Down
7 changes: 6 additions & 1 deletion internal/agent/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func RegisterApi(router *chi.Mux, statusUpdater *service.StatusUpdater, configur
})
router.Get("/api/v1/status", func(w http.ResponseWriter, r *http.Request) {
status, statusInfo, _ := statusUpdater.CalculateStatus()
_ = render.Render(w, r, StatusReply{Status: string(status), StatusInfo: statusInfo})
environmentStatus := true
if statusUpdater.HealthChecker != nil && statusUpdater.HealthChecker.State() == service.HealthCheckStateConsoleUnreachable {
environmentStatus = false
}
_ = render.Render(w, r, StatusReply{Status: string(status), StatusInfo: statusInfo, Connected: fmt.Sprintf("%t", environmentStatus)})
})
router.Get("/api/v1/url", func(w http.ResponseWriter, r *http.Request) {
_ = render.Render(w, r, ServiceUIReply{URL: configuration.PlannerService.Service.UI})
Expand All @@ -56,6 +60,7 @@ func RegisterApi(router *chi.Mux, statusUpdater *service.StatusUpdater, configur

type StatusReply struct {
Status string `json:"status"`
Connected string `json:"connected"`
StatusInfo string `json:"statusInfo"`
}

Expand Down
11 changes: 6 additions & 5 deletions internal/agent/service/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ const (
)

type StatusUpdater struct {
agentID uuid.UUID
version string
config *config.Config
client client.Planner
credUrl string
agentID uuid.UUID
version string
config *config.Config
client client.Planner
credUrl string
HealthChecker *HealthChecker
}

func NewStatusUpdater(agentID uuid.UUID, version, credUrl string, config *config.Config, client client.Planner) *StatusUpdater {
Expand Down

0 comments on commit 126a63b

Please sign in to comment.