diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dfd15b..de39032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,20 @@ +## 2.1.0 +**Maintainer**: Raffael Sahli \ +**Date**: Tue Mar 19 2019 16:01:20 CET 2019 + +* [FEATURE] Change servicegroup definition #17 + + ## 2.0.1 **Maintainer**: Raffael Sahli \ -**Date**: Thu 21 Feb 2019 17:14:20 PM ET +**Date**: Thu Feb 21 17:14:20 CET 2019 * [FIX] none string environment variables not parsed correctly into config #10 ## 2.0.0 **Maintainer**: Raffael Sahli \ -**Date**: Thu 21 Feb 2019 14:28:20 PM ET +**Date**: Thu Feb 21 14:28:20 PM CET 2019 * [FIX] Fixes "(node:25116) UnhandledPromiseRejectionWarning: TypeError: result is not iterable" due error response from icinga * [FIX] Better error handling and catching various uncaught promises @@ -31,7 +38,7 @@ ## 1.0.1 **Maintainer**: Raffael Sahli \ -**Date**: Fri 01 Jun 2018 01:18:20 PM CEST +**Date**: Fri Jun 01 01:18:20 CEST 2018 * [FIX] fixed protocol (service ports.protocol) lowercase * [CHANGE] config logger.level => log.level diff --git a/README.md b/README.md index 1300268..29332f0 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ You may use the following annotations: | `kube-icinga/check_command` | Use a custom icinga check command. | | `kube-icinga/host` | Use a custom hostname (to which icinga host a service gets bound to). | | `kube-icinga/template` | Use a custom icinga template. | -| `kube-icinga/definition` | JSON encoded icinga definiton which may contain advanced icinga options and gets merged with the defaults. | +| `kube-icinga/definition` | JSON encoded icinga definition which may contain advanced icinga options and gets merged with the defaults. | ```yaml @@ -199,43 +199,44 @@ List of configurable values: |`icinga.apiUser`|Icinga2 API username|`ICINGA_API_USERNAME`|`admin`| |`icinga.apiPassword`|Icinga2 API password|`ICINGA_API_PASSWORD`|`admin`| |`cleanup`|If `true` all kubernetes objects get removed from icinga at startup|`CLEANUP`|`true`| +|`kubernetes.namespaces.serviceGroupDefinition`|You may overwrite specific attributes of the icinga [service group definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#servicegroup). |`KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION`|'{}'| |`kubernetes.nodes.discover`|Deploy kubernetes node objects|`KUBERNETES_NODES_DISCOVER`|`true`| -|`kubernetes.nodes.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_NODES_HOST_DEFINITION`|`{}`| +|`kubernetes.nodes.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_NODES_HOST_DEFINITION`|`{}`| |`kubernetes.nodes.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_NODES_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.ingresses.discover`|Deploy kubernetes ingress objects|`KUBERNETES_INGRESSES_DISCOVER`|`true`| |`kubernetes.ingresses.hostName`|The name of the icinga host object to attach services to (May also be null to enabled host object provisioning)|`KUBERNETES_INGRESSES_HOSTNAME`|`kubernetes-ingresses`| -|`kubernetes.ingresses.serviceDefinition`|You may overwrite specific attributes of the icinga [service definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_INGRESSES_SERVICE_DEFINITION`|'{}'| -|`kubernetes.ingresses.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_INGRESSES_SERVICE_DEFINITION`|`{}`| +|`kubernetes.ingresses.serviceDefinition`|You may overwrite specific attributes of the icinga [service definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_INGRESSES_SERVICE_DEFINITION`|'{}'| +|`kubernetes.ingresses.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_INGRESSES_SERVICE_DEFINITION`|`{}`| |`kubernetes.ingresses.serviceTemplates`|Specify a list of icinga service templates (comma separated string if defined via env variable)|`KUBERNETES_INGRESSES_SERVICE_TEMPLATES`|`['generic-service']`| |`kubernetes.ingresses.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_INGRESSES_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.ingresses.applyServices`|Apply ingress paths as icinga services attached to the icinga ingress host|`KUBERNETES_INGRESSES_APPLYSERVICES`|`true`| |`kubernetes.ingresses.attachToNodes`|If `true` instead attaching port services to a dummy host object `metadata.name` all services get attached to each kubernetes worker node!|`KUBERNETES_INGRESSES_ATTACHTONODES`|`false`| |`kubernetes.volumes.discover`|Deploy kubernetes ingress objects|`KUBERNETES_VOLUMES_DISCOVER`|`true`| |`kubernetes.volumes.hostName`|The name of the icinga host object to attach services to (May also be null to enabled host object provisioning)|`KUBERNETES_VOLUMES_HOSTNAME`|`kubernetes-volumes`| -|`kubernetes.volumes.serviceDefinition`|You may overwrite specific attributes of the icinga [service definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_VOLUMES_SERVICE_DEFINITION`|'{}'| -|`kubernetes.volumes.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_VOLUMES_SERVICE_DEFINITION`|`{}`| +|`kubernetes.volumes.serviceDefinition`|You may overwrite specific attributes of the icinga [service definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_VOLUMES_SERVICE_DEFINITION`|'{}'| +|`kubernetes.volumes.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_VOLUMES_SERVICE_DEFINITION`|`{}`| |`kubernetes.volumes.serviceTemplates`|Specify a list of icinga service templates (comma separated string if defined via env variable)|`KUBERNETES_VOLUMES_SERVICE_TEMPLATES`|`['generic-service']`| |`kubernetes.volumes.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_VOLUMES_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.volumes.applyServices`|Apply volumes as icinga services attached to a icinga host object|`KUBERNETES_VOLUMES_APPLYSERVICES`|`true`| |`kubernetes.volumes.attachToNodes`|If `true` instead attaching port services to a dummy host object `metadata.name` all services get attached to each kubernetes worker node!|`KUBERNETES_VOLUMES_ATTACHTONODES`|`false`| |`kubernetes.services.ClusterIP.discover`|Deploy kubernetes service objects|`KUBERNETES_SERVICES_CLUSTERIP_DISCOVER`|`false`| |`kubernetes.services.ClusterIP.hostName`|The name of the icinga host object to attach services to (May also be null to enabled host object provisioning)|`KUBERNETES_SERVICES_CLUSTERIP_HOSTNAME`|`kubernetes-clusterip-services`| -|`kubernetes.services.ClusterIP.serviceDefinition`|You may overwrite specific attributes of the icinga [service definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_CLUSTERIP_SERVICE_DEFINITION`|`{}`| -|`kubernetes.services.ClusterIP.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_CLUSTERIP_HOST_DEFINITION`|`{}`| +|`kubernetes.services.ClusterIP.serviceDefinition`|You may overwrite specific attributes of the icinga [service definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_CLUSTERIP_SERVICE_DEFINITION`|`{}`| +|`kubernetes.services.ClusterIP.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_CLUSTERIP_HOST_DEFINITION`|`{}`| |`kubernetes.services.ClusterIP.serviceTemplates`|Specify a list of icinga service templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_CLUSTERIP_SERVICE_TEMPLATES`|`['generic-service']`| |`kubernetes.services.ClusterIP.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_CLUSTERIP_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.services.ClusterIP.applyServices`|URI of LDAP server|`KUBERNETES_SERVICES_CLUSTERIP_APPLYSERVICES`|`true`| |`kubernetes.services.NodePort.discover`|Deploy kubernetes service objects|`KUBERNETES_SERVICES_NODEPORT_DISCOVER`|`true`| -|`kubernetes.services.NodePort.serviceDefinition`|You may overwrite specific attributes of the icinga [service definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_SERVICE_DEFINITION`|`{}`| -|`kubernetes.services.NodePort.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_NODEPORT_HOST_DEFINITION`|`{}`| +|`kubernetes.services.NodePort.serviceDefinition`|You may overwrite specific attributes of the icinga [service definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_SERVICE_DEFINITION`|`{}`| +|`kubernetes.services.NodePort.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_NODEPORT_HOST_DEFINITION`|`{}`| |`kubernetes.services.NodePort.serviceTemplates`|Specify a list of icinga service templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_NODEPORT_SERVICE_TEMPLATES`|`['generic-service']`| |`kubernetes.services.NodePort.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_NODEPORT_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.services.NodePort.applyServices`|URI of LDAP server|`KUBERNETES_SERVICES_NODEPORT_APPLYSERVICES`|`true`| |`kubernetes.services.NodePort.hostName`|The name of the icinga host object to attach services to (May also be null to enabled host object provisioning)|`KUBERNETES_SERVICES_NODEPORT_HOSTNAME`|`kubernetes-nodeport-services`| |`kubernetes.services.LoadBalancer.discover`|Deploy kubernetes service objects|`KUBERNETES_SERVICES_LOADBALANCER_DISCOVER`|`true`| |`kubernetes.services.LoadBalancer.hostName`|The name of the icinga host object to attach services to (May also be null to enabled host object provisioning)|`KUBERNETES_SERVICES_LOADBALANCER_HOSTNAME`|`kubernetes-loadbalancer-services`| -|`kubernetes.services.LoadBalancer.serviceDefinition`|You may overwrite specific attributes of the icinga [service definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_LOADBALANCER_SERVICE_DEFINITION`|`{}`| -|`kubernetes.services.LoadBalancer.hostDefinition`|You may overwrite specific attributes of the icinga [host definiton](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_LOADBALANCER_HOST_DEFINITION`|`{}`| +|`kubernetes.services.LoadBalancer.serviceDefinition`|You may overwrite specific attributes of the icinga [service definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#service). |`KUBERNETES_SERVICES_LOADBALANCER_SERVICE_DEFINITION`|`{}`| +|`kubernetes.services.LoadBalancer.hostDefinition`|You may overwrite specific attributes of the icinga [host definition](https://www.icinga.com/docs/icinga2/latest/doc/09-object-types/#host).|`KUBERNETES_SERVICES_LOADBALANCER_HOST_DEFINITION`|`{}`| |`kubernetes.services.LoadBalancer.serviceTemplates`|Specify a list of icinga service templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_LOADBALANCER_SERVICE_TEMPLATES`|`['generic-service']`| |`kubernetes.services.LoadBalancer.hostTemplates`|Specify a list of host templates (comma separated string if defined via env variable)|`KUBERNETES_SERVICES_LOADBALANCER_HOST_TEMPLATES`|`['generic-host']`| |`kubernetes.services.LoadBalancer.applyServices`|URI of LDAP server|`KUBERNETES_SERVICES_LOADBALANCER_APPLYSERVICES`|`true`| diff --git a/config.json b/config.json index 8e4e781..decfcf1 100644 --- a/config.json +++ b/config.json @@ -10,6 +10,9 @@ "apiPassword": "kube-icinga" }, "kubernetes": { + "namespaces": { + "serviceGroupDefinition": {} + }, "nodes": { "discover": true, "hostDefinition": {}, diff --git a/src/config.ts b/src/config.ts index e16ff66..3ea0e2f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -66,6 +66,7 @@ const config = { hostName: stringParse('KUBERNETES_INGRESSES_HOSTNAME', defaultConfig.kubernetes.ingresses.hostName), applyServices: jsonParse('KUBERNETES_INGRESSES_APPLYSERVICES', defaultConfig.kubernetes.ingresses.applyServices), serviceDefinition: jsonParse('KUBERNETES_INGRESSES_SERVICE_DEFINITION', defaultConfig.kubernetes.ingresses.serviceDefinition), + serviceGroupDefinition: jsonParse('KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION', defaultConfig.kubernetes.namespaces.serviceGroupDefinition), hostDefinition: jsonParse('KUBERNETES_INGRESSES_HOST_DEFINITION', defaultConfig.kubernetes.ingresses.hostDefinition), serviceTemplates: split('KUBERNETES_INGRESSES_SERVICE_TEMPLATES', defaultConfig.kubernetes.ingresses.serviceTemplates), hostTemplates: split('KUBERNETES_INGRESSES_HOST_TEMPLATES', defaultConfig.kubernetes.ingresses.hostTemplates), @@ -76,6 +77,7 @@ const config = { hostName: stringParse('KUBERNETES_VOLUMES_HOSTNAME', defaultConfig.kubernetes.volumes.hostName), applyServices: jsonParse('KUBERNETES_VOLUMES_APPLYSERVICES', defaultConfig.kubernetes.volumes.applyServices), serviceDefinition: jsonParse('KUBERNETES_VOLUMES_SERVICE_DEFINITION', defaultConfig.kubernetes.volumes.serviceDefinition), + serviceGroupDefinition: jsonParse('KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION', defaultConfig.kubernetes.namespaces.serviceGroupDefinition), hostDefinition: jsonParse('KUBERNETES_VOLUMES_HOST_DEFINITION', defaultConfig.kubernetes.volumes.hostDefinition), serviceTemplates: split('KUBERNETES_VOLUMES_SERVICE_TEMPLATES', defaultConfig.kubernetes.volumes.serviceTemplates), hostTemplates: split('KUBERNETES_VOLUMES_HOST_TEMPLATES', defaultConfig.kubernetes.volumes.hostTemplates), @@ -87,6 +89,7 @@ const config = { hostName: stringParse('KUBERNETES_SERVICES_CLUSTERIP_HOSTNAME', defaultConfig.kubernetes.services.ClusterIP.hostName), applyServices: jsonParse('KUBERNETES_SERVICES_CLUSTERIP_APPLYSERVICES', defaultConfig.kubernetes.services.ClusterIP.applyServices), serviceDefinition: jsonParse('KUBERNETES_SERVICES_CLUSTERIP_SERVICE_DEFINITION', defaultConfig.kubernetes.services.ClusterIP.serviceDefinition), + serviceGroupDefinition: jsonParse('KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION', defaultConfig.kubernetes.namespaces.serviceGroupDefinition), hostDefinition: jsonParse('KUBERNETES_SERVICES_CLUSTERIP_HOST_DEFINITION', defaultConfig.kubernetes.services.ClusterIP.hostDefinition), serviceTemplates: split('KUBERNETES_SERVICES_CLUSTERIP_SERVICE_TEMPLATES', defaultConfig.kubernetes.services.ClusterIP.serviceTemplates), hostTemplates: split('KUBERNETES_SERVICES_CLUSTERIP_HOST_TEMPLATES', defaultConfig.kubernetes.services.ClusterIP.hostTemplates), @@ -96,6 +99,7 @@ const config = { hostName: jsonParse('KUBERNETES_SERVICES_NODEPORT_HOSTNAME', defaultConfig.kubernetes.services.NodePort.hostName), applyServices: jsonParse('KUBERNETES_SERVICES_NODEPORT_APPLYSERVICES', defaultConfig.kubernetes.services.NodePort.applyServices), serviceDefinition: jsonParse('KUBERNETES_SERVICES_NODEPORT_SERVICE_DEFINITION', defaultConfig.kubernetes.services.NodePort.serviceDefinition), + serviceGroupDefinition: jsonParse('KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION', defaultConfig.kubernetes.namespaces.serviceGroupDefinition), hostDefinition: jsonParse('KUBERNETES_SERVICES_NODEPORT_HOST_DEFINITION', defaultConfig.kubernetes.services.NodePort.hostDefinition), serviceTemplates: split('KUBERNETES_SERVICES_NODEPORT_SERVICE_TEMPLATES', defaultConfig.kubernetes.services.NodePort.serviceTemplates), hostTemplates: split('KUBERNETES_SERVICES_NODEPORT_HOST_TEMPLATES', defaultConfig.kubernetes.services.NodePort.hostTemplates), @@ -105,6 +109,7 @@ const config = { hostName: stringParse('KUBERNETES_SERVICES_LOADBALANCER_HOSTNAME', defaultConfig.kubernetes.services.LoadBalancer.hostName), applyServices: jsonParse('KUBERNETES_SERVICES_LOADBALANCER_APPLYSERVICES', defaultConfig.kubernetes.services.LoadBalancer.applyServices), serviceDefinition: jsonParse('KUBERNETES_SERVICES_LOADBALANCER_SERVICE_DEFINITION', defaultConfig.kubernetes.services.LoadBalancer.serviceDefinition), + serviceGroupDefinition: jsonParse('KUBERNETES_NAMESPACES_SERVICEGROUP_DEFINITION', defaultConfig.kubernetes.namespaces.serviceGroupDefinition), hostDefinition: jsonParse('KUBERNETES_SERVICES_LOADBALANCER_HOST_DEFINITION', defaultConfig.kubernetes.services.LoadBalancer.hostDefinition), serviceTemplates: split('KUBERNETES_SERVICES_LOADBALANCER_SERVICE_TEMPLATES', defaultConfig.kubernetes.services.LoadBalancer.serviceTemplates), hostTemplates: split('KUBERNETES_SERVICES_LOADBALANCER_HOST_TEMPLATES', defaultConfig.kubernetes.services.LoadBalancer.hostTemplates), diff --git a/src/icinga.ts b/src/icinga.ts index 91c6d7b..3cbbdfb 100644 --- a/src/icinga.ts +++ b/src/icinga.ts @@ -93,16 +93,20 @@ export default class Icinga { /** * Create service group */ - public applyServiceGroup(name: string): Promise { + public applyServiceGroup(name: string, definition={}): Promise { + let group = { + attrs: definition + }; + return new Promise((resolve, reject) => { - this.logger.info(`apply service group ${name} aka kubernetes namespace`); + this.logger.info(`apply service group ${name} aka kubernetes namespace`, {serviceGroup: group}); this.icingaClient.getServiceGroup(name, (err, result) => { if (err) { if (err.Statuscode == '404') { this.logger.info(`service group ${name} on monitoring was not found, create one`, {error: err}); - this.icingaClient.createServiceGroup(name, name, [], (err, result) => { + this.icingaClient.createServiceGroupCustom(JSON.stringify(group), name, (err, result) => { if (err) { this.logger.error(`failed create service group ${name}`, {error: err}); resolve(false); diff --git a/src/kube/ingress.ts b/src/kube/ingress.ts index c2786f9..72389f6 100644 --- a/src/kube/ingress.ts +++ b/src/kube/ingress.ts @@ -10,6 +10,7 @@ interface IngressOptions { attachToNodes?: boolean; hostDefinition?: object; serviceDefinition?: object; + serviceGroupDefinition?: object; hostTemplates?: string[]; serviceTemplates?: string[]; } @@ -27,6 +28,7 @@ export default class Ingress extends Resource { attachToNodes: false, hostDefinition: {}, serviceDefinition: {}, + serviceGroupDefinition: {}, hostTemplates: [], serviceTemplates: [], }; @@ -86,9 +88,9 @@ export default class Ingress extends Resource { let service = this.prepareResource(definition); let templates = this.options.serviceTemplates; templates = templates.concat(this.prepareTemplates(definition)); - + if (this.options.applyServices) { - await this.icinga.applyServiceGroup(definition.metadata.namespace); + await this.icinga.applyServiceGroup(definition.metadata.namespace, this.options.serviceGroupDefinition); for (const spec of definition.spec.rules) { for (const path of spec.http.paths) { diff --git a/src/kube/service.ts b/src/kube/service.ts index cf1029a..193ea3a 100644 --- a/src/kube/service.ts +++ b/src/kube/service.ts @@ -9,6 +9,7 @@ interface ServiceTypeOptions { applyServices?: boolean; hostDefinition?: any; serviceDefinition?: any; + serviceGroupDefinition?: any; hostTemplates?: string[]; serviceTemplates?: string[]; } @@ -26,6 +27,7 @@ const defaults: ServiceOptions = { applyServices: true, hostDefinition: {}, serviceDefinition: {}, + serviceGroupDefinition: {}, hostTemplates: [], serviceTemplates: [], }, @@ -35,6 +37,7 @@ const defaults: ServiceOptions = { applyServices: true, hostDefinition: {}, serviceDefinition: {}, + serviceGroupDefinition: {}, hostTemplates: [], serviceTemplates: [], }, @@ -44,6 +47,7 @@ const defaults: ServiceOptions = { applyServices: true, hostDefinition: {}, serviceDefinition: {}, + serviceGroupDefinition: {}, hostTemplates: [], serviceTemplates: [], }, @@ -133,7 +137,7 @@ export default class Service extends Resource { } if (options.applyServices) { - await this.icinga.applyServiceGroup(definition.metadata.namespace); + await this.icinga.applyServiceGroup(definition.metadata.namespace, options.serviceGroupDefinition); for (const servicePort of definition.spec.ports) { let port = JSON.parse(JSON.stringify(service)); diff --git a/src/kube/volume.ts b/src/kube/volume.ts index 690e0e5..c61d048 100644 --- a/src/kube/volume.ts +++ b/src/kube/volume.ts @@ -10,6 +10,7 @@ interface VolumeOptions { hostName?: string; hostDefinition?: object; serviceDefinition?: object; + serviceGroupDefinition?: object; hostTemplates?: string[]; serviceTemplates?: string[]; } @@ -27,6 +28,7 @@ export default class Volume extends Resource { hostName: 'kubernetes-volumes', hostDefinition: {}, serviceDefinition: {}, + serviceGroupDefinition: {}, hostTemplates: [], serviceTemplates: [], }; @@ -89,7 +91,7 @@ export default class Volume extends Resource { if (definition.spec.claimRef.namespace) { groups.push(definition.spec.claimRef.namespace); - await this.icinga.applyServiceGroup(definition.spec.claimRef.namespace); + await this.icinga.applyServiceGroup(definition.spec.claimRef.namespace, this.options.serviceGroupDefinition); } let templates = this.options.serviceTemplates; diff --git a/tests/icinga.test.ts b/tests/icinga.test.ts index 35daf47..3105868 100644 --- a/tests/icinga.test.ts +++ b/tests/icinga.test.ts @@ -109,15 +109,15 @@ describe('icinga', () => { describe('apply service group', () => { it('icinga service group does exists', async () => { - IcingaApi.createServiceGroup = jest.fn(); + IcingaApi.createServiceGroupCustom = jest.fn(); IcingaApi.getServiceGroup = jest.fn() .mockImplementation((ServiceGroup, cb) => cb(null, {foo: "bar"})); - await expect(icinga.applyServiceGroup('foobar')).resolves.toEqual(true); + await expect(icinga.applyServiceGroup('foobar', {zone: "foo"})).resolves.toEqual(true); const calls = IcingaApi.getServiceGroup.mock.calls; expect(calls.length).toBe(1); expect(calls[0][0]).toBe('foobar'); - expect(IcingaApi.createServiceGroup.mock.calls.length).toBe(0); + expect(IcingaApi.createServiceGroupCustom.mock.calls.length).toBe(0); }); it('get service group error response', async () => { @@ -131,42 +131,43 @@ describe('icinga', () => { const calls = IcingaApi.getServiceGroup.mock.calls; expect(calls.length).toBe(1); expect(calls[0][0]).toBe('foobar'); - expect(IcingaApi.createServiceGroup.mock.calls.length).toBe(0); + expect(IcingaApi.createServiceGroupCustom.mock.calls.length).toBe(0); }); it('add new service group', async () => { - IcingaApi.createServiceGroup = jest.fn() - .mockImplementation((ServiceGroup, display_name, data, cb) => cb(null, {foo: "bar"})); + IcingaApi.createServiceGroupCustom = jest.fn() + .mockImplementation((ServiceGroup, name, cb) => cb(null, {foo: "bar"})); IcingaApi.getServiceGroup = jest.fn() .mockImplementation((ServiceGroup, cb) => cb({Statuscode: 404}, null)); - await expect(icinga.applyServiceGroup('foobar')).resolves.toEqual(true); + await expect(icinga.applyServiceGroup('foobar', {zone: "foo"})).resolves.toEqual(true); var calls = IcingaApi.getServiceGroup.mock.calls; expect(calls.length).toBe(1); expect(calls[0][0]).toBe('foobar'); - calls = IcingaApi.createServiceGroup.mock.calls; + calls = IcingaApi.createServiceGroupCustom.mock.calls; expect(calls.length).toBe(1); - expect(calls[0][0]).toBe('foobar'); + expect(calls[0][1]).toBe('foobar'); + expect(calls[0][0]).toBe("{\"attrs\":{\"zone\":\"foo\"}}"); }); it('add new service group error response', async () => { - IcingaApi.createServiceGroup = jest.fn() - .mockImplementation((ServiceGroup, display_name, data, cb) => cb({Statuscode: 500}, null)); + IcingaApi.createServiceGroupCustom = jest.fn() + .mockImplementation((ServiceGroup, name, cb) => cb({Statuscode: 500}, null)); IcingaApi.getServiceGroup = jest.fn() .mockImplementation((ServiceGroup, cb) => cb({Statuscode: 404}, null)); - await expect(icinga.applyServiceGroup('foobar')).resolves.toEqual(false); + await expect(icinga.applyServiceGroup('foobar', {zone: "foo"})).resolves.toEqual(false); var calls = IcingaApi.getServiceGroup.mock.calls; expect(calls.length).toBe(1); expect(calls[0][0]).toBe('foobar'); - calls = IcingaApi.createServiceGroup.mock.calls; + calls = IcingaApi.createServiceGroupCustom.mock.calls; expect(calls.length).toBe(1); - expect(calls[0][0]).toBe('foobar'); + expect(calls[0][1]).toBe('foobar'); }); });