Skip to content

Commit

Permalink
now with environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Jun 27, 2024
1 parent c5bbbcd commit 2f684cb
Show file tree
Hide file tree
Showing 12 changed files with 910 additions and 809 deletions.
13 changes: 13 additions & 0 deletions .projen/deps.json

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

4 changes: 2 additions & 2 deletions .projen/tasks.json

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

8 changes: 6 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cdk } from 'projen';
const kplus = 'cdk8s-plus-24';
const project = new cdk.JsiiProject({
author: 'Jens W. Klein',
authorAddress: '[email protected]',
Expand All @@ -10,14 +11,17 @@ const project = new cdk.JsiiProject({
description: 'Provides a CMS Plone Backend and Frontend for Kubernetes with cdk8s',
deps: [
'cdk8s',
'cdk8s-plus-24',
'constructs',
kplus,
'constructs@^10.3.0',
],
peerDeps: [
'cdk8s',
kplus,
'constructs@^10.3.0',
],
devDeps: [
'cdk8s',
kplus,
'constructs@^10.3.0',
'yaml',
],
Expand Down
34 changes: 28 additions & 6 deletions API.md

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

17 changes: 10 additions & 7 deletions package.json

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

19 changes: 15 additions & 4 deletions src/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Names } from 'cdk8s';
// eslint-disable-next-line import/no-extraneous-dependencies
import * as kplus from 'cdk8s-plus-24';
import { Construct } from 'constructs';
import * as k8s from './imports/k8s';
import { PlonePDB, PlonePDBOptions } from './pdb';
Expand Down Expand Up @@ -31,6 +31,12 @@ export interface PloneDeploymentOptions {
*/
readonly image?: PloneImageOptions;

/**
* Specify an environment for Plone .
* @default - none
*/
readonly environment?: kplus.Env;

/**
* Number of replicas.
* @default 2
Expand Down Expand Up @@ -79,12 +85,17 @@ export class PloneDeployment extends Construct {
...options.labels ?? {},
...label,
};
var ploneContainerSpec = {
...options.ploneContainer ?? {},
const kpEnv = options.environment ?? new kplus.Env([], {});
var env: k8s.EnvVar[] = [];
for (const name in kpEnv.variables) {
env.push({ name: name, value: kpEnv.variables[name].value });
}
var ploneContainerSpec: k8s.Container = {
name: id + '-container', // here the namespaced name shold be used, but how?
image: image.image,
imagePullPolicy: image.imagePullPolicy,
imagePullSecret: { name: image.imagePullSecret },
// imagePullSecret: image.imagePullSecret, -> ServiceAccount should be used
env: env,
};
const deploymentOptions: k8s.KubeDeploymentProps = {
metadata: {
Expand Down
17 changes: 8 additions & 9 deletions src/pdb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Construct } from 'constructs';
import { IntOrString, KubePodDisruptionBudget, PodDisruptionBudgetSpec } from './imports/k8s';
import * as k8s from './imports/k8s';

export interface PlonePDBOptions {
/**
Expand Down Expand Up @@ -28,30 +27,30 @@ export class PlonePDB extends Construct {
constructor(scope: Construct, id: string, selectorLabel: { [name: string]: string }, options: PlonePDBOptions) {
super(scope, id);

var spec: PodDisruptionBudgetSpec = {};
var spec: k8s.PodDisruptionBudgetSpec = {};
if (typeof options.maxUnavailable === 'number') {
spec = {
maxUnavailable: IntOrString.fromNumber(options.maxUnavailable as number),
maxUnavailable: k8s.IntOrString.fromNumber(options.maxUnavailable as number),
};
} else if (typeof options.maxUnavailable === 'string') {
spec = {
maxUnavailable: IntOrString.fromString(options.maxUnavailable as string),
maxUnavailable: k8s.IntOrString.fromString(options.maxUnavailable as string),
};
}
if (typeof options.minAvailable === 'number') {
spec = {
...spec,
minAvailable: IntOrString.fromNumber(options.minAvailable as number),
minAvailable: k8s.IntOrString.fromNumber(options.minAvailable as number),
};
} else if (typeof options.minAvailable === 'string') {
spec = {
...spec,
minAvailable: IntOrString.fromString(options.minAvailable as string),
minAvailable: k8s.IntOrString.fromString(options.minAvailable as string),
};
}
if (options.maxUnavailable === undefined && options.minAvailable === undefined) {
spec = {
minAvailable: IntOrString.fromNumber(1),
minAvailable: k8s.IntOrString.fromNumber(1),
};
}

Expand All @@ -60,7 +59,7 @@ export class PlonePDB extends Construct {
selector: { matchLabels: selectorLabel },
};

new KubePodDisruptionBudget(this, 'PDB', {
new k8s.KubePodDisruptionBudget(this, 'PDB', {
metadata: {
labels: options.labels ?? {},
},
Expand Down
28 changes: 19 additions & 9 deletions src/plone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { Names } from 'cdk8s';
import * as kplus from 'cdk8s-plus-24';
import { Construct } from 'constructs';
import { PloneDeployment } from './deployment';
import { PloneService } from './service';
Expand All @@ -11,19 +11,22 @@ export interface PloneOptions {
readonly backendReplicas?: number;
readonly backendMaxUnavailable?: number | string;
readonly backendMinAvailable?: number | string;
readonly backendEnvironment?: string;
readonly backendEnvironment?: kplus.Env;

readonly frontendImage?: string;
readonly frontendImagePullSecret?: string;
readonly frontendImagePullPolicy?: string;
readonly frontendReplicas?: number;
readonly frontendMaxUnavailable?: number | string;
readonly frontendMinAvailable?: number | string;
readonly frontendEnvironment?: string;
readonly frontendEnvironment?: kplus.Env;
}

export class Plone extends Construct {

public readonly backendServiceName: string;
public readonly frontendServiceName: string;

constructor(scope: Construct, id: string, options: PloneOptions = {}) {
super(scope, id);

Expand All @@ -33,40 +36,47 @@ export class Plone extends Construct {
image: {
image: options.backendImage ?? 'plone/plone-backend:latest',
imagePullSecret: options.backendImagePullSecret ?? '',
imagePullPolicy: options.backendImagePullPolicy ?? 'always',
imagePullPolicy: options.backendImagePullPolicy ?? 'ifNotPresent',
},
replicas: options.backendReplicas,
pdb: {
maxUnavailable: options.backendMaxUnavailable ?? undefined,
minAvailable: options.backendMinAvailable ?? undefined,
},
port: backendPort,
// environment: options.backendEnvironment,
environment: options.backendEnvironment,
});
new PloneService(backendDeployment, 'service', {
const backendService = new PloneService(backendDeployment, 'service', {
targetPort: backendPort,
selectorLabel: { app: Names.toLabelValue(backendDeployment) },
});
this.backendServiceName = backendService.name;

// Frontend
const frontendPort = 3000;
var frontendEnvironment = options.frontendEnvironment ?? new kplus.Env([], {});
if (frontendEnvironment.variables.RAZZLE_API_PATH === undefined) {
frontendEnvironment?.addVariable('RAZZLE_INTERNAL_API_PATH', kplus.EnvValue.fromValue(`http://${backendService.name}:80`));
}

const frontendDeployment = new PloneDeployment(this, 'frontend', {
image: {
image: options.frontendImage ?? 'plone/plone-frontend:latest',
imagePullSecret: options.frontendImagePullSecret ?? '',
imagePullPolicy: options.frontendImagePullPolicy ?? 'always',
imagePullPolicy: options.frontendImagePullPolicy ?? 'ifNotPresent',
},
replicas: options.frontendReplicas,
pdb: {
maxUnavailable: options.frontendMaxUnavailable ?? undefined,
minAvailable: options.frontendMinAvailable ?? undefined,
},
port: frontendPort,
// environment: options.frontendEnvironment,
environment: frontendEnvironment,
});
new PloneService(frontendDeployment, 'service', {
const frontendService = new PloneService(frontendDeployment, 'service', {
targetPort: frontendPort,
selectorLabel: { app: Names.toLabelValue(frontendDeployment) },
});
this.frontendServiceName = frontendService.name;
}
}
Loading

0 comments on commit 2f684cb

Please sign in to comment.