-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathwaitfor.go
101 lines (87 loc) · 3.07 KB
/
waitfor.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"context"
"path/filepath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"github.com/openshift/installer/cmd/openshift-install/command"
timer "github.com/openshift/installer/pkg/metrics/timer"
)
func newWaitForCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "wait-for",
Short: "Wait for install-time events",
Long: `Wait for install-time events.
'create cluster' has a few stages that wait for cluster events. But
these waits can also be useful on their own. This subcommand exposes
them directly.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(newWaitForBootstrapCompleteCmd())
cmd.AddCommand(newWaitForInstallCompleteCmd())
return cmd
}
func newWaitForBootstrapCompleteCmd() *cobra.Command {
return &cobra.Command{
Use: "bootstrap-complete",
Short: "Wait until cluster bootstrapping has completed",
Args: cobra.ExactArgs(0),
Run: func(_ *cobra.Command, _ []string) {
timer.StartTimer(timer.TotalTimeElapsed)
ctx := context.Background()
cleanup := command.SetupFileHook(command.RootOpts.Dir)
defer cleanup()
config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(command.RootOpts.Dir, "auth", "kubeconfig"))
if err != nil {
logrus.Fatal(errors.Wrap(err, "loading kubeconfig"))
}
timer.StartTimer("Bootstrap Complete")
if err := waitForBootstrapComplete(ctx, config); err != nil {
if err2 := logClusterOperatorConditions(ctx, config); err2 != nil {
logrus.Error("Attempted to gather ClusterOperator status after wait failure: ", err2)
}
logrus.Info("Use the following commands to gather logs from the cluster")
logrus.Info("openshift-install gather bootstrap --help")
logrus.Error("Bootstrap failed to complete: ", err.Unwrap())
logrus.Error(err.Error())
logrus.Exit(exitCodeBootstrapFailed)
}
logrus.Info("It is now safe to remove the bootstrap resources")
timer.StopTimer("Bootstrap Complete")
timer.StopTimer(timer.TotalTimeElapsed)
timer.LogSummary()
},
}
}
func newWaitForInstallCompleteCmd() *cobra.Command {
return &cobra.Command{
Use: "install-complete",
Short: "Wait until the cluster is ready",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
timer.StartTimer(timer.TotalTimeElapsed)
ctx := context.Background()
cleanup := command.SetupFileHook(command.RootOpts.Dir)
defer cleanup()
config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(command.RootOpts.Dir, "auth", "kubeconfig"))
if err != nil {
logrus.Fatal(errors.Wrap(err, "loading kubeconfig"))
}
err = waitForInstallComplete(ctx, config, command.RootOpts.Dir)
if err != nil {
if err2 := logClusterOperatorConditions(ctx, config); err2 != nil {
logrus.Error("Attempted to gather ClusterOperator status after wait failure: ", err2)
}
logTroubleshootingLink()
logrus.Error(err)
logrus.Exit(exitCodeInstallFailed)
}
timer.StopTimer(timer.TotalTimeElapsed)
timer.LogSummary()
},
}
}