-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new "kubectl wait" action handler
- Loading branch information
1 parent
b34e948
commit e4fd15b
Showing
15 changed files
with
436 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Kubectl Wait | ||
|
||
`kubectl wait` command wrapper. | ||
|
||
**ID:** `com.fireblink.fbl.plugins.k8s.kubectl.wait` | ||
|
||
**Aliases:** | ||
|
||
- `fbl.plugins.k8s.kubectl.wait` | ||
- `k8s.kubectl.wait` | ||
- `kubectl.wait` | ||
|
||
## Usage | ||
|
||
```yaml | ||
kubectl.wait: | ||
# [required] K8s resource type name | ||
resource: pod | ||
|
||
# [required] Resource name | ||
name: busybox1 | ||
|
||
# [required] condition | ||
for: | ||
# [optional] whether should wait for the resource to be deleted | ||
# Note: either "delete" or "condition" should be specified, but not both at the same time | ||
delete: true | ||
|
||
# [optional] condition to waif for | ||
# Note: either "delete" or "condition" should be specified, but not both at the same time | ||
condition: Ready | ||
|
||
# [optional] timeout to wait | ||
timeout: '60s' | ||
|
||
# [optional] K8s namespace. | ||
# Default value: default | ||
namespace: nondefault | ||
|
||
# [optional] Enable verbose output. | ||
debug: true | ||
|
||
# [optional] Extra arguments to append to the command. | ||
# Refer to `kubectl wait --help` for all available options. | ||
extra: [] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
ActionHandler, | ||
ActionProcessor, | ||
IActionHandlerMetadata, | ||
IContext, | ||
ActionSnapshot, | ||
IDelegatedParameters, | ||
} from 'fbl'; | ||
import { WaitActionProcessor } from '../processors'; | ||
|
||
export class WaitActionHandler extends ActionHandler { | ||
private static metadata = <IActionHandlerMetadata>{ | ||
id: 'com.fireblink.fbl.plugins.k8s.kubectl.wait', | ||
aliases: ['fbl.plugins.k8s.kubectl.wait', 'k8s.kubectl.wait', 'kubectl.wait'], | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
getMetadata(): IActionHandlerMetadata { | ||
return WaitActionHandler.metadata; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getProcessor( | ||
options: any, | ||
context: IContext, | ||
snapshot: ActionSnapshot, | ||
parameters: IDelegatedParameters, | ||
): ActionProcessor { | ||
return new WaitActionProcessor(options, context, snapshot, parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as Joi from 'joi'; | ||
import { BaseActionProcessor } from './BaseActionProcessor'; | ||
import { K8sObjectJoiValidationSchema } from '../joi/K8sObjectJoiValidationSchema'; | ||
import { TempPathsRegistry, FBL_ASSIGN_TO_SCHEMA, FBL_PUSH_TO_SCHEMA, ContextUtil, FSUtil } from 'fbl'; | ||
import Container from 'typedi'; | ||
import { join, basename } from 'path'; | ||
|
||
export class WaitActionProcessor extends BaseActionProcessor { | ||
private static validationSchema = Joi.object({ | ||
resource: Joi.string() | ||
.min(1) | ||
.required(), | ||
|
||
name: Joi.string() | ||
.min(1) | ||
.required(), | ||
|
||
for: Joi.object({ | ||
delete: Joi.boolean(), | ||
condition: Joi.string().min(1), | ||
}) | ||
.xor('delete', 'condition') | ||
.required() | ||
.options({ abortEarly: true, allowUnknown: false }), | ||
|
||
// enable verbose output | ||
debug: Joi.boolean(), | ||
|
||
// Namespace | ||
namespace: Joi.string(), | ||
|
||
timeout: Joi.string().min(1), | ||
|
||
// extra arguments to append to the command | ||
// refer to `kubectl wait --help` for all available options | ||
extra: Joi.array().items(Joi.string()), | ||
}) | ||
.required() | ||
.options({ abortEarly: true, allowUnknown: false }); | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getValidationSchema(): Joi.SchemaLike | null { | ||
return WaitActionProcessor.validationSchema; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async execute(): Promise<void> { | ||
const args = await this.prepareCLIArgs(); | ||
await this.execKubectlCommand(args, this.options.debug); | ||
} | ||
|
||
/** | ||
* Prepare CLI args | ||
*/ | ||
private async prepareCLIArgs(): Promise<string[]> { | ||
const args: string[] = ['wait']; | ||
|
||
this.pushWithValue(args, '--namespace', this.options.namespace); | ||
this.pushWithValue(args, '--timeout', this.options.timeout); | ||
|
||
if (this.options.extra) { | ||
args.push(...this.options.extra); | ||
} | ||
|
||
if (this.options.for.delete) { | ||
args.push('--for=delete'); | ||
} | ||
|
||
if (this.options.for.condition) { | ||
args.push(`--for=condition=${this.options.for.condition}`); | ||
} | ||
|
||
args.push(`${this.options.resource}/${this.options.name}`); | ||
|
||
return args; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.