Skip to content

Commit 3fb1a5f

Browse files
fix: resolve #2827 — CDK8s+: Support headless services without ports
Fixes #2827 Signed-off-by: tudragon154203 <76395825+tudragon154203@users.noreply.github.com>
1 parent 8992fdf commit 3fb1a5f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

test/cdk8s-plus-XX/test.service.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { App, Chart, Service, Testing } from '../../src';
2+
3+
describe('service', () => {
4+
test('allows headless service without ports', () => {
5+
const app = new App();
6+
const chart = new Chart(app, 'test');
7+
8+
new Service(chart, 'Service', {
9+
clusterIP: 'None',
10+
selector: {
11+
app: 'foo',
12+
},
13+
});
14+
15+
const manifests = Testing.synth(chart);
16+
const service = manifests.find((m) => m.kind === 'Service') as any;
17+
18+
expect(service).toMatchObject({
19+
spec: {
20+
clusterIP: 'None',
21+
},
22+
});
23+
expect(service.spec.ports ?? []).toEqual([]);
24+
});
25+
26+
test('requires a port for non-headless services', () => {
27+
const app = new App();
28+
const chart = new Chart(app, 'test');
29+
30+
expect(() => {
31+
new Service(chart, 'Service', {
32+
selector: {
33+
app: 'foo',
34+
},
35+
});
36+
37+
Testing.synth(chart);
38+
}).toThrow(/port/i);
39+
});
40+
});

0 commit comments

Comments
 (0)