Skip to content

Commit

Permalink
fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Oct 31, 2024
1 parent d0b6d9d commit fa21d75
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ export interface PloneDeploymentOptions {
* Liveness Probe for the pod.
* @default - generated
*/
readonly livenessProbe?: k8s.Probe;
livenessProbe?: k8s.Probe;

/**
* Readiness Probe for the pod.
* @default - generated
*/
readonly readinessProbe?: k8s.Probe;
readinessProbe?: k8s.Probe;

}

Expand Down
118 changes: 58 additions & 60 deletions src/plone.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Names } from 'cdk8s';
import * as kplus from 'cdk8s-plus-24';
import { Construct } from 'constructs';
import { PloneDeployment } from './deployment';
import { Probe, IntOrString } from './imports/k8s';
import { PloneDeployment, PloneDeploymentOptions } from './deployment';
import { IntOrString } from './imports/k8s';
import * as k8s from './imports/k8s';
import { PloneService } from './service';

Expand Down Expand Up @@ -80,14 +80,34 @@ export class Plone extends Construct {
};
const backendPort = 8080;

// Options
var backendOptions: PloneDeploymentOptions = {
labels: backendLabels,
image: {
image: backend.image ?? 'plone/plone-backend:latest',
imagePullSecrets: options.imagePullSecrets ?? [],
imagePullPolicy: backend.imagePullPolicy ?? 'IfNotPresent',
},
replicas: backend.replicas,
limitCpu: backend.limitCpu ?? '500m',
limitMemory: backend.limitMemory ?? '512Mi',
requestCpu: backend.requestCpu ?? '200m',
requestMemory: backend.requestMemory ?? '256Mi',
pdb: {
maxUnavailable: backend.maxUnavailable ?? undefined,
minAvailable: backend.minAvailable ?? undefined,
},
port: backendPort,
environment: backend.environment,
};

// Probing
const backendActionHttpGet: k8s.HttpGetAction = {
path: '/',
port: IntOrString.fromNumber(backendPort),
};
var backendLivenessProbe: Probe | undefined = undefined;
if (backend.livenessEnabled ?? false) {
backendLivenessProbe = {
backendOptions.livenessProbe = {
httpGet: backendActionHttpGet,
initialDelaySeconds: backend.livenessInitialDelaySeconds ?? 30,
timeoutSeconds: backend.livenessIimeoutSeconds ?? 5,
Expand All @@ -96,9 +116,8 @@ export class Plone extends Construct {
failureThreshold: backend.livenessFailureThreshold ?? 3,
};
}
var backendReadinessProbe: Probe | undefined = undefined;
if (backend.readinessEnabled ?? true) {
backendReadinessProbe = {
backendOptions.readinessProbe = {
httpGet: backendActionHttpGet,
initialDelaySeconds: backend.readinessInitialDelaySeconds ?? 10,
timeoutSeconds: backend.readinessIimeoutSeconds ?? 15,
Expand All @@ -108,27 +127,7 @@ export class Plone extends Construct {
};
}
// Deployment
const backendDeployment = new PloneDeployment(this, 'backend', {
labels: backendLabels,
image: {
image: backend.image ?? 'plone/plone-backend:latest',
imagePullSecrets: options.imagePullSecrets ?? [],
imagePullPolicy: backend.imagePullPolicy ?? 'IfNotPresent',
},
replicas: backend.replicas,
limitCpu: backend.limitCpu ?? '500m',
limitMemory: backend.limitMemory ?? '512Mi',
requestCpu: backend.requestCpu ?? '200m',
requestMemory: backend.requestMemory ?? '256Mi',
pdb: {
maxUnavailable: backend.maxUnavailable ?? undefined,
minAvailable: backend.minAvailable ?? undefined,
},
port: backendPort,
environment: backend.environment,
livenessProbe: backendLivenessProbe,
readinessProbe: backendReadinessProbe,
});
var backendDeployment = new PloneDeployment(this, 'backend', backendOptions);

// Service
const backendService = new PloneService(backendDeployment, 'service', {
Expand All @@ -152,43 +151,15 @@ export class Plone extends Construct {
'app.kubernetes.io/version': options.version ?? 'undefined',
};

// Probing
const frontendActionHttpGet: k8s.HttpGetAction = {
path: '/',
port: IntOrString.fromNumber(frontendPort),
};
var frontendLivenessProbe: Probe | undefined = undefined;
if (frontend.livenessEnabled ?? false) {
frontendLivenessProbe = {
httpGet: frontendActionHttpGet,
initialDelaySeconds: frontend.livenessInitialDelaySeconds ?? 30,
timeoutSeconds: frontend.livenessIimeoutSeconds ?? 5,
periodSeconds: frontend.livenessPeriodSeconds ?? 10,
successThreshold: frontend.livenessSuccessThreshold ?? 1,
failureThreshold: frontend.livenessFailureThreshold ?? 3,
};
}
var frontendReadinessProbe: Probe | undefined = undefined;
if (frontend.readinessEnabled ?? true) {
frontendReadinessProbe = {
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
var frontendEnvironment = frontend.environment ?? new kplus.Env([], {});
if (frontendEnvironment.variables.RAZZLE_INTERNAL_API_PATH === undefined) {
// connect with backend service
frontendEnvironment?.addVariable('RAZZLE_INTERNAL_API_PATH', kplus.EnvValue.fromValue(`http://${backendService.name}:${backendPort}/${this.siteId}`));
}

// Deployment
const frontendDeployment = new PloneDeployment(this, 'frontend', {
// Options
var frontendOptions: PloneDeploymentOptions = {
labels: frontendLabels,
image: {
image: frontend.image ?? 'plone/plone-frontend:latest',
Expand All @@ -207,9 +178,36 @@ export class Plone extends Construct {
},
port: frontendPort,
environment: frontendEnvironment,
livenessProbe: frontendLivenessProbe,
readinessProbe: frontendReadinessProbe,
});
};

// Probing
const frontendActionHttpGet: k8s.HttpGetAction = {
path: '/',
port: IntOrString.fromNumber(frontendPort),
};
if (frontend.livenessEnabled ?? false) {
frontendOptions.livenessProbe = {
httpGet: frontendActionHttpGet,
initialDelaySeconds: frontend.livenessInitialDelaySeconds ?? 30,
timeoutSeconds: frontend.livenessIimeoutSeconds ?? 5,
periodSeconds: frontend.livenessPeriodSeconds ?? 10,
successThreshold: frontend.livenessSuccessThreshold ?? 1,
failureThreshold: frontend.livenessFailureThreshold ?? 3,
};
}
if (frontend.readinessEnabled ?? true) {
frontendOptions.readinessProbe = {
httpGet: frontendActionHttpGet,
initialDelaySeconds: frontend.readinessInitialDelaySeconds ?? 10,
timeoutSeconds: frontend.readinessIimeoutSeconds ?? 15,
periodSeconds: frontend.readinessPeriodSeconds ?? 10,
successThreshold: frontend.readinessSuccessThreshold ?? 1,
failureThreshold: frontend.readinessFailureThreshold ?? 3,
};
}

// Deployment
const frontendDeployment = new PloneDeployment(this, 'frontend', frontendOptions);

// Service
const frontendService = new PloneService(frontendDeployment, 'service', {
Expand Down

0 comments on commit fa21d75

Please sign in to comment.