Review a zero-downtime service rollout

src/service-rollout-config.tsTypeScript
@@ -0,0 +1,77 @@
1+export type HealthCheck = "process" | "database" | "message-broker";
2+
3+export interface ServiceRolloutConfig {
4+ replicas: number;
5+ health: {
6+ livenessChecks: HealthCheck[];
7+ readinessChecks: HealthCheck[];
8+ minimumReadySeconds: number;
9+ };
10+ shutdown: {
11+ drainTimeoutSeconds: number;
12+ forceAfterSeconds: number;
13+ };
14+ rollingReplacement: {
15+ maxUnavailable: number;
16+ maxSurge: number;
17+ };
18+ voluntaryDisruption: {
19+ minimumAvailable: number;
20+ };
21+}
22+
23+export const serviceRolloutConfig: ServiceRolloutConfig = {
24+ replicas: 3,
25+ health: {
26+ livenessChecks: ["process"],
27+ readinessChecks: ["process"],
28+ minimumReadySeconds: 20,
29+ },
30+ shutdown: {
31+ drainTimeoutSeconds: 30,
32+ forceAfterSeconds: 10,
33+ },
34+ rollingReplacement: {
35+ maxUnavailable: 2,
36+ maxSurge: 0,
37+ },
38+ voluntaryDisruption: {
39+ minimumAvailable: 1,
40+ },
41+};
42+
43+export interface RenderedServiceDeployment {
44+ instanceCount: number;
45+ probes: {
46+ liveness: HealthCheck[];
47+ readiness: HealthCheck[];
48+ readyWarmupSeconds: number;
49+ };
50+ termination: { drainSeconds: number; forceSeconds: number };
51+ replacement: { unavailable: number; surge: number };
52+ disruption: { minimumAvailable: number };
53+}
54+
55+export function renderServiceDeployment(
56+ config: ServiceRolloutConfig,
57+): RenderedServiceDeployment {
58+ return {
59+ instanceCount: config.replicas,
60+ probes: {
61+ liveness: [...config.health.livenessChecks],
62+ readiness: [...config.health.readinessChecks],
63+ readyWarmupSeconds: config.health.minimumReadySeconds,
64+ },
65+ termination: {
66+ drainSeconds: config.shutdown.drainTimeoutSeconds,
67+ forceSeconds: config.shutdown.forceAfterSeconds,
68+ },
69+ replacement: {
70+ unavailable: config.rollingReplacement.maxUnavailable,
71+ surge: config.rollingReplacement.maxSurge,
72+ },
73+ disruption: {
74+ minimumAvailable: config.voluntaryDisruption.minimumAvailable,
75+ },
76+ };
77+}