-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add frontend and refactor pdb to genric use
- Loading branch information
Showing
12 changed files
with
501 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Names } from 'cdk8s'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Construct } from 'constructs'; | ||
import * as k8s from './imports/k8s'; | ||
import { PlonePDB, PlonePDBOptions } from './pdb'; | ||
|
||
export interface PloneBackendDeploymentOptions { | ||
/** | ||
* Specify a custom image for Plone Backend. | ||
* @default "plone/plone-backend:latest" | ||
*/ | ||
readonly image?: string; | ||
|
||
/** | ||
* Number of replicas. | ||
* @default 2 | ||
*/ | ||
readonly replicas?: number; | ||
|
||
/** | ||
* Port number. | ||
* @default 8080 | ||
*/ | ||
readonly port?: number; | ||
|
||
/** | ||
* Extra labels to associate with resources. | ||
* @default - none | ||
*/ | ||
readonly labels?: { [name: string]: string }; | ||
|
||
/** | ||
* Create a PodDisruptionBugdet for the deployment? | ||
* If given | ||
* @default - none | ||
*/ | ||
readonly pdbOptions?: PlonePDBOptions; | ||
} | ||
|
||
export class PloneBackendDeployment extends Construct { | ||
|
||
constructor(scope: Construct, id: string, options: PloneBackendDeploymentOptions = {}) { | ||
super(scope, id); | ||
const image = options.image ?? 'plone/plone-backend:latest'; | ||
const replicas = options.replicas ?? 2; | ||
const label = { app: Names.toLabelValue(this) }; | ||
const template_labels = { | ||
...options.labels ?? {}, | ||
...label, | ||
}; | ||
const deploymentOptions: k8s.KubeDeploymentProps = { | ||
metadata: { | ||
labels: options.labels ?? {}, | ||
}, | ||
spec: { | ||
replicas, | ||
selector: { | ||
matchLabels: label, | ||
}, | ||
template: { | ||
metadata: { labels: template_labels }, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: id + '-container', // here the namespaced name shold be used, but how? | ||
image: image, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
new k8s.KubeDeployment(this, 'deployment', deploymentOptions); | ||
|
||
if (options.pdbOptions ?? false) { | ||
const pdbOptions = options.pdbOptions ?? {}; | ||
new PlonePDB(this, 'pdb', label, pdbOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Names } from 'cdk8s'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Construct } from 'constructs'; | ||
import * as k8s from './imports/k8s'; | ||
import { PlonePDB, PlonePDBOptions } from './pdb'; | ||
|
||
export interface PloneFrontendDeploymentOptions { | ||
/** | ||
* Specify a custom image for Plone Frontend. | ||
* @default "plone/plone-frontend:latest" | ||
*/ | ||
readonly image?: string; | ||
|
||
/** | ||
* Number of replicas. | ||
* @default 2 | ||
*/ | ||
readonly replicas?: number; | ||
|
||
/** | ||
* Port number. | ||
* @default 8080 | ||
*/ | ||
readonly port?: number; | ||
|
||
/** | ||
* Extra labels to associate with resources. | ||
* @default - none | ||
*/ | ||
readonly labels?: { [name: string]: string }; | ||
|
||
/** | ||
* Create a PodDisruptionBugdet for the deployment? | ||
* If given | ||
* @default - none | ||
*/ | ||
readonly pdbOptions?: PlonePDBOptions; | ||
} | ||
|
||
export class PloneFrontendDeployment extends Construct { | ||
|
||
constructor(scope: Construct, id: string, options: PloneFrontendDeploymentOptions = {}) { | ||
super(scope, id); | ||
const image = options.image ?? 'plone/plone-backend:latest'; | ||
const replicas = options.replicas ?? 2; | ||
const label = { app: Names.toLabelValue(this) }; | ||
const template_labels = { | ||
...options.labels ?? {}, | ||
...label, | ||
}; | ||
const deploymentOptions: k8s.KubeDeploymentProps = { | ||
metadata: { | ||
labels: options.labels ?? {}, | ||
}, | ||
spec: { | ||
replicas, | ||
selector: { | ||
matchLabels: label, | ||
}, | ||
template: { | ||
metadata: { labels: template_labels }, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: id + '-container', // here the namespaced name shold be used, but how? | ||
image: image, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
new k8s.KubeDeployment(this, 'deployment', deploymentOptions); | ||
|
||
|
||
if (options.pdbOptions ?? false) { | ||
const pdbOptions = options.pdbOptions ?? {}; | ||
new PlonePDB(this, id + '-pdb', label, pdbOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Construct } from 'constructs'; | ||
import { IntOrString, KubeServiceProps, KubeService } from './imports/k8s'; | ||
|
||
export interface PloneFrontendServiceOptions { | ||
/** | ||
* Port number. | ||
* @default 3000 | ||
*/ | ||
readonly port?: number; | ||
|
||
/** | ||
* Port number. | ||
* @default 3000; | ||
*/ | ||
readonly targetPort?: number; | ||
|
||
/** | ||
* Selector label. | ||
*/ | ||
readonly selectorLabel: { [name: string]: string }; | ||
|
||
/** | ||
* Extra labels to associate with resources. | ||
* @default - none | ||
*/ | ||
readonly labels?: { [name: string]: string }; | ||
} | ||
|
||
export class PloneFrontendService extends Construct { | ||
|
||
constructor(scope: Construct, id: string, options: PloneFrontendServiceOptions) { | ||
super(scope, id); | ||
|
||
const port = options.port ?? 3000; | ||
const targetPort = IntOrString.fromNumber(options.targetPort ?? 3000); | ||
const selectorLabel = options.selectorLabel; | ||
|
||
const serviceOpts: KubeServiceProps = { | ||
metadata: { | ||
labels: options.labels ?? {}, | ||
}, | ||
spec: { | ||
type: 'ClusterIP', | ||
clusterIp: 'None', | ||
ports: [{ port: port, targetPort: targetPort }], | ||
selector: selectorLabel, | ||
}, | ||
}; | ||
new KubeService(this, 'service', serviceOpts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Names } from 'cdk8s'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Construct } from 'constructs'; | ||
import { PloneFrontendDeploymentOptions, PloneFrontendDeployment } from './frontend-deployment'; | ||
import { PloneFrontendServiceOptions, PloneFrontendService } from './frontend-service'; | ||
|
||
export interface PloneFrontendOptions { | ||
readonly deployment?: PloneFrontendDeploymentOptions; | ||
readonly service?: PloneFrontendServiceOptions; | ||
} | ||
|
||
export class PloneFrontend extends Construct { | ||
|
||
constructor(scope: Construct, id: string, options: PloneFrontendOptions = {}) { | ||
super(scope, id); | ||
const deploymentOptions = options.deployment ?? {}; | ||
|
||
// Create a deployment | ||
const deployment = new PloneFrontendDeployment(this, 'deployment', deploymentOptions); | ||
|
||
// Create a service | ||
const serviceOptions = { | ||
...options.service ?? {}, | ||
selectorLabel: { app: Names.toLabelValue(deployment) }, | ||
}; | ||
new PloneFrontendService(this, 'service', serviceOptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
export { PlonePDBOptions, PlonePDB } from './pdb'; | ||
export { PloneBackendDeploymentOptions, PloneBackendDeployment } from './backend-deployment'; | ||
export { PloneBackendPDBOptions, PloneBackendPDB } from './backend-pdb'; | ||
export { PloneBackendServiceOptions, PloneBackendService } from './backend-service'; | ||
export { PloneBackendOptions, PloneBackend } from './backend'; | ||
export { PloneFrontendDeploymentOptions, PloneFrontendDeployment } from './frontend-deployment'; | ||
export { PloneFrontendServiceOptions, PloneFrontendService } from './frontend-service'; | ||
export { PloneFrontendOptions, PloneFrontend } from './frontend'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.