Skip to content

Commit 6cc5a80

Browse files
author
Jean-Dominique Nguele
authored
Merge pull request #2 from ChipWolf/master
Add namespace config
2 parents fef28dc + 3583857 commit 6cc5a80

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ inputs:
1212
description: 'Time to wait (in seconds) before attempting the check after a failure.'
1313
required: false
1414
default: 30
15+
namespace:
16+
description: "Namespace to check"
17+
required: false
18+
default: 'default'
19+
all-namespaces:
20+
description: 'Set true to check all namespaces'
21+
required: false
22+
default: 'false'
1523
runs:
1624
using: 'node12'
17-
main: 'src/index.js'
25+
main: 'src/index.js'

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ const { spawnSync } = require('child_process');
33

44
const maxRetryAttempts = parseInt(`${core.getInput('max-retry-attempts')}`);
55
const retryDelay = parseInt(`${core.getInput('retry-delay')}`);
6+
const namespace = core.getInput('namespace')
7+
const allNamespaces = core.getInput('all-namespaces').toLowerCase() == "true" ? true : false
68

79
function checkPodsAreUp() {
8-
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods','--field-selector=status.phase!=Running,status.phase!=Completed']);
10+
if (allNamespaces) {
11+
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods', '--field-selector=status.phase!=Running,status.phase!=Completed', '--all-namespaces']);
12+
} else {
13+
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods', '--field-selector=status.phase!=Running,status.phase!=Completed', '-n ', namespace]);
14+
}
915
var errorOutput = lastCommandRunning.stderr.toString();
1016
var defaultOutput = lastCommandRunning.stdout.toString();
1117
return {
@@ -26,6 +32,7 @@ if (maxRetryAttempts <= 0 || retryDelay <= 0) {
2632
try {
2733
console.log('Check pods are up...');
2834
var result = checkPodsAreUp();
35+
console.log(result.message);
2936
var attemptsCount = 0;
3037

3138
while(!result.success && attemptsCount < maxRetryAttempts) {
@@ -45,4 +52,4 @@ try {
4552
}
4653
} catch (error) {
4754
core.setFailed(error.message);
48-
}
55+
}

0 commit comments

Comments
 (0)