From 08983b8a5f44a29e37d9128311c7eaa9a3e32b90 Mon Sep 17 00:00:00 2001 From: Vlad Tkachenko Date: Thu, 20 Feb 2020 14:44:49 +0200 Subject: [PATCH] feat: update wait action handler --- docs/Wait.md | 12 ++++++++- package.json | 2 +- src/processors/WaitActionProcessor.ts | 30 ++++++++++++++++++--- test/handlers/WaitActionHandlerTestSuite.ts | 4 ++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/docs/Wait.md b/docs/Wait.md index c7bc5c4..d65cdba 100644 --- a/docs/Wait.md +++ b/docs/Wait.md @@ -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 diff --git a/package.json b/package.json index b7f9d86..9a7ac37 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/processors/WaitActionProcessor.ts b/src/processors/WaitActionProcessor.ts index df97db0..9cb7fad 100644 --- a/src/processors/WaitActionProcessor.ts +++ b/src/processors/WaitActionProcessor.ts @@ -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(), @@ -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 }); @@ -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); @@ -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; } diff --git a/test/handlers/WaitActionHandlerTestSuite.ts b/test/handlers/WaitActionHandlerTestSuite.ts index 15f9082..c6ede6b 100644 --- a/test/handlers/WaitActionHandlerTestSuite.ts +++ b/test/handlers/WaitActionHandlerTestSuite.ts @@ -101,7 +101,9 @@ class WaitHandlerTestSuite { processor = await actionHandler.getProcessor( { resource: 'pods', - name, + labels: { + app: name, + }, for: { delete: true, },