UNPKG

2.78 kBTypeScriptView Raw
1import { Configuration } from "@atomist/automation-client";
2import { ExecuteGoalResult, GoalInvocation, GoalScheduler } from "@atomist/sdm";
3import * as k8s from "@kubernetes/client-node";
4/**
5 * Options to configure the k8s goal scheduling support
6 */
7export interface KubernetesGoalSchedulerOptions {
8 isolateAll?: boolean;
9}
10/**
11 * GoalScheduler implementation that schedules SDM goals inside k8s jobs.
12 *
13 * It reuses the podSpec of the deployed SDM to create a new jobSpec from.
14 * Subclasses may change the spec and job creation behavior by overwriting beforeCreation
15 * and/or afterCreation methods.
16 */
17export declare class KubernetesGoalScheduler implements GoalScheduler {
18 private readonly options;
19 private podSpec;
20 constructor(options?: KubernetesGoalSchedulerOptions);
21 supports(gi: GoalInvocation): Promise<boolean>;
22 schedule(gi: GoalInvocation): Promise<ExecuteGoalResult>;
23 /**
24 * Extension point for sub classes to modify k8s resources or provided jobSpec before the
25 * Job gets created in k8s.
26 * Note: A potentially existing job with the same name has already been deleted at this point.
27 * @param gi
28 * @param jobSpec
29 */
30 protected beforeCreation(gi: GoalInvocation, jobSpec: k8s.V1Job): Promise<void>;
31 /**
32 * Extension point for sub classes to modify k8s resources after the job has been created.
33 * The provided jobSpec contains the result of the job creation API call.
34 * @param gi
35 * @param jobSpec
36 */
37 protected afterCreation(gi: GoalInvocation, jobSpec: k8s.V1Job): Promise<void>;
38 initialize(configuration: Configuration): Promise<void>;
39 /**
40 * Extension point to allow for custom clean up logic.
41 */
42 protected cleanUp(): Promise<void>;
43}
44/**
45 * Cleanup scheduled k8s goal jobs
46 * @returns {Promise<void>}
47 */
48export declare function cleanCompletedJobs(): Promise<void>;
49/**
50 * Create a jobSpec by modifying the provided podSpec
51 * @param podSpec
52 * @param podNs
53 * @param gi
54 * @param context
55 */
56export declare function createJobSpec(podSpec: k8s.V1Pod, podNs: string, gi: GoalInvocation): k8s.V1Job;
57/**
58 * Checks if one of the provided values is configured in ATOMIST_GOAL_SCHEDULER or -
59 * for backwards compatibility reasons - ATOMIST_GOAL_LAUNCHER.
60 * @param values
61 */
62export declare function isConfiguredInEnv(...values: string[]): boolean;
63/**
64 * Strip out any characters that aren't allowed a k8s label value
65 * @param name
66 */
67export declare function sanitizeName(name: string): string;
68/**
69 * List k8s jobs for a single namespace or cluster-wide depending on evn configuration
70 * @param labelSelector
71 */
72export declare function listJobs(labelSelector?: string): Promise<k8s.V1Job[]>;
73export declare function prettyPrintError(e: any): string;