Skip to content

Commit 8a8623e

Browse files
feat: kong tcp ingress (#1)
1 parent e368e58 commit 8a8623e

File tree

4 files changed

+302
-0
lines changed

4 files changed

+302
-0
lines changed

API.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,105 @@
22

33
## Constructs <a name="Constructs" id="Constructs"></a>
44

5+
### KongTcpIngress <a name="KongTcpIngress" id="cdk8s-various.KongTcpIngress"></a>
6+
7+
#### Initializers <a name="Initializers" id="cdk8s-various.KongTcpIngress.Initializer"></a>
8+
9+
```typescript
10+
import { KongTcpIngress } from 'cdk8s-various'
11+
12+
new KongTcpIngress(scope: Construct, name: string, opts: KongTcpOptions)
13+
```
14+
15+
| **Name** | **Type** | **Description** |
16+
| --- | --- | --- |
17+
| <code><a href="#cdk8s-various.KongTcpIngress.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | *No description.* |
18+
| <code><a href="#cdk8s-various.KongTcpIngress.Initializer.parameter.name">name</a></code> | <code>string</code> | *No description.* |
19+
| <code><a href="#cdk8s-various.KongTcpIngress.Initializer.parameter.opts">opts</a></code> | <code><a href="#cdk8s-various.KongTcpOptions">KongTcpOptions</a></code> | *No description.* |
20+
21+
---
22+
23+
##### `scope`<sup>Required</sup> <a name="scope" id="cdk8s-various.KongTcpIngress.Initializer.parameter.scope"></a>
24+
25+
- *Type:* constructs.Construct
26+
27+
---
28+
29+
##### `name`<sup>Required</sup> <a name="name" id="cdk8s-various.KongTcpIngress.Initializer.parameter.name"></a>
30+
31+
- *Type:* string
32+
33+
---
34+
35+
##### `opts`<sup>Required</sup> <a name="opts" id="cdk8s-various.KongTcpIngress.Initializer.parameter.opts"></a>
36+
37+
- *Type:* <a href="#cdk8s-various.KongTcpOptions">KongTcpOptions</a>
38+
39+
---
40+
41+
#### Methods <a name="Methods" id="Methods"></a>
42+
43+
| **Name** | **Description** |
44+
| --- | --- |
45+
| <code><a href="#cdk8s-various.KongTcpIngress.toString">toString</a></code> | Returns a string representation of this construct. |
46+
47+
---
48+
49+
##### `toString` <a name="toString" id="cdk8s-various.KongTcpIngress.toString"></a>
50+
51+
```typescript
52+
public toString(): string
53+
```
54+
55+
Returns a string representation of this construct.
56+
57+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
58+
59+
| **Name** | **Description** |
60+
| --- | --- |
61+
| <code><a href="#cdk8s-various.KongTcpIngress.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
62+
63+
---
64+
65+
##### ~~`isConstruct`~~ <a name="isConstruct" id="cdk8s-various.KongTcpIngress.isConstruct"></a>
66+
67+
```typescript
68+
import { KongTcpIngress } from 'cdk8s-various'
69+
70+
KongTcpIngress.isConstruct(x: any)
71+
```
72+
73+
Checks if `x` is a construct.
74+
75+
###### `x`<sup>Required</sup> <a name="x" id="cdk8s-various.KongTcpIngress.isConstruct.parameter.x"></a>
76+
77+
- *Type:* any
78+
79+
Any object.
80+
81+
---
82+
83+
#### Properties <a name="Properties" id="Properties"></a>
84+
85+
| **Name** | **Type** | **Description** |
86+
| --- | --- | --- |
87+
| <code><a href="#cdk8s-various.KongTcpIngress.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
88+
89+
---
90+
91+
##### `node`<sup>Required</sup> <a name="node" id="cdk8s-various.KongTcpIngress.property.node"></a>
92+
93+
```typescript
94+
public readonly node: Node;
95+
```
96+
97+
- *Type:* constructs.Node
98+
99+
The tree node.
100+
101+
---
102+
103+
5104
### SecurityGroupPolicy <a name="SecurityGroupPolicy" id="cdk8s-various.SecurityGroupPolicy"></a>
6105

7106
#### Initializers <a name="Initializers" id="cdk8s-various.SecurityGroupPolicy.Initializer"></a>
@@ -103,6 +202,123 @@ The tree node.
103202

104203
## Structs <a name="Structs" id="Structs"></a>
105204

205+
### KongTcpBackend <a name="KongTcpBackend" id="cdk8s-various.KongTcpBackend"></a>
206+
207+
#### Initializer <a name="Initializer" id="cdk8s-various.KongTcpBackend.Initializer"></a>
208+
209+
```typescript
210+
import { KongTcpBackend } from 'cdk8s-various'
211+
212+
const kongTcpBackend: KongTcpBackend = { ... }
213+
```
214+
215+
#### Properties <a name="Properties" id="Properties"></a>
216+
217+
| **Name** | **Type** | **Description** |
218+
| --- | --- | --- |
219+
| <code><a href="#cdk8s-various.KongTcpBackend.property.serviceName">serviceName</a></code> | <code>string</code> | *No description.* |
220+
| <code><a href="#cdk8s-various.KongTcpBackend.property.servicePort">servicePort</a></code> | <code>number</code> | *No description.* |
221+
222+
---
223+
224+
##### `serviceName`<sup>Required</sup> <a name="serviceName" id="cdk8s-various.KongTcpBackend.property.serviceName"></a>
225+
226+
```typescript
227+
public readonly serviceName: string;
228+
```
229+
230+
- *Type:* string
231+
232+
---
233+
234+
##### `servicePort`<sup>Required</sup> <a name="servicePort" id="cdk8s-various.KongTcpBackend.property.servicePort"></a>
235+
236+
```typescript
237+
public readonly servicePort: number;
238+
```
239+
240+
- *Type:* number
241+
242+
---
243+
244+
### KongTcpOptions <a name="KongTcpOptions" id="cdk8s-various.KongTcpOptions"></a>
245+
246+
#### Initializer <a name="Initializer" id="cdk8s-various.KongTcpOptions.Initializer"></a>
247+
248+
```typescript
249+
import { KongTcpOptions } from 'cdk8s-various'
250+
251+
const kongTcpOptions: KongTcpOptions = { ... }
252+
```
253+
254+
#### Properties <a name="Properties" id="Properties"></a>
255+
256+
| **Name** | **Type** | **Description** |
257+
| --- | --- | --- |
258+
| <code><a href="#cdk8s-various.KongTcpOptions.property.annotations">annotations</a></code> | <code>{[ key: string ]: string}</code> | *No description.* |
259+
| <code><a href="#cdk8s-various.KongTcpOptions.property.rules">rules</a></code> | <code><a href="#cdk8s-various.KongTcpRule">KongTcpRule</a>[]</code> | *No description.* |
260+
261+
---
262+
263+
##### `annotations`<sup>Optional</sup> <a name="annotations" id="cdk8s-various.KongTcpOptions.property.annotations"></a>
264+
265+
```typescript
266+
public readonly annotations: {[ key: string ]: string};
267+
```
268+
269+
- *Type:* {[ key: string ]: string}
270+
271+
---
272+
273+
##### `rules`<sup>Optional</sup> <a name="rules" id="cdk8s-various.KongTcpOptions.property.rules"></a>
274+
275+
```typescript
276+
public readonly rules: KongTcpRule[];
277+
```
278+
279+
- *Type:* <a href="#cdk8s-various.KongTcpRule">KongTcpRule</a>[]
280+
281+
---
282+
283+
### KongTcpRule <a name="KongTcpRule" id="cdk8s-various.KongTcpRule"></a>
284+
285+
#### Initializer <a name="Initializer" id="cdk8s-various.KongTcpRule.Initializer"></a>
286+
287+
```typescript
288+
import { KongTcpRule } from 'cdk8s-various'
289+
290+
const kongTcpRule: KongTcpRule = { ... }
291+
```
292+
293+
#### Properties <a name="Properties" id="Properties"></a>
294+
295+
| **Name** | **Type** | **Description** |
296+
| --- | --- | --- |
297+
| <code><a href="#cdk8s-various.KongTcpRule.property.backend">backend</a></code> | <code><a href="#cdk8s-various.KongTcpBackend">KongTcpBackend</a></code> | *No description.* |
298+
| <code><a href="#cdk8s-various.KongTcpRule.property.port">port</a></code> | <code>number</code> | *No description.* |
299+
300+
---
301+
302+
##### `backend`<sup>Required</sup> <a name="backend" id="cdk8s-various.KongTcpRule.property.backend"></a>
303+
304+
```typescript
305+
public readonly backend: KongTcpBackend;
306+
```
307+
308+
- *Type:* <a href="#cdk8s-various.KongTcpBackend">KongTcpBackend</a>
309+
310+
---
311+
312+
##### `port`<sup>Required</sup> <a name="port" id="cdk8s-various.KongTcpRule.property.port"></a>
313+
314+
```typescript
315+
public readonly port: number;
316+
```
317+
318+
- *Type:* number
319+
320+
---
321+
106322
### SecurityGroupPolicyOptions <a name="SecurityGroupPolicyOptions" id="cdk8s-various.SecurityGroupPolicyOptions"></a>
107323

108324
#### Initializer <a name="Initializer" id="cdk8s-various.SecurityGroupPolicyOptions.Initializer"></a>

src/index.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface SecurityGroupPolicyOptions {
66
readonly securityGroupIds?: string[];
77
}
88

9+
910
export class SecurityGroupPolicy extends Construct {
1011
constructor(scope: Construct, name: string, opts: SecurityGroupPolicyOptions) {
1112
super(scope, `${name}-sgp`);
@@ -27,3 +28,37 @@ export class SecurityGroupPolicy extends Construct {
2728
});
2829
}
2930
}
31+
32+
33+
export interface KongTcpOptions {
34+
readonly annotations?: Record<string, string>;
35+
readonly rules?: KongTcpRule[];
36+
}
37+
38+
export interface KongTcpRule {
39+
readonly backend: KongTcpBackend;
40+
readonly port: number;
41+
}
42+
43+
export interface KongTcpBackend {
44+
readonly serviceName: string;
45+
readonly servicePort: number;
46+
}
47+
48+
export class KongTcpIngress extends Construct {
49+
constructor(scope: Construct, name: string, opts: KongTcpOptions) {
50+
super(scope, name);
51+
52+
new ApiObject(this, 'ingress', {
53+
apiVersion: 'configuration.konghq.com/v1beta1',
54+
kind: 'TCPIngress',
55+
metadata: {
56+
name: name,
57+
annotations: opts.annotations,
58+
},
59+
spec: {
60+
rules: opts.rules,
61+
},
62+
});
63+
}
64+
}

test/__snapshots__/kongtcp.test.ts.snap

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/kongtcp.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Chart, Testing } from 'cdk8s';
2+
import { KongTcpIngress } from '../src/index';
3+
4+
test('sgp', () => {
5+
6+
const app = Testing.app();
7+
const chart = new Chart(app, 'test');
8+
9+
new KongTcpIngress(chart, 'test', {
10+
annotations: {
11+
'kubernetes.io/ingress.class': 'kong',
12+
},
13+
rules: [{
14+
port: 9000,
15+
backend: {
16+
servicePort: 8080,
17+
serviceName: 'test',
18+
},
19+
}],
20+
});
21+
22+
23+
expect(Testing.synth(chart)).toMatchSnapshot();
24+
});

0 commit comments

Comments
 (0)