Skip to content

Commit

Permalink
feature: support all environment options (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens authored Jul 28, 2024
1 parent f9eee9b commit a9ac5e2
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// import { log } from 'console';
import { Names } from 'cdk8s';
import * as kplus from 'cdk8s-plus-24';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -117,15 +118,16 @@ export class PloneDeployment extends Construct {
'app.kubernetes.io/part-of': 'plone',
'app.kubernetes.io/managed-by': 'cdk8s-plone',
};
const kpEnv = options.environment ?? new kplus.Env([], {});
const kpEnv: kplus.Env = options?.environment ?? new kplus.Env([], {});
var env: k8s.EnvVar[] = [];
var envFrom: k8s.EnvFromSource[] = [];
for (const name in kpEnv.variables) {
env.push({ name: name, value: kpEnv.variables[name].value });
env.push({ name: name, value: kpEnv.variables[name].value, valueFrom: kpEnv.variables[name].valueFrom });
}
var envFrom: k8s.EnvFromSource[] = [];
for (const idx in kpEnv.sources) {
const source = kpEnv.sources[idx];
envFrom.push(source._toKube());
}
// for (const source in kpEnv.sources) {
// envFrom.push({ configMapRef: source.configMap, prefix: source.prefix, secretRef: source.sec });
// }
var ploneContainerSpec: k8s.Container = {
name: id + '-container', // here the namespaced name shold be used, but how?
image: image.image,
Expand All @@ -138,8 +140,8 @@ export class PloneDeployment extends Construct {
memory: k8s.Quantity.fromString(options.limitMemory ?? '1Gi'),
},
},
livenessProbe: options.livenessProbe ?? { },
readinessProbe: options.readinessProbe ?? { },
livenessProbe: options.livenessProbe ?? {},
readinessProbe: options.readinessProbe ?? {},
};
const deploymentOptions: k8s.KubeDeploymentProps = {
metadata: {
Expand Down
127 changes: 127 additions & 0 deletions test/__snapshots__/deployment.test.ts.snap

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

33 changes: 33 additions & 0 deletions test/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,36 @@ test('with-environment', () => {
// THEN
expect(Testing.synth(chart)).toMatchSnapshot();
});

test('with-environment-valueFrom', () => {
// GIVEN
const app = Testing.app();
const chart = new Chart(app, 'plone');

// WHEN
const env = new kplus.Env([], { MY_ENV: { valueFrom: { secretKeyRef: { name: 'my-secret', key: 'MY_ENV_SECRET' } } } });
new PloneDeployment(chart, 'with_environment_valueFrom', {
port: 3000,
environment: env,
});

// THEN
expect(Testing.synth(chart)).toMatchSnapshot();
});

test('with-environment-from-secret', () => {
// GIVEN
const app = Testing.app();
const chart = new Chart(app, 'plone');

// WHEN
const envfrom = kplus.Env.fromSecret(new kplus.Secret(chart, 'foo'));
const env = new kplus.Env([envfrom], {});
new PloneDeployment(chart, 'with_environment_secret', {
port: 3000,
environment: env,
});

// THEN
expect(Testing.synth(chart)).toMatchSnapshot();
});

0 comments on commit a9ac5e2

Please sign in to comment.