-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathwaitfor.go
More file actions
150 lines (127 loc) · 4.64 KB
/
Copy pathwaitfor.go
File metadata and controls
150 lines (127 loc) · 4.64 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package agent
import (
"context"
"path/filepath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/rest"
"github.com/openshift/installer/cmd/openshift-install/command"
agentpkg "github.com/openshift/installer/pkg/agent"
agentasset "github.com/openshift/installer/pkg/asset/agent"
"github.com/openshift/installer/pkg/asset/agent/workflow"
assetstore "github.com/openshift/installer/pkg/asset/store"
)
// NewWaitForCmd create the commands for waiting the completion of the agent based cluster installation.
func NewWaitForCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "wait-for",
Short: "Wait for install-time events",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(newWaitForBootstrapCompleteCmd())
cmd.AddCommand(newWaitForInstallCompleteCmd())
return cmd
}
func handleBootstrapError(ctx context.Context, config *rest.Config, cluster *agentpkg.Cluster, err error) {
logrus.Debug("Printing the event list gathered from the Agent Rest API")
cluster.PrintInfraEnvRestAPIEventList()
err2 := command.LogClusterOperatorConditions(ctx, config)
if 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(errors.Wrap(err, "Bootstrap failed to complete: "))
logrus.Exit(command.ExitCodeBootstrapFailed)
}
func newWaitForBootstrapCompleteCmd() *cobra.Command {
return &cobra.Command{
Use: "bootstrap-complete",
Short: "Wait until the cluster bootstrap is complete",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
cleanup := command.SetupFileHook(command.RootOpts.Dir)
defer cleanup()
assetDir := command.RootOpts.Dir
logrus.Debugf("asset directory: %s", assetDir)
if len(assetDir) == 0 {
logrus.Fatal("No cluster installation directory found")
}
kubeconfigPath := filepath.Join(assetDir, "auth", "kubeconfig")
assetStore, err := assetstore.NewStore(assetDir)
if err != nil {
logrus.Fatal(err)
}
rendezvousIP, err := agentpkg.FindRendezvousIPFromAssetStore(assetStore)
if err != nil {
logrus.Fatal(err)
}
ctx := context.Background()
cluster, err := agentpkg.NewCluster(ctx, assetStore, rendezvousIP, kubeconfigPath, workflow.AgentWorkflowTypeInstall)
if err != nil {
logrus.Exit(command.ExitCodeBootstrapFailed)
}
if err := agentpkg.WaitForBootstrapComplete(cluster); err != nil {
handleBootstrapError(ctx, cluster.API.Kube.Config, cluster, err)
}
},
}
}
func newWaitForInstallCompleteCmd() *cobra.Command {
return &cobra.Command{
Use: "install-complete",
Short: "Wait until the cluster installation is complete",
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
cleanup := command.SetupFileHook(command.RootOpts.Dir)
defer cleanup()
assetDir := command.RootOpts.Dir
logrus.Debugf("asset directory: %s", assetDir)
if len(assetDir) == 0 {
logrus.Fatal("No cluster installation directory found")
}
kubeconfigPath := filepath.Join(assetDir, "auth", "kubeconfig")
assetStore, err := assetstore.NewStore(assetDir)
if err != nil {
logrus.Fatal(err)
}
rendezvousIP, err := agentpkg.FindRendezvousIPFromAssetStore(assetStore)
if err != nil {
logrus.Fatal(err)
}
ctx := context.Background()
cluster, err := agentpkg.NewCluster(ctx, assetStore, rendezvousIP, kubeconfigPath, workflow.AgentWorkflowTypeInstall)
if err != nil {
logrus.Exit(command.ExitCodeBootstrapFailed)
}
if err := agentpkg.WaitForBootstrapComplete(cluster); err != nil {
handleBootstrapError(ctx, cluster.API.Kube.Config, cluster, err)
}
// Load install-config to check if FIPS verification is needed
var fipsEnabled bool
if installConfigAsset, err := assetStore.Load(&agentasset.OptionalInstallConfig{}); err == nil && installConfigAsset != nil {
ic := installConfigAsset.(*agentasset.OptionalInstallConfig)
if ic.Config != nil {
fipsEnabled = ic.Config.FIPS
}
}
options := command.WaitOptions{
VerifyFIPS: fipsEnabled,
}
if err = command.WaitForInstallComplete(ctx, cluster.API.Kube.Config, options); err != nil {
logrus.Error(err)
err2 := command.LogClusterOperatorConditions(ctx, cluster.API.Kube.Config)
if err2 != nil {
logrus.Error("Attempted to gather ClusterOperator status after wait failure: ", err2)
}
command.LogTroubleshootingLink()
logrus.Error(err)
logrus.Exit(command.ExitCodeInstallFailed)
}
},
}
}