Skip to content

Commit 90cf6b9

Browse files
committed
typescript strict
1 parent 77e82d5 commit 90cf6b9

File tree

15 files changed

+114
-523
lines changed

15 files changed

+114
-523
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [CHANGE] Upgrade to typescript 3.x / jest 24.x #22
1010
* [FIX] ClusterIP service check for UDP fails #20
1111
* [FIX] LoadBalancers services using node port instead of target port #21
12+
* [CHANGE] Enabled best pratcicts typescript compiler flags (strict, notnull, ..)
1213

1314

1415
## 2.0.1

docker-compose-dev.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ services:
88
hostname: icinga2
99
environment:
1010
- MYSQL_ROOT_PASSWORD=<password>
11-
- ICINGA2_FEATURE_GRAPHITE=1
1211
# Important:
1312
# keep the hostname graphite the same as
1413
# the name of the graphite docker-container
15-
- ICINGA2_FEATURE_GRAPHITE_HOST=graphite
16-
- ICINGA2_FEATURE_GRAPHITE_PORT=2003
17-
- ICINGA2_FEATURE_GRAPHITE_URL=http://graphite
18-
#- ICINGAWEB2_ADMIN_USER=icingaadmin
1914
#- ICINGAWEB2_ADMIN_PASS=icinga
2015
#- ICINGA2_USER_FULLNAME=Icinga2 Docker Monitoring Instance
2116
- DEFAULT_MYSQL_HOST=mysql
@@ -39,19 +34,9 @@ services:
3934
#- ./ssmtp/revaliases:/etc/ssmtp/revaliases:ro
4035
#- ./ssmtp/ssmtp.conf:/etc/ssmtp/ssmtp.conf:ro
4136
ports:
42-
- "80:80"
37+
- "81:80"
4338
- "443:443"
4439
- "5665:5665"
45-
graphite:
46-
image: graphiteapp/graphite-statsd:latest
47-
container_name: graphite
48-
restart: on-failure:5
49-
hostname: graphite
50-
volumes:
51-
- ./data/graphite/conf:/opt/graphite/conf
52-
- ./data/graphite/storage:/opt/graphite/storage
53-
- ./data/graphite/log/graphite:/var/log/graphite
54-
- ./data/graphite/log/carbon:/var/log/carbon
5540
mysql:
5641
image: mariadb:10.1
5742
environment:

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module 'icinga2-api';
2+
declare module 'json-stream';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kube-icinga",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Icinga2 autodiscovery service for kubernetes",
55
"main": "main.js",
66
"scripts": {

src/icinga.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class Icinga {
134134
/**
135135
* Create or update a new icinga host object
136136
*/
137-
public applyHost(name: string, definition: IcingaObject, templates: string[]=[]): Promise<boolean> {
137+
public applyHost(name: string, definition: IcingaObject={}, templates: string[]=[]): Promise<boolean> {
138138
let host = {
139139
attrs: definition,
140140
templates: templates,
@@ -171,7 +171,7 @@ export class Icinga {
171171
/**
172172
* Create or update an icinga service object
173173
*/
174-
public applyService(host: string, name: string, definition: IcingaObject, templates: string[]=[]): Promise<boolean> {
174+
public applyService(host: string, name: string, definition: IcingaObject={}, templates: string[]=[]): Promise<boolean> {
175175
let service = {
176176
attrs: definition,
177177
templates: templates,

src/kube/abstract.resource.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {Logger} from 'winston';
2-
import {Service as KubeService} from 'kubernetes-types/core/v1';
32

43
/**
54
* kubernetes hosts
65
*/
76
export default abstract class Resource {
87
protected logger: Logger;
98

9+
/**
10+
* Initialize kube handler with logger
11+
*/
1012
constructor(logger: Logger) {
1113
this.logger = logger;
1214
}
@@ -61,7 +63,7 @@ export default abstract class Resource {
6163
/**
6264
* Get annotations
6365
*/
64-
protected getAnnotations(definition: KubeService): { [key: string]: string } {
66+
protected getAnnotations(definition: any): { [key: string]: string } {
6567
if (definition.metadata && definition.metadata.annotations) {
6668
return definition.metadata.annotations;
6769
}
@@ -109,6 +111,7 @@ export default abstract class Resource {
109111

110112
if (object.type == 'ADDED' || object.type == 'MODIFIED') {
111113
this.prepareObject(object.object).catch((err) => {
114+
console.log(err);
112115
this.logger.error('failed to handle resource', {error: err});
113116
});
114117
}

src/kube/ingress.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ const DefaultOptions: IngressOptions = {
3535
export default class Ingress extends AbstractResource {
3636
protected icinga: Icinga;
3737
protected kubeNode: KubeNode;
38-
protected options = DefaultOptions;
38+
protected options: IngressOptions = DefaultOptions;
3939

4040
/**
4141
* kubernetes hosts
4242
*/
43-
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: IngressOptions = DefaultOptions) {
43+
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: any = DefaultOptions) {
4444
super(logger);
4545
this.logger = logger;
4646
this.icinga = icinga;
4747
this.kubeNode = kubeNode;
48-
this.options = Object.assign(this.options, options);
48+
this.options = Object.assign({}, this.options, options);
4949
}
5050

5151
/**
@@ -138,8 +138,10 @@ export default class Ingress extends AbstractResource {
138138
* Get hostname
139139
*/
140140
protected getHostname(definition: KubeIngress): string {
141-
if (definition.metadata!.annotations!['kube-icinga/host']) {
142-
return definition.metadata!.annotations!['kube-icinga/host'];
141+
let annotations = this.getAnnotations(definition);
142+
143+
if (annotations['kube-icinga/host']) {
144+
return annotations['kube-icinga/host'];
143145
} else if (this.options.hostName === null) {
144146
return this.escapeName(['ingress', definition.metadata!.namespace, definition.metadata!.name].join('-'));
145147
}

src/kube/node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const DefaultOptions: NodeOptions = {
2121
export default class Node extends Resource {
2222
protected icinga: Icinga;
2323
protected nodes: string[] = [];
24-
protected options = DefaultOptions;
24+
protected options: NodeOptions = DefaultOptions;
2525

2626
/**
2727
* kubernetes hosts
2828
*/
29-
constructor(logger: Logger, icinga: Icinga, options: NodeOptions = DefaultOptions) {
29+
constructor(logger: Logger, icinga: Icinga, options: any = DefaultOptions) {
3030
super(logger);
3131
this.icinga = icinga;
32-
this.options = Object.assign(this.options, options);
32+
this.options = Object.assign({}, this.options, options);
3333
}
3434

3535
/**

src/kube/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ const HEADLESS_ADDRESS = 'None';
7272
export default class Service extends AbstractResource {
7373
protected icinga: Icinga;
7474
protected kubeNode: KubeNode;
75-
protected options = DefaultOptions;
75+
protected options: ServiceOptions = DefaultOptions;
7676

7777
/**
7878
* kubernetes services
7979
*/
80-
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: ServiceOptions=DefaultOptions) {
80+
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: any =DefaultOptions) {
8181
super(logger);
8282
this.icinga = icinga;
8383
let clone = JSON.parse(JSON.stringify(DefaultOptions));
@@ -289,7 +289,7 @@ export default class Service extends AbstractResource {
289289
stream.on('data', async (object: any) => {
290290
this.logger.debug('received kubernetes service resource', {object});
291291

292-
if (this.getServiceAddress(object.obect) === HEADLESS_ADDRESS) {
292+
if (this.getServiceAddress(object.object) === HEADLESS_ADDRESS) {
293293
this.logger.info('skip headless service object (use pod provisioning instead)', {object: object});
294294
return false;
295295
}

src/kube/volume.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ const DefaultOptions: VolumeOptions = {
3535
export default class Volume extends AbstractResource {
3636
protected icinga: Icinga;
3737
protected kubeNode: KubeNode;
38-
protected options = DefaultOptions;
38+
protected options: VolumeOptions = DefaultOptions;
3939

4040
/**
4141
* kubernetes hosts
4242
*/
43-
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: VolumeOptions = DefaultOptions) {
43+
constructor(logger: Logger, kubeNode: KubeNode, icinga: Icinga, options: any = DefaultOptions) {
4444
super(logger);
4545
this.logger = logger;
4646
this.icinga = icinga;
4747
this.kubeNode = kubeNode;
48-
this.options = Object.assign(this.options, options);
48+
this.options = Object.assign({}, this.options, options);
4949
}
5050

5151
/**
@@ -125,8 +125,10 @@ export default class Volume extends AbstractResource {
125125
* Get hostname
126126
*/
127127
protected getHostname(definition: PersistentVolume): string {
128-
if (definition.metadata!.annotations!['kube-icinga/host']) {
129-
return definition.metadata!.annotations!['kube-icinga/host'];
128+
let annotations = this.getAnnotations(definition);
129+
130+
if (annotations['kube-icinga/host']) {
131+
return annotations['kube-icinga/host'];
130132
} else if (this.options.hostName === null) {
131133
return this.escapeName(['volume', definition.metadata!.name].join('-'));
132134
}

0 commit comments

Comments
 (0)