@atomist/sdm-core
Version:
Atomist Software Delivery Machine - Implementation
95 lines • 3.78 kB
TypeScript
import { Configuration, HandlerContext } from "@atomist/automation-client";
import { ExecuteGoalResult, GoalInvocation, GoalScheduler, SdmGoalEvent } from "@atomist/sdm";
import * as k8s from "@kubernetes/client-node";
/**
* Options to configure the k8s goal scheduling support
*/
export interface KubernetesGoalSchedulerOptions {
isolateAll?: boolean;
podSpec?: k8s.V1Pod;
}
/**
* GoalScheduler implementation that schedules SDM goals inside k8s jobs.
*
* It reuses the podSpec of the deployed SDM to create a new jobSpec from.
* Subclasses may change the spec and job creation behavior by overwriting beforeCreation
* and/or afterCreation methods.
*/
export declare class KubernetesGoalScheduler implements GoalScheduler {
private readonly options;
podSpec: k8s.V1Pod;
constructor(options?: KubernetesGoalSchedulerOptions);
supports(gi: GoalInvocation): Promise<boolean>;
schedule(gi: GoalInvocation): Promise<ExecuteGoalResult>;
/**
* Extension point for sub classes to modify k8s resources or provided jobSpec before the
* Job gets created in k8s.
* Note: A potentially existing job with the same name has already been deleted at this point.
* @param gi
* @param jobSpec
*/
protected beforeCreation(gi: GoalInvocation, jobSpec: k8s.V1Job): Promise<void>;
/**
* Extension point for sub classes to modify k8s resources after the job has been created.
* The provided jobSpec contains the result of the job creation API call.
* @param gi
* @param jobSpec
*/
protected afterCreation(gi: GoalInvocation, jobSpec: k8s.V1Job): Promise<void>;
initialize(configuration: Configuration): Promise<void>;
/**
* Extension point to allow for custom clean up logic.
*/
protected cleanUp(): Promise<void>;
}
/**
* Cleanup scheduled k8s goal jobs
* @returns {Promise<void>}
*/
export declare function cleanCompletedJobs(): Promise<void>;
/** Unique name for job to use in k8s job spec. */
export declare function k8sJobName(podSpec: k8s.V1Pod, goalEvent: SdmGoalEvent): string;
/**
* Kubernetes container spec environment variables that specify an SDM
* running in single-goal mode.
*/
export declare function k8sJobEnv(podSpec: k8s.V1Pod, goalEvent: SdmGoalEvent, context: HandlerContext): k8s.V1EnvVar[];
/**
* Create a jobSpec by modifying the provided podSpec
* @param podSpec
* @param podNs
* @param gi
*/
export declare function createJobSpec(podSpec: k8s.V1Pod, podNs: string, gi: GoalInvocation): k8s.V1Job;
/**
* Checks if one of the provided values is configured in ATOMIST_GOAL_SCHEDULER or -
* for backwards compatibility reasons - ATOMIST_GOAL_LAUNCHER.
* @param values
*/
export declare function isConfiguredInEnv(...values: string[]): boolean;
/**
* Strip out any characters that aren't allowed a k8s label value
* @param name
*/
export declare function sanitizeName(name: string): string;
/**
* List k8s jobs for a single namespace or cluster-wide depending on evn configuration
* @param labelSelector
*/
export declare function listJobs(labelSelector?: string): Promise<k8s.V1Job[]>;
export declare const K8sNamespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace";
/**
* Read the namespace of the deployment from environment and k8s service account files.
* Falls back to the default namespace and no other configuration can be found.
*/
export declare function readNamespace(): Promise<string>;
export declare function prettyPrintError(e: any): string;
export declare function deleteJob(job: {
name: string;
namespace: string;
}): Promise<void>;
export declare function deletePods(job: {
name: string;
namespace: string;
}): Promise<void>;
//# sourceMappingURL=KubernetesGoalScheduler.d.ts.map