Skip to content

Commit

Permalink
fix: bug issue 47 disabling livenessProbes creates corrupted manifests (
Browse files Browse the repository at this point in the history
#49)

* moved todos to issues

* fixes #47

* update jsii to 5.5.x

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

* feat: Update jssi and cdk8splus (#52)

* Update jssi and cdk8splus

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: github-actions <[email protected]>

* tackle probing in deployment too

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
jensens and github-actions authored Nov 6, 2024
1 parent 67004aa commit 9592efc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 117 deletions.
39 changes: 3 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This chart provides a library to bootstrap a Plone deployment on a Kubernetes cluster using the [CDK8S](https://cdk8s.io) framework.

It provides
- Backend (for API with `plone.volto` or as Classic-UI)
- Backend (as API with `plone.volto` or as Classic-UI)
- Frontend (Plone-Volto, a ReactJS based user interface)
- Varnish using kube-httpcache. It includes a way to invalidate varnish cluster (optional)

Expand Down Expand Up @@ -39,8 +39,6 @@ cdk8s init python-app
Python package name is [cdk8s-plone](https://pypi.org/project/cdk8s-plone/).




## Usage

With `cdk8s-cli` installed, create a new project:
Expand Down Expand Up @@ -75,43 +73,12 @@ Clone the repository and install the dependencies:
```bash
```
nvm use lts/*
npx projen install
corepack enable
npx projen
```
Then run the following command to run the test:
```bash
npx projen test
```

### Feature Wishlist:

Each step need to be implemented with tests!

- [x] Support Variants for ClassicUI or Volto
- [ ] Start Backend
- [x] deployment
- [x] service
- [x] pdb
- [ ] init container running `plone-site-create`
- [x] lifecycle checks (readiness, liveness)
- [x] generic way to inject sidecars
- [ ] metrics sidecar
- [ ] Start Frontend
- [x] deployment
- [x] service
- [x] pdb
- [x] lifecycle checks (readiness, liveness)
- [x] generic way to inject sidecars
- [ ] metrics sidecar
- [x] Start Varnish (using `kube-httpcache`) optional in separate chart
- [x] provide a default VCL for Volto with routing to backend and frontend
- [ ] provide a default VCL for ClassicUI
- [ ] Configure Ingress, optional in separate chart
- [ ] Traefik
- [ ] Konq

- [ ] Release packages for other Languages
- [x] Python
- [ ] Golang
- [ ] Java
8 changes: 4 additions & 4 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 Expand Up @@ -156,8 +156,8 @@ export class PloneDeployment extends Construct {
memory: k8s.Quantity.fromString(options.requestMemory ?? '300Mi'),
},
},
livenessProbe: options.livenessProbe ?? {},
readinessProbe: options.readinessProbe ?? {},
livenessProbe: options.livenessProbe ?? undefined,
readinessProbe: options.readinessProbe ?? undefined,
};
const deploymentOptions: k8s.KubeDeploymentProps = {
metadata: {
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-29';
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
10 changes: 0 additions & 10 deletions test/__snapshots__/deployment.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions test/__snapshots__/httpcache.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions test/__snapshots__/plone.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9592efc

Please sign in to comment.