Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/openshift-install/create: Fatal Kube API wait timeouts #786

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions cmd/openshift-install/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,31 @@ var (
Short: "Create an OpenShift cluster",
// FIXME: add longer descriptions for our commands with examples for better UX.
// Long: "",
PostRunE: func(_ *cobra.Command, _ []string) error {
PostRun: func(_ *cobra.Command, _ []string) {
ctx := context.Background()

cleanup := setupFileHook(rootOpts.dir)
defer cleanup()

config, err := clientcmd.BuildConfigFromFlags("", filepath.Join(rootOpts.dir, "auth", "kubeconfig"))
if err != nil {
return errors.Wrap(err, "loading kubeconfig")
logrus.Fatal(errors.Wrap(err, "loading kubeconfig"))
}

err = destroyBootstrap(ctx, config, rootOpts.dir)
if err != nil {
return err
logrus.Fatal(err)
}

consoleURL, err := waitForConsole(ctx, config, rootOpts.dir)
if err != nil {
return err
logrus.Fatal(err)
}

return logComplete(rootOpts.dir, consoleURL)
err = logComplete(rootOpts.dir, consoleURL)
if err != nil {
logrus.Fatal(err)
}
},
},
assets: []asset.WritableAsset{&cluster.TerraformVariables{}, &kubeconfig.Admin{}, &cluster.Cluster{}},
Expand All @@ -126,22 +134,16 @@ func newCreateCmd() *cobra.Command {
}

for _, t := range targets {
t.command.RunE = runTargetCmd(t.assets...)
t.command.Run = runTargetCmd(t.assets...)
cmd.AddCommand(t.command)
}

return cmd
}

func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
cleanup, err := setupFileHook(rootOpts.dir)
if err != nil {
return errors.Wrap(err, "failed to setup logging hook")
}
defer cleanup()

assetStore, err := asset.NewStore(rootOpts.dir)
func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args []string) {
runner := func(directory string) error {
assetStore, err := asset.NewStore(directory)
if err != nil {
return errors.Wrapf(err, "failed to create asset store")
}
Expand All @@ -155,7 +157,7 @@ func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args
err = errors.Wrapf(err, "failed to fetch %s", a.Name())
}

if err2 := asset.PersistToFile(a, rootOpts.dir); err2 != nil {
if err2 := asset.PersistToFile(a, directory); err2 != nil {
err2 = errors.Wrapf(err2, "failed to write asset (%s) to disk", a.Name())
if err != nil {
logrus.Error(err2)
Expand All @@ -170,17 +172,21 @@ func runTargetCmd(targets ...asset.WritableAsset) func(cmd *cobra.Command, args
}
return nil
}

return func(cmd *cobra.Command, args []string) {
cleanup := setupFileHook(rootOpts.dir)
defer cleanup()

err := runner(rootOpts.dir)
if err != nil {
logrus.Fatal(err)
}
}
}

// FIXME: pulling the kubeconfig and metadata out of the root
// directory is a bit cludgy when we already have them in memory.
func destroyBootstrap(ctx context.Context, config *rest.Config, directory string) (err error) {
cleanup, err := setupFileHook(rootOpts.dir)
if err != nil {
return errors.Wrap(err, "failed to setup logging hook")
}
defer cleanup()

client, err := kubernetes.NewForConfig(config)
if err != nil {
return errors.Wrap(err, "creating a Kubernetes client")
Expand Down Expand Up @@ -217,6 +223,10 @@ func destroyBootstrap(ctx context.Context, config *rest.Config, directory string
}
}
}, 2*time.Second, apiContext.Done())
err = apiContext.Err()
if err != nil && err != context.Canceled {
return errors.Wrap(err, "waiting for Kubernetes API")
}

events := client.CoreV1().Events("kube-system")

Expand Down
32 changes: 20 additions & 12 deletions cmd/openshift-install/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@ func newDestroyClusterCmd() *cobra.Command {
return &cobra.Command{
Use: "cluster",
Short: "Destroy an OpenShift cluster",
RunE: runDestroyCmd,
}
}
Run: func(_ *cobra.Command, _ []string) {
cleanup := setupFileHook(rootOpts.dir)
defer cleanup()

func runDestroyCmd(cmd *cobra.Command, args []string) error {
cleanup, err := setupFileHook(rootOpts.dir)
if err != nil {
return errors.Wrap(err, "failed to setup logging hook")
err := runDestroyCmd(rootOpts.dir)
if err != nil {
logrus.Fatal(err)
}
},
}
defer cleanup()
}

destroyer, err := destroy.New(logrus.StandardLogger(), rootOpts.dir)
func runDestroyCmd(directory string) error {
destroyer, err := destroy.New(logrus.StandardLogger(), directory)
if err != nil {
return errors.Wrap(err, "Failed while preparing to destroy cluster")
}
if err := destroyer.Run(); err != nil {
return errors.Wrap(err, "Failed to destroy cluster")
}

store, err := asset.NewStore(rootOpts.dir)
store, err := asset.NewStore(directory)
if err != nil {
return errors.Wrapf(err, "failed to create asset store")
}
Expand All @@ -65,8 +67,14 @@ func newDestroyBootstrapCmd() *cobra.Command {
return &cobra.Command{
Use: "bootstrap",
Short: "Destroy the bootstrap resources",
RunE: func(cmd *cobra.Command, args []string) error {
return bootstrap.Destroy(rootOpts.dir)
Run: func(cmd *cobra.Command, args []string) {
cleanup := setupFileHook(rootOpts.dir)
defer cleanup()

err := bootstrap.Destroy(rootOpts.dir)
if err != nil {
logrus.Fatal(err)
}
},
}
}
8 changes: 4 additions & 4 deletions cmd/openshift-install/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func (h *fileHook) Fire(entry *logrus.Entry) error {
return err
}

func setupFileHook(baseDir string) (func(), error) {
func setupFileHook(baseDir string) func() {
if err := os.MkdirAll(baseDir, 0755); err != nil {
return nil, errors.Wrap(err, "failed to create base directory for logs")
logrus.Fatal(errors.Wrap(err, "failed to create base directory for logs"))
}

logfile, err := os.OpenFile(filepath.Join(baseDir, ".openshift_install.log"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
return nil, errors.Wrap(err, "failed to open log file")
logrus.Fatal(errors.Wrap(err, "failed to open log file"))
}

originalHooks := logrus.LevelHooks{}
Expand All @@ -68,5 +68,5 @@ func setupFileHook(baseDir string) (func(), error) {
return func() {
logfile.Close()
logrus.StandardLogger().ReplaceHooks(originalHooks)
}, nil
}
}