output error details when minikube fails to start

pull/13920/head
Steven Powell 2022-04-07 02:48:43 +04:30
parent 007f02114d
commit f3c47136b8
2 changed files with 100 additions and 10 deletions

View File

@ -194,9 +194,14 @@ void Window::createTrayIcon()
void Window::startMinikube() void Window::startMinikube()
{ {
QStringList args = { "start", "-p", selectedCluster() }; QString text;
sendMinikubeCommand(args); QStringList args = { "start", "-p", selectedCluster(), "-o", "json" };
bool success = sendMinikubeCommand(args, text);
updateClusters(); updateClusters();
if (success) {
return;
}
outputFailedStart(text);
} }
void Window::stopMinikube() void Window::stopMinikube()
@ -415,18 +420,18 @@ bool Window::sendMinikubeCommand(QStringList cmds, QString &text)
} }
QStringList arguments; QStringList arguments;
arguments << cmds; arguments << cmds;
bool success;
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
process->start(program, arguments); process->start(program, arguments);
this->setCursor(Qt::WaitCursor); this->setCursor(Qt::WaitCursor);
success = process->waitForFinished(300 * 1000); bool timedOut = process->waitForFinished(300 * 1000);
int exitCode = process->exitCode();
bool success = !timedOut && exitCode == 0;
this->unsetCursor(); this->unsetCursor();
if (success) {
text = process->readAllStandardOutput(); text = process->readAllStandardOutput();
if (success) {
} else { } else {
qDebug() << process->readAllStandardOutput();
qDebug() << process->readAllStandardError(); qDebug() << process->readAllStandardError();
} }
delete process; delete process;
@ -459,8 +464,13 @@ void Window::askName()
int code = dialog.exec(); int code = dialog.exec();
profile = profileField.text(); profile = profileField.text();
if (code == QDialog::Accepted) { if (code == QDialog::Accepted) {
QStringList arg = { "start", "-p", profile }; QStringList arg = { "start", "-p", profile, "-o", "json" };
sendMinikubeCommand(arg); QString text;
bool success = sendMinikubeCommand(arg, text);
if (success) {
return;
}
outputFailedStart(text);
} else if (code == QDialog::Rejected) { } else if (code == QDialog::Rejected) {
askCustom(); askCustom();
} }
@ -522,8 +532,87 @@ void Window::askCustom()
"--cpus", "--cpus",
QString::number(cpus), QString::number(cpus),
"--memory", "--memory",
QString::number(memory) }; QString::number(memory),
sendMinikubeCommand(args); "-o",
"json"
};
QString text;
bool success = sendMinikubeCommand(args, text);
if (success) {
return;
}
outputFailedStart(text);
}
}
void Window::outputFailedStart(QString text) {
QStringList lines;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
lines = text.split("\n", Qt::SkipEmptyParts);
#else
lines = text.split("\n", QString::SkipEmptyParts);
#endif
for (int i = 0; i < lines.size(); i++) {
QString line = lines.at(i);
QJsonParseError error;
QJsonDocument json = QJsonDocument::fromJson(line.toUtf8(), &error);
if (json.isNull() || !json.isObject()) {
continue;
}
QJsonObject par = json.object();
QJsonObject data = par["data"].toObject();
if (!data.contains("exitcode")) {
continue;
}
QString advice = data["advice"].toString();
QString message = data["message"].toString();
QString name = data["name"].toString();
QString url = data["url"].toString();
QString issues = data["issues"].toString();
QDialog dialog;
dialog.setWindowTitle(tr("minikube start failed"));
dialog.setWindowIcon(*trayIconIcon);
dialog.setFixedWidth(600);
dialog.setModal(true);
QFormLayout form(&dialog);
QLabel *errorCodeLabel = new QLabel(this);
errorCodeLabel->setWordWrap(true);
if (!name.isEmpty()) {
errorCodeLabel->setText("Error Code: " + name);
form.addRow(errorCodeLabel);
}
QLabel *adviceLabel = new QLabel(this);
adviceLabel->setWordWrap(true);
if (!advice.isEmpty()) {
adviceLabel->setText("Advice: " + advice);
form.addRow(adviceLabel);
}
QLabel *messageLabel = new QLabel(this);
messageLabel->setWordWrap(true);
if (!message.isEmpty()) {
messageLabel->setText("Error message: " + message);
form.addRow(messageLabel);
}
QLabel *urlLabel = new QLabel(this);
urlLabel->setOpenExternalLinks(true);
urlLabel->setWordWrap(true);
if (!url.isEmpty()) {
urlLabel->setText("Link to documentation: <a href='" + url + "'>" + url + "</a>");
form.addRow(urlLabel);
}
QLabel *linkLabel = new QLabel(this);
linkLabel->setOpenExternalLinks(true);
urlLabel->setWordWrap(true);
if (!issues.isEmpty()) {
urlLabel->setText("Link to related issue: <a href='" + issues + "'>" + issues + "</a>");
form.addRow(urlLabel);
}
QDialogButtonBox buttonBox(Qt::Horizontal, &dialog);
buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole);
connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
form.addRow(&buttonBox);
dialog.exec();
} }
} }

View File

@ -122,6 +122,7 @@ private:
void sshConsole(); void sshConsole();
void dashboardBrowser(); void dashboardBrowser();
void checkForMinikube(); void checkForMinikube();
void outputFailedStart(QString text);
QPushButton *sshButton; QPushButton *sshButton;
QPushButton *dashboardButton; QPushButton *dashboardButton;
QProcess *dashboardProcess; QProcess *dashboardProcess;