@@ -7,12 +7,14 @@ package manager
7
7
import (
8
8
"context"
9
9
"crypto/tls"
10
+ "io/ioutil"
10
11
"net/http"
11
12
"net/url"
12
13
"time"
13
14
14
15
"github.com/gitpod-io/gitpod/common-go/log"
15
16
"github.com/gitpod-io/gitpod/common-go/tracing"
17
+ "k8s.io/apimachinery/pkg/util/json"
16
18
)
17
19
18
20
// WorkspaceProbeResult marks the result of a workspace probe
@@ -38,7 +40,7 @@ type WorkspaceReadyProbe struct {
38
40
39
41
// NewWorkspaceReadyProbe creates a new workspace probe
40
42
func NewWorkspaceReadyProbe (workspaceID string , workspaceURL url.URL ) WorkspaceReadyProbe {
41
- workspaceURL .Path += "/_supervisor/v1/status/ide"
43
+ workspaceURL .Path += "/_supervisor/v1/status/ide/wait "
42
44
readyURL := workspaceURL .String ()
43
45
44
46
return WorkspaceReadyProbe {
@@ -92,14 +94,31 @@ func (p *WorkspaceReadyProbe) Run(ctx context.Context) WorkspaceProbeResult {
92
94
// we've timed out - do not log this as it would spam the logs for no good reason
93
95
continue
94
96
}
95
- resp .Body .Close ()
96
97
97
- if resp .StatusCode == http .StatusOK {
98
- break
98
+ if resp .StatusCode != http .StatusOK {
99
+ resp .Body .Close ()
100
+ log .WithField ("url" , p .readyURL ).WithField ("status" , resp .StatusCode ).Debug ("workspace did not respond to ready probe with OK status" )
101
+ time .Sleep (p .RetryDelay )
102
+ continue
99
103
}
100
104
101
- log .WithField ("url" , p .readyURL ).WithField ("status" , resp .StatusCode ).Debug ("workspace did not respond to ready probe with OK status" )
102
- time .Sleep (p .RetryDelay )
105
+ rawBody , err := ioutil .ReadAll (resp .Body )
106
+ resp .Body .Close ()
107
+ if err != nil {
108
+ log .WithField ("url" , p .readyURL ).WithField ("status" , resp .StatusCode ).WithError (err ).Debug ("ready probe failed: cannot read body" )
109
+ continue
110
+ }
111
+ var probeResult struct {
112
+ Ok bool `json:"ok"`
113
+ }
114
+ err = json .Unmarshal (rawBody , & probeResult )
115
+ if err != nil {
116
+ log .WithField ("url" , p .readyURL ).WithField ("status" , resp .StatusCode ).WithError (err ).Debug ("ready probe failed: unable to unmarshal json" )
117
+ continue
118
+ }
119
+ if probeResult .Ok {
120
+ break
121
+ }
103
122
}
104
123
105
124
// workspace is actually ready
0 commit comments