-
Notifications
You must be signed in to change notification settings - Fork 1.5k
installer-create: Provide user friendly error messages during failures #4800
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
rna-afk:api_bootstrap_error_message_cleanup
Mar 31, 2021
+66
−13
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,15 +111,16 @@ var ( | |
| } | ||
|
|
||
| timer.StartTimer("Bootstrap Complete") | ||
| err = waitForBootstrapComplete(ctx, config) | ||
| if err != nil { | ||
| if err := waitForBootstrapComplete(ctx, config); err != nil { | ||
| if err2 := logClusterOperatorConditions(ctx, config); err2 != nil { | ||
| logrus.Error("Attempted to gather ClusterOperator status after installation failure: ", err2) | ||
| } | ||
| if err2 := runGatherBootstrapCmd(rootOpts.dir); err2 != nil { | ||
| logrus.Error("Attempted to gather debug logs after installation failure: ", err2) | ||
| } | ||
| logrus.Fatal("Bootstrap failed to complete: ", err) | ||
| logrus.Error("Bootstrap failed to complete: ", err.Unwrap()) | ||
| logrus.Error(err.Error()) | ||
| logrus.Fatal("Bootstrap failed to complete") | ||
| } | ||
| timer.StopTimer("Bootstrap Complete") | ||
| timer.StartTimer("Bootstrap Destroy") | ||
|
|
@@ -154,6 +155,55 @@ var ( | |
| targets = []target{installConfigTarget, manifestsTarget, ignitionConfigsTarget, clusterTarget, singleNodeIgnitionConfigTarget} | ||
| ) | ||
|
|
||
| // clusterCreateError defines a custom error type that would help identify where the error occurs | ||
| // during the bootstrap phase of the installation process. This would help identify whether the error | ||
| // comes either from the Kubernetes API failure, the bootstrap failure or a general kubernetes client | ||
| // creation error. In the event of any error, this interface packages the error message and a custom | ||
| // log message that must be neatly presented to the user before termination of the project. | ||
| type clusterCreateError struct { | ||
| wrappedError error | ||
| logMessage string | ||
| } | ||
|
|
||
| // Unwrap provides the actual stored error that occured during installation. | ||
| func (ce *clusterCreateError) Unwrap() error { | ||
| return ce.wrappedError | ||
| } | ||
|
|
||
| // Error provides the actual stored error that occured during installation. | ||
| func (ce *clusterCreateError) Error() string { | ||
| return ce.logMessage | ||
| } | ||
|
|
||
| // newAPIError creates a clusterCreateError object with a default error message specific to the API failure. | ||
| func newAPIError(errorInfo error) *clusterCreateError { | ||
| return &clusterCreateError{ | ||
| wrappedError: errorInfo, | ||
| logMessage: "Failed waiting for Kubernetes API. This error usually happens when there " + | ||
| "is a problem on the bootstrap host that prevents creating a temporary control plane.", | ||
| } | ||
| } | ||
|
|
||
| // newBootstrapError creates a clusterCreateError object with a default error message specific to the | ||
| // bootstrap failure. | ||
| func newBootstrapError(errorInfo error) *clusterCreateError { | ||
| return &clusterCreateError{ | ||
| wrappedError: errorInfo, | ||
| logMessage: "Failed to wait for bootstrapping to complete. This error usually " + | ||
| "happens when there is a problem with control plane hosts that prevents " + | ||
| "the control plane operators from creating the control plane.", | ||
| } | ||
| } | ||
|
|
||
| // newClientError creates a clusterCreateError object with a default error message specific to the | ||
| // kubernetes client creation failure. | ||
| func newClientError(errorInfo error) *clusterCreateError { | ||
| return &clusterCreateError{ | ||
| wrappedError: errorInfo, | ||
| logMessage: "Failed to create a kubernetes client.", | ||
| } | ||
| } | ||
|
|
||
| func newCreateCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
|
|
@@ -264,10 +314,10 @@ func addRouterCAToClusterCA(ctx context.Context, config *rest.Config, directory | |
| return nil | ||
| } | ||
|
|
||
| func waitForBootstrapComplete(ctx context.Context, config *rest.Config) (err error) { | ||
| func waitForBootstrapComplete(ctx context.Context, config *rest.Config) *clusterCreateError { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are returning a pointer, then the receiver for the |
||
| client, err := kubernetes.NewForConfig(config) | ||
| if err != nil { | ||
| return errors.Wrap(err, "creating a Kubernetes client") | ||
| return newClientError(errors.Wrap(err, "creating a Kubernetes client")) | ||
| } | ||
|
|
||
| discovery := client.Discovery() | ||
|
|
@@ -309,9 +359,9 @@ func waitForBootstrapComplete(ctx context.Context, config *rest.Config) (err err | |
| err = apiContext.Err() | ||
| if err != nil && err != context.Canceled { | ||
| if lastErr != nil { | ||
| return errors.Wrap(lastErr, "failed waiting for Kubernetes API") | ||
| return newAPIError(lastErr) | ||
| } | ||
| return errors.Wrap(err, "waiting for Kubernetes API") | ||
| return newAPIError(err) | ||
| } | ||
|
|
||
| return waitForBootstrapConfigMap(ctx, client) | ||
|
|
@@ -320,7 +370,7 @@ func waitForBootstrapComplete(ctx context.Context, config *rest.Config) (err err | |
| // waitForBootstrapConfigMap watches the configmaps in the kube-system namespace | ||
| // and waits for the bootstrap configmap to report that bootstrapping has | ||
| // completed. | ||
| func waitForBootstrapConfigMap(ctx context.Context, client *kubernetes.Clientset) error { | ||
| func waitForBootstrapConfigMap(ctx context.Context, client *kubernetes.Clientset) *clusterCreateError { | ||
| timeout := 30 * time.Minute | ||
| logrus.Infof("Waiting up to %v for bootstrapping to complete...", timeout) | ||
|
|
||
|
|
@@ -352,8 +402,10 @@ func waitForBootstrapConfigMap(ctx context.Context, client *kubernetes.Clientset | |
| return status == "complete", nil | ||
| }, | ||
| ) | ||
|
|
||
| return errors.Wrap(err, "failed to wait for bootstrapping to complete") | ||
| if err != nil { | ||
| return newBootstrapError(err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // waitForInitializedCluster watches the ClusterVersion waiting for confirmation | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define the
Errorfunction, too, so thatclusterCreateErrorimplementserror.