Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace config #2

Merged
merged 1 commit into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}