Skip to content

Commit

Permalink
feat: update wait action handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-tkachenko committed Feb 20, 2020
1 parent e4fd15b commit 08983b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
12 changes: 11 additions & 1 deletion docs/Wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ kubectl.wait:
# [required] K8s resource type name
resource: pod

# [required] Resource name
# [optional] Resource name
# Note: only one of "name", "labels" or "all" settings should be provided
name: busybox1

# [optional] Labels for resource to match.
# Note: only one of "name", "labels" or "all" settings should be provided
labels:
app: awesome-api

# [optional] Whether to match all resources.
# Note: only one of "name", "labels" or "all" settings should be provided
all: true

# [required] condition
for:
# [optional] whether should wait for the resource to be deleted
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fbl-plugins/k8s-kubectl",
"version": "1.2.2",
"version": "1.2.3",
"description": "FBL plugin for K8s Kubectl CLI",
"main": "dist/index.js",
"scripts": {
Expand Down
30 changes: 26 additions & 4 deletions src/processors/WaitActionProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ export class WaitActionProcessor extends BaseActionProcessor {
.min(1)
.required(),

name: Joi.string()
.min(1)
.required(),
name: Joi.string().min(1),

labels: Joi.object().pattern(
Joi.string()
.min(1)
.required(),
Joi.string()
.required()
.min(1),
),

all: Joi.boolean(),

for: Joi.object({
delete: Joi.boolean(),
Expand All @@ -35,6 +44,7 @@ export class WaitActionProcessor extends BaseActionProcessor {
// refer to `kubectl wait --help` for all available options
extra: Joi.array().items(Joi.string()),
})
.xor('name', 'labels', 'all')
.required()
.options({ abortEarly: true, allowUnknown: false });

Expand All @@ -61,6 +71,7 @@ export class WaitActionProcessor extends BaseActionProcessor {

this.pushWithValue(args, '--namespace', this.options.namespace);
this.pushWithValue(args, '--timeout', this.options.timeout);
this.pushWithoutValue(args, '--all', this.options.all);

if (this.options.extra) {
args.push(...this.options.extra);
Expand All @@ -74,7 +85,18 @@ export class WaitActionProcessor extends BaseActionProcessor {
args.push(`--for=condition=${this.options.for.condition}`);
}

args.push(`${this.options.resource}/${this.options.name}`);
if (this.options.labels) {
for (const label of Object.keys(this.options.labels)) {
const value = this.options.labels[label];
args.push('-l', `${label}=${value}`);
}
}

args.push(this.options.resource);

if (this.options.name) {
args.push(this.options.name);
}

return args;
}
Expand Down
4 changes: 3 additions & 1 deletion test/handlers/WaitActionHandlerTestSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class WaitHandlerTestSuite {
processor = await actionHandler.getProcessor(
{
resource: 'pods',
name,
labels: {
app: name,
},
for: {
delete: true,
},
Expand Down

0 comments on commit 08983b8

Please sign in to comment.