From 9a2aae44e6c07af057020c180a0fc39478aaacf3 Mon Sep 17 00:00:00 2001 From: shackit Date: Wed, 18 Jul 2018 15:26:49 +0100 Subject: [PATCH] Adds reconnect logic to kube-ldap client --- README.md | 3 +++ src/app.js | 5 +++++ src/config.js | 3 +++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 0488f90..671504c 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,9 @@ List of configurable values: |`config.ldap.baseDn`|Base DN for LDAP search|`LDAP_BASEDN`|dc=example,dc=com| |`config.ldap.filter`|Filter for LDAP search|`LDAP_FILTER`|(uid=%s)| |`config.ldap.timeout`|Timeout for LDAP connections & operations (in seconds)|`LDAP_TIMEOUT`|0 (infinite for operations, OS default for connections)| +|`config.ldap.reconnectInitialDelay`|Seconds to wait before reconnecting|`LDAP_RECONN_INIT_DELAY`|100| +|`config.ldap.reconnectMaxDelay`|Maximum seconds to wait before reconnecting|`LDAP_RECONN_MAX_DELAY`|1000| +|`config.ldap.reconnectFailAfter`|Fail after number of retries|`LDAP_RECONN_FAIL_AFTER`|10| |`config.mapping.username`|Name of ldap attribute to be used as username in kubernetes TokenReview|`MAPPING_USERNAME`|uid| |`config.mapping.uid`|Name of ldap attribute to be used as uid in kubernetes TokenReview|`MAPPING_UID`|uid| |`config.mapping.groups`|Name of ldap attribute to be used for groups in kubernetes TokenReview|`MAPPING_GROUPS`|memberOf| diff --git a/src/app.js b/src/app.js index 4b28061..15f7e24 100644 --- a/src/app.js +++ b/src/app.js @@ -16,6 +16,11 @@ let ldapClient = new Client( url: config.ldap.uri, timeout: config.ldap.timeout * 1000, connectTimeout: config.ldap.timeout * 1000, + reconnect: { + initialDelay: config.ldap.reconnectInitialDelay, + maxDelay: config.ldap.reconnectMaxDelay, + failAfter: config.ldap.reconnectFailAfter + } }), config.ldap.baseDn, config.ldap.bindDn, diff --git a/src/config.js b/src/config.js index 549c92d..c16eea2 100644 --- a/src/config.js +++ b/src/config.js @@ -31,6 +31,9 @@ const getConfig = () => { baseDn: process.env.LDAP_BASEDN || 'dc=example,dc=com', filter: process.env.LDAP_FILTER || '(uid=%s)', timeout: parseInt(process.env.LDAP_TIMEOUT) || 0, + reconnectInitialDelay: parseInt(process.env.LDAP_RECONN_INIT_DELAY) || 100, + reconnectMaxDelay: parseInt(process.env.LDAP_RECONN_MAX_DELAY) || 1000, + reconnectFailAfter: parseInt(process.env.LDAP_RECONN_FAIL_AFTER) || 10, }, mapping: { username: process.env.MAPPING_USERNAME || 'uid',