|
3 | 3 | * Licensed under the MIT License. See LICENSE file in the project root for license information. |
4 | 4 | *-----------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { window, commands, env, QuickPickItem, ExtensionContext, Terminal, Uri, workspace, WebviewPanel, Progress as VProgress, QuickInputButton, ThemeIcon, QuickPickItemButtonEvent } from 'vscode'; |
| 6 | +import { KubernetesObject } from '@kubernetes/client-node'; |
| 7 | +import { ExtensionContext, QuickInputButton, QuickPickItem, QuickPickItemButtonEvent, Terminal, ThemeIcon, Uri, Progress as VProgress, WebviewPanel, commands, env, window, workspace } from 'vscode'; |
| 8 | +import { CliChannel, CliExitData } from '../cli'; |
7 | 9 | import { Command } from '../odo/command'; |
8 | | -import OpenShiftItem, { clusterRequired } from './openshiftItem'; |
9 | | -import { CliExitData, CliChannel } from '../cli'; |
10 | 10 | import { TokenStore } from '../util/credentialManager'; |
11 | | -import { KubeConfigUtils } from '../util/kubeUtils'; |
12 | 11 | import { Filters } from '../util/filters'; |
13 | | -import { Progress } from '../util/progress'; |
| 12 | +import { KubeConfigUtils } from '../util/kubeUtils'; |
14 | 13 | import { Platform } from '../util/platform'; |
| 14 | +import { Progress } from '../util/progress'; |
15 | 15 | import { WindowUtil } from '../util/windowUtils'; |
16 | | -import { vsCommand, VsCommandError } from '../vscommand'; |
| 16 | +import { VsCommandError, vsCommand } from '../vscommand'; |
17 | 17 | import ClusterViewLoader from '../webview/cluster/clusterViewLoader'; |
18 | | -import { KubernetesObject } from '@kubernetes/client-node'; |
| 18 | +import OpenShiftItem, { clusterRequired } from './openshiftItem'; |
| 19 | +import fetch = require('make-fetch-happen'); |
19 | 20 |
|
20 | 21 | interface Versions { |
21 | 22 | 'openshift_version': string; |
@@ -275,9 +276,60 @@ export class Cluster extends OpenShiftItem { |
275 | 276 |
|
276 | 277 | if (response !== 'Yes') return null; |
277 | 278 |
|
278 | | - const clusterURL = await Cluster.getUrl(); |
| 279 | + let clusterIsUp = false; |
| 280 | + let clusterURL: string; |
279 | 281 |
|
280 | | - if (!clusterURL) return null; |
| 282 | + do { |
| 283 | + clusterURL = await Cluster.getUrl(); |
| 284 | + |
| 285 | + if (!clusterURL) return null; |
| 286 | + |
| 287 | + try { |
| 288 | + await fetch(`${clusterURL}/api`, { |
| 289 | + // disable cert checking. crc uses a self-signed cert, |
| 290 | + // which means this request will always fail on crc unless cert checking is disabled |
| 291 | + strictSSL: false |
| 292 | + }); |
| 293 | + // since the fetch didn't throw an exception, |
| 294 | + // a route to the cluster is available, |
| 295 | + // so it's running |
| 296 | + clusterIsUp = true; |
| 297 | + } catch (e) { |
| 298 | + const clusterURLObj = new URL(clusterURL); |
| 299 | + if (clusterURLObj.hostname === 'api.crc.testing') { |
| 300 | + const startCrc = 'Start OpenShift Local'; |
| 301 | + const promptResponse = await window.showWarningMessage( |
| 302 | + 'The cluster appears to be a OpenShift Local cluster, but it isn\'t running', |
| 303 | + 'Use a different cluster', |
| 304 | + startCrc, |
| 305 | + ); |
| 306 | + if (promptResponse === startCrc){ |
| 307 | + await commands.executeCommand('openshift.explorer.addCluster', 'crc'); |
| 308 | + // no point in continuing with the wizard, |
| 309 | + // it will take the cluster a few minutes to stabilize |
| 310 | + return null; |
| 311 | + } |
| 312 | + } else if (/api\.sandbox-.*openshiftapps\.com/.test(clusterURLObj.hostname)) { |
| 313 | + const devSandboxSignup = 'Sign up for OpenShift Dev Sandbox'; |
| 314 | + const promptResponse = await window.showWarningMessage( |
| 315 | + 'The cluster appears to be a OpenShift Dev Sandbox cluster, but it isn\'t running', |
| 316 | + 'Use a different cluster', |
| 317 | + devSandboxSignup, |
| 318 | + ); |
| 319 | + if (promptResponse === devSandboxSignup){ |
| 320 | + await commands.executeCommand('openshift.explorer.addCluster', 'sandbox'); |
| 321 | + // no point in continuing with the wizard, |
| 322 | + // the user needs to sign up for the service |
| 323 | + return null; |
| 324 | + } |
| 325 | + } else { |
| 326 | + void window.showWarningMessage( |
| 327 | + 'Unable to contact the cluster. Is it running and accessible?', |
| 328 | + ); |
| 329 | + } |
| 330 | + |
| 331 | + } |
| 332 | + } while (!clusterIsUp); |
281 | 333 |
|
282 | 334 | const loginActions = [ |
283 | 335 | { |
|
0 commit comments