Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis committed Mar 19, 2019
1 parent e47fdbb commit c0f15e2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 36 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
## 2.1.0
**Maintainer**: Raffael Sahli <[email protected]>\
**Date**: Tue Mar 19 2019 16:01:20 CET 2019

* [FEATURE] Change servicegroup definition #17


## 2.0.1
**Maintainer**: Raffael Sahli <[email protected]>\
**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 <[email protected]>\
**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
Expand All @@ -31,7 +38,7 @@

## 1.0.1
**Maintainer**: Raffael Sahli <[email protected]>\
**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
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`|
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"apiPassword": "kube-icinga"
},
"kubernetes": {
"namespaces": {
"serviceGroupDefinition": {}
},
"nodes": {
"discover": true,
"hostDefinition": {},
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
10 changes: 7 additions & 3 deletions src/icinga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@ export default class Icinga {
/**
* Create service group
*/
public applyServiceGroup(name: string): Promise<boolean> {
public applyServiceGroup(name: string, definition={}): Promise<boolean> {
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);
Expand Down
6 changes: 4 additions & 2 deletions src/kube/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface IngressOptions {
attachToNodes?: boolean;
hostDefinition?: object;
serviceDefinition?: object;
serviceGroupDefinition?: object;
hostTemplates?: string[];
serviceTemplates?: string[];
}
Expand All @@ -27,6 +28,7 @@ export default class Ingress extends Resource {
attachToNodes: false,
hostDefinition: {},
serviceDefinition: {},
serviceGroupDefinition: {},
hostTemplates: [],
serviceTemplates: [],
};
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit c0f15e2

Please sign in to comment.