Skip to content

Commit

Permalink
Merge pull request #2 from ChipWolf/master
Browse files Browse the repository at this point in the history
Add namespace config
  • Loading branch information
Jean-Dominique Nguele authored Jun 7, 2020
2 parents fef28dc + 3583857 commit 6cc5a80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ inputs:
description: 'Time to wait (in seconds) before attempting the check after a failure.'
required: false
default: 30
namespace:
description: "Namespace to check"
required: false
default: 'default'
all-namespaces:
description: 'Set true to check all namespaces'
required: false
default: 'false'
runs:
using: 'node12'
main: 'src/index.js'
main: 'src/index.js'
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ const { spawnSync } = require('child_process');

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

function checkPodsAreUp() {
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods','--field-selector=status.phase!=Running,status.phase!=Completed']);
if (allNamespaces) {
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods', '--field-selector=status.phase!=Running,status.phase!=Completed', '--all-namespaces']);
} else {
var lastCommandRunning = spawnSync('kubectl', ['get', 'pods', '--field-selector=status.phase!=Running,status.phase!=Completed', '-n ', namespace]);
}
var errorOutput = lastCommandRunning.stderr.toString();
var defaultOutput = lastCommandRunning.stdout.toString();
return {
Expand All @@ -26,6 +32,7 @@ if (maxRetryAttempts <= 0 || retryDelay <= 0) {
try {
console.log('Check pods are up...');
var result = checkPodsAreUp();
console.log(result.message);
var attemptsCount = 0;

while(!result.success && attemptsCount < maxRetryAttempts) {
Expand All @@ -45,4 +52,4 @@ try {
}
} catch (error) {
core.setFailed(error.message);
}
}

0 comments on commit 6cc5a80

Please sign in to comment.