Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit 9441216

Browse files
authored
feat: allow disabling of interval polling (#211)
1 parent fd7dcb3 commit 9441216

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

bin/daemon.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {
2222
logger,
2323
metricsPort,
2424
pollerIntervalMilliseconds,
25+
pollingDisabled,
2526
rolePermittedAnnotation
2627
} = require('../config')
2728

@@ -49,6 +50,7 @@ async function main () {
4950
pollerIntervalMilliseconds,
5051
rolePermittedAnnotation,
5152
customResourceManifest,
53+
pollingDisabled,
5254
logger
5355
})
5456

charts/kubernetes-external-secrets/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The following table lists the configurable parameters of the `kubernetes-externa
4949
| `env.ROLE_PERMITTED_ANNOTATION` | Specify the annotation key where to lookup the role arn permission boundaries | `iam.amazonaws.com/permitted` |
5050
| `env.POLLER_INTERVAL_MILLISECONDS` | Set POLLER_INTERVAL_MILLISECONDS in Deployment Pod | `10000` |
5151
| `env.VAULT_ADDR` | Endpoint for the Vault backend, if using Vault | `http://127.0.0.1:8200 |
52+
| `env.DISABLE_POLLING` | Disables backend polling and only updates secrets when ExternalSecret is modified, setting this to any value will disable polling | `nil` |
5253
| `envVarsFromSecret.AWS_ACCESS_KEY_ID` | Set AWS_ACCESS_KEY_ID (from a secret) in Deployment Pod | |
5354
| `envVarsFromSecret.AWS_SECRET_ACCESS_KEY` | Set AWS_SECRET_ACCESS_KEY (from a secret) in Deployment Pod | |
5455
| `image.repository` | kubernetes-external-secrets Image name | `godaddy/kubernetes-external-secrets` |

config/environment.js

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const pollerIntervalMilliseconds = process.env.POLLER_INTERVAL_MILLISECONDS
2121
? Number(process.env.POLLER_INTERVAL_MILLISECONDS) : 10000
2222

2323
const logLevel = process.env.LOG_LEVEL || 'info'
24+
const pollingDisabled = 'DISABLE_POLLING' in process.env
2425

2526
const rolePermittedAnnotation = process.env.ROLE_PERMITTED_ANNOTATION || 'iam.amazonaws.com/permitted'
2627

@@ -32,5 +33,6 @@ module.exports = {
3233
pollerIntervalMilliseconds,
3334
metricsPort,
3435
rolePermittedAnnotation,
36+
pollingDisabled,
3537
logLevel
3638
}

lib/poller-factory.js

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PollerFactory {
2020
pollerIntervalMilliseconds,
2121
rolePermittedAnnotation,
2222
customResourceManifest,
23+
pollingDisabled,
2324
logger
2425
}) {
2526
this._logger = logger
@@ -29,6 +30,7 @@ class PollerFactory {
2930
this._pollerIntervalMilliseconds = pollerIntervalMilliseconds
3031
this._customResourceManifest = customResourceManifest
3132
this._rolePermittedAnnotation = rolePermittedAnnotation
33+
this._pollingDisabled = pollingDisabled
3234
}
3335

3436
/**
@@ -44,6 +46,7 @@ class PollerFactory {
4446
metrics: this._metrics,
4547
customResourceManifest: this._customResourceManifest,
4648
rolePermittedAnnotation: this._rolePermittedAnnotation,
49+
pollingDisabled: this._pollingDisabled,
4750
externalSecret
4851
})
4952

lib/poller.js

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Poller {
3737
metrics,
3838
customResourceManifest,
3939
rolePermittedAnnotation,
40+
pollingDisabled,
4041
externalSecret
4142
}) {
4243
this._backends = backends
@@ -45,6 +46,7 @@ class Poller {
4546
this._logger = logger
4647
this._timeoutId = null
4748
this._metrics = metrics
49+
this._pollingDisabled = pollingDisabled
4850
this._rolePermittedAnnotation = rolePermittedAnnotation
4951
this._customResourceManifest = customResourceManifest
5052

@@ -221,6 +223,11 @@ class Poller {
221223
return this._setNextPoll(0)
222224
}
223225

226+
// If polling is disabled we only react to changes in the ExternalSecret
227+
if (this._pollingDisabled) {
228+
return
229+
}
230+
224231
const now = Date.now()
225232
const lastPollTime = Date.parse(lastSync) || 0
226233

lib/poller.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,25 @@ describe('Poller', () => {
479479
})
480480
})
481481

482+
it('disable interval polling', async () => {
483+
poller = new Poller({
484+
intervalMilliseconds: 5000,
485+
kubeClient: kubeClientMock,
486+
logger: loggerMock,
487+
externalSecret: fakeExternalSecret,
488+
customResourceManifest: fakeCustomResourceManifest,
489+
// Disable polling!
490+
pollingDisabled: true
491+
})
492+
493+
poller._setNextPoll = sinon.stub()
494+
495+
await poller._scheduleNextPoll()
496+
497+
expect(externalSecretsApiMock.status.get.calledWith()).to.equal(true)
498+
sinon.assert.notCalled(poller._setNextPoll)
499+
})
500+
482501
it('logs error if it fails', async () => {
483502
const error = new Error('something boom')
484503
externalSecretsApiMock.status.get = sinon.stub().throws(error)

0 commit comments

Comments
 (0)