-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add domain check for Kubernetes family infrastructures
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2020 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
import * as http from 'http' | ||
import * as Listr from 'listr' | ||
|
||
export namespace CommonPlatformTasks { | ||
/** | ||
* Checks whether cluster on which Che is being deployed accessible. | ||
* Requires flags.domain to be set. | ||
*/ | ||
export function getPingClusterTask(flags: any): Listr.ListrTask { | ||
return { | ||
title: 'Check if cluster accessible', | ||
skip: () => flags['skip-cluster-check'], | ||
task: async (_ctx: any, task: any) => { | ||
const domain: string = flags.domain | ||
if (!domain) { | ||
task.title = `${task.title}... "--domain" flag is not set. Cannot check cluster availability.'` | ||
return | ||
} | ||
|
||
if (!await checkServer(domain, 80) && !await checkServer(domain, 443)) { | ||
throw new Error(`Cannot reach cluster "${domain}". To skip this check add "--skip-cluster-check" flag.`) | ||
} | ||
|
||
task.title = `${task.title}... ok` | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Sends request to given server to check if it is accessible. | ||
*/ | ||
function checkServer(host: string, port: number): Promise<boolean> { | ||
return new Promise(resolve => { | ||
http.get({ host, port }, response => { | ||
// It is ok to have 404, but not 5xx | ||
if (response.statusCode && response.statusCode / 100 < 5) { | ||
resolve(true) | ||
} | ||
resolve(false) | ||
}).on('error', () => { | ||
resolve(false) | ||
}) | ||
}) | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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