From bab60d4fc4f2c8a0c44d535053600b125eba190e Mon Sep 17 00:00:00 2001 From: "Jens W. Klein" Date: Tue, 6 Aug 2024 14:44:46 +0200 Subject: [PATCH 1/2] feat: configurable readiness/liveness values --- src/plone.ts | 87 +++++++++++++++------------ test/__snapshots__/plone.test.ts.snap | 16 ++--- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/plone.ts b/src/plone.ts index 4917788..e990a44 100644 --- a/src/plone.ts +++ b/src/plone.ts @@ -3,19 +3,35 @@ import * as kplus from 'cdk8s-plus-24'; import { Construct } from 'constructs'; import { PloneDeployment } from './deployment'; import { Probe, IntOrString } from './imports/k8s'; +import * as k8s from './imports/k8s'; import { PloneService } from './service'; export interface PloneBaseOptions { + // image readonly image?: string; readonly imagePullPolicy?: string; + // replicas readonly replicas?: number; readonly maxUnavailable?: number | string; readonly minAvailable?: number | string; + // resources readonly limitCpu?: string; readonly limitMemory?: string; readonly requestCpu?: string; readonly requestMemory?: string; readonly environment?: kplus.Env; + // readiness Probe + readonly readinessInitialDelaySeconds?: number; + readonly readinessIimeoutSeconds?: number; + readonly readinessPeriodSeconds?: number; + readonly readinessSuccessThreshold?: number; + readonly readinessFailureThreshold?: number; + // liveness Probe + readonly livenessInitialDelaySeconds?: number; + readonly livenessIimeoutSeconds?: number; + readonly livenessPeriodSeconds?: number; + readonly livenessSuccessThreshold?: number; + readonly livenessFailureThreshold?: number; } export interface PloneOptions { readonly version?: string; @@ -23,6 +39,7 @@ export interface PloneOptions { readonly backend?: PloneBaseOptions; readonly frontend?: PloneBaseOptions; readonly imagePullSecrets?: string[]; + } export class Plone extends Construct { @@ -40,35 +57,33 @@ export class Plone extends Construct { // ------------------------------------------------------------------------ // Backend const backend = options.backend ?? {}; - const backendPort = 8080; const backendLabels = { 'app.kubernetes.io/name': 'plone-backend', 'app.kubernetes.io/component': 'backend', 'app.kubernetes.io/version': options.version ?? 'undefined', }; + const backendPort = 8080; // Probing + const backendActionHttpGet: k8s.HttpGetAction = { + path: '/', + port: IntOrString.fromNumber(backendPort), + }; + const backendLivenessProbe: Probe = { - httpGet: { - path: '/', - port: IntOrString.fromNumber(backendPort), - }, - initialDelaySeconds: 30, - timeoutSeconds: 1, - periodSeconds: 10, - successThreshold: 1, - failureThreshold: 3, + httpGet: backendActionHttpGet, + initialDelaySeconds: backend.livenessInitialDelaySeconds ?? 30, + timeoutSeconds: backend.livenessIimeoutSeconds ?? 5, + periodSeconds: backend.livenessPeriodSeconds ?? 10, + successThreshold: backend.livenessSuccessThreshold ?? 1, + failureThreshold: backend.livenessFailureThreshold ?? 3, }; const backendReadinessProbe: Probe = { - httpGet: { - path: '/', - port: IntOrString.fromNumber(backendPort), - }, - initialDelaySeconds: 10, - timeoutSeconds: 15, - periodSeconds: 10, - successThreshold: 1, - failureThreshold: 3, + initialDelaySeconds: backend.readinessInitialDelaySeconds ?? 10, + timeoutSeconds: backend.readinessIimeoutSeconds ?? 15, + periodSeconds: backend.readinessPeriodSeconds ?? 10, + successThreshold: backend.readinessSuccessThreshold ?? 1, + failureThreshold: backend.readinessFailureThreshold ?? 3, }; // Deployment @@ -116,27 +131,25 @@ export class Plone extends Construct { }; // Probing + const frontendActionHttpGet: k8s.HttpGetAction = { + path: '/', + port: IntOrString.fromNumber(frontendPort), + }; const frontendLivenessProbe: Probe = { - httpGet: { - path: '/', - port: IntOrString.fromNumber(frontendPort), - }, - initialDelaySeconds: 30, - timeoutSeconds: 1, - periodSeconds: 10, - successThreshold: 1, - failureThreshold: 3, + httpGet: frontendActionHttpGet, + initialDelaySeconds: frontend.livenessInitialDelaySeconds ?? 30, + timeoutSeconds: frontend.livenessIimeoutSeconds ?? 5, + periodSeconds: frontend.livenessPeriodSeconds ?? 10, + successThreshold: frontend.livenessSuccessThreshold ?? 1, + failureThreshold: frontend.livenessFailureThreshold ?? 3, }; const frontendReadinessProbe: Probe = { - httpGet: { - path: '/', - port: IntOrString.fromNumber(frontendPort), - }, - initialDelaySeconds: 10, - timeoutSeconds: 15, - periodSeconds: 10, - successThreshold: 1, - failureThreshold: 3, + httpGet: frontendActionHttpGet, + initialDelaySeconds: frontend.readinessInitialDelaySeconds ?? 10, + timeoutSeconds: frontend.readinessIimeoutSeconds ?? 15, + periodSeconds: frontend.readinessPeriodSeconds ?? 10, + successThreshold: frontend.readinessSuccessThreshold ?? 1, + failureThreshold: frontend.readinessFailureThreshold ?? 3, }; // Environment for RAZZLE diff --git a/test/__snapshots__/plone.test.ts.snap b/test/__snapshots__/plone.test.ts.snap index 9c0a1f9..1c6c106 100644 --- a/test/__snapshots__/plone.test.ts.snap +++ b/test/__snapshots__/plone.test.ts.snap @@ -46,15 +46,11 @@ exports[`defaults 1`] = ` "initialDelaySeconds": 30, "periodSeconds": 10, "successThreshold": 1, - "timeoutSeconds": 1, + "timeoutSeconds": 5, }, "name": "backend-container", "readinessProbe": { "failureThreshold": 3, - "httpGet": { - "path": "/", - "port": 8080, - }, "initialDelaySeconds": 10, "periodSeconds": 10, "successThreshold": 1, @@ -170,7 +166,7 @@ exports[`defaults 1`] = ` "initialDelaySeconds": 30, "periodSeconds": 10, "successThreshold": 1, - "timeoutSeconds": 1, + "timeoutSeconds": 5, }, "name": "frontend-container", "readinessProbe": { @@ -294,15 +290,11 @@ exports[`defaults-with-pdps 1`] = ` "initialDelaySeconds": 30, "periodSeconds": 10, "successThreshold": 1, - "timeoutSeconds": 1, + "timeoutSeconds": 5, }, "name": "backend-container", "readinessProbe": { "failureThreshold": 3, - "httpGet": { - "path": "/", - "port": 8080, - }, "initialDelaySeconds": 10, "periodSeconds": 10, "successThreshold": 1, @@ -418,7 +410,7 @@ exports[`defaults-with-pdps 1`] = ` "initialDelaySeconds": 30, "periodSeconds": 10, "successThreshold": 1, - "timeoutSeconds": 1, + "timeoutSeconds": 5, }, "name": "frontend-container", "readinessProbe": { From c72bb0e702d80cce87c6b9a5972b292708bb0f5a Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 6 Aug 2024 12:46:41 +0000 Subject: [PATCH 2/2] chore: self mutation Signed-off-by: github-actions --- API.md | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/API.md b/API.md index 0cc964b..7fc09e6 100644 --- a/API.md +++ b/API.md @@ -158,8 +158,18 @@ const ploneBaseOptions: PloneBaseOptions = { ... } | imagePullPolicy | string | *No description.* | | limitCpu | string | *No description.* | | limitMemory | string | *No description.* | +| livenessFailureThreshold | number | *No description.* | +| livenessIimeoutSeconds | number | *No description.* | +| livenessInitialDelaySeconds | number | *No description.* | +| livenessPeriodSeconds | number | *No description.* | +| livenessSuccessThreshold | number | *No description.* | | maxUnavailable | string \| number | *No description.* | | minAvailable | string \| number | *No description.* | +| readinessFailureThreshold | number | *No description.* | +| readinessIimeoutSeconds | number | *No description.* | +| readinessInitialDelaySeconds | number | *No description.* | +| readinessPeriodSeconds | number | *No description.* | +| readinessSuccessThreshold | number | *No description.* | | replicas | number | *No description.* | | requestCpu | string | *No description.* | | requestMemory | string | *No description.* | @@ -216,6 +226,56 @@ public readonly limitMemory: string; --- +##### `livenessFailureThreshold`Optional + +```typescript +public readonly livenessFailureThreshold: number; +``` + +- *Type:* number + +--- + +##### `livenessIimeoutSeconds`Optional + +```typescript +public readonly livenessIimeoutSeconds: number; +``` + +- *Type:* number + +--- + +##### `livenessInitialDelaySeconds`Optional + +```typescript +public readonly livenessInitialDelaySeconds: number; +``` + +- *Type:* number + +--- + +##### `livenessPeriodSeconds`Optional + +```typescript +public readonly livenessPeriodSeconds: number; +``` + +- *Type:* number + +--- + +##### `livenessSuccessThreshold`Optional + +```typescript +public readonly livenessSuccessThreshold: number; +``` + +- *Type:* number + +--- + ##### `maxUnavailable`Optional ```typescript @@ -236,6 +296,56 @@ public readonly minAvailable: string | number; --- +##### `readinessFailureThreshold`Optional + +```typescript +public readonly readinessFailureThreshold: number; +``` + +- *Type:* number + +--- + +##### `readinessIimeoutSeconds`Optional + +```typescript +public readonly readinessIimeoutSeconds: number; +``` + +- *Type:* number + +--- + +##### `readinessInitialDelaySeconds`Optional + +```typescript +public readonly readinessInitialDelaySeconds: number; +``` + +- *Type:* number + +--- + +##### `readinessPeriodSeconds`Optional + +```typescript +public readonly readinessPeriodSeconds: number; +``` + +- *Type:* number + +--- + +##### `readinessSuccessThreshold`Optional + +```typescript +public readonly readinessSuccessThreshold: number; +``` + +- *Type:* number + +--- + ##### `replicas`Optional ```typescript