-
Notifications
You must be signed in to change notification settings - Fork 90
/
scheduler.go
63 lines (50 loc) · 1.34 KB
/
scheduler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cluster
import (
"context"
"fmt"
"net/http"
"time"
"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/logger"
"k8s.io/kubernetes/cmd/kube-scheduler/app"
)
func runScheduler(ctx context.Context, dataDir string) error {
log := ctx.Value("log").(*logger.CLILogger)
log.Info("starting kubernetes scheduler")
schedulerConfigFile, err := schedulerConfigFilePath(dataDir)
if err != nil {
return errors.Wrap(err, "scheduler config file path")
}
args := []string{
fmt.Sprintf("--config=%s", schedulerConfigFile),
"--v=2",
}
command := app.NewSchedulerCommand()
command.SetArgs(args)
go func() {
// TODO @divolgin this error needs to be nadled.
logger.Infof("kubernetes scheduler exited %v", command.Execute())
}()
// watch the readyz endpoint to know when the api server has started
stopWaitingAfter := time.Now().Add(time.Minute)
for {
url := "http://localhost:11251/healthz"
client := http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return errors.Wrap(err, "failed to create http request")
}
resp, err := client.Do(req)
if err != nil {
time.Sleep(time.Second)
continue // keep trying
}
if resp.StatusCode == http.StatusOK {
return nil
}
if stopWaitingAfter.Before(time.Now()) {
return errors.New("scheduler did not start")
}
time.Sleep(time.Second)
}
}