diff --git a/action.yml b/action.yml index 2a169b8..a8357a7 100644 --- a/action.yml +++ b/action.yml @@ -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' \ No newline at end of file + main: 'src/index.js' diff --git a/src/index.js b/src/index.js index 5611eac..d93cdd1 100644 --- a/src/index.js +++ b/src/index.js @@ -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 { @@ -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) { @@ -45,4 +52,4 @@ try { } } catch (error) { core.setFailed(error.message); -} \ No newline at end of file +}