Skip to content

Commit

Permalink
autopilot: add 'configured' field to autopilot status response
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl authored and peterjan committed Aug 11, 2023
1 parent b3be49f commit a760a08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type (
// AutopilotStatusResponse is the response type for the /autopilot/status
// endpoint.
AutopilotStatusResponse struct {
Configured bool `json:"configured"`
Migrating bool `json:"migrating"`
MigratingLastStart ParamTime `json:"migratingLastStart"`
Scanning bool `json:"scanning"`
Expand Down
8 changes: 7 additions & 1 deletion autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (ap *Autopilot) blockUntilConfigured(interrupt <-chan time.Time) bool {
for {
// try and fetch the config
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
_, err := ap.bus.Autopilot(ctx, api.DefaultAutopilotID)
_, err := ap.bus.Autopilot(ctx, ap.id)
cancel()

// if the config was not found, or we were unable to fetch it, keep blocking
Expand Down Expand Up @@ -584,7 +584,13 @@ func (ap *Autopilot) hostHandlerGET(jc jape.Context) {
func (ap *Autopilot) statusHandlerGET(jc jape.Context) {
migrating, mLastStart := ap.m.Status()
scanning, sLastStart := ap.s.Status()
_, err := ap.bus.Autopilot(jc.Request.Context(), ap.id)
if err != nil && !strings.Contains(err.Error(), api.ErrAutopilotNotFound.Error()) {
jc.Error(err, http.StatusInternalServerError)
return
}
jc.Encode(api.AutopilotStatusResponse{
Configured: err == nil,
Migrating: migrating,
MigratingLastStart: api.ParamTime(mLastStart),
Scanning: scanning,
Expand Down
3 changes: 3 additions & 0 deletions internal/testing/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ func TestNewTestCluster(t *testing.T) {
if status.UptimeMS == 0 {
t.Fatal("uptime should be set")
}
if !status.Configured {
t.Fatal("autopilot should be configured")
}
}

// TestObjectEntries is an integration test that verifies objects are uploaded,
Expand Down

0 comments on commit a760a08

Please sign in to comment.