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

Commit

Permalink
feat: allow disabling of interval polling (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flydiverny authored Nov 9, 2019
1 parent fd7dcb3 commit 9441216
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
logger,
metricsPort,
pollerIntervalMilliseconds,
pollingDisabled,
rolePermittedAnnotation
} = require('../config')

Expand Down Expand Up @@ -49,6 +50,7 @@ async function main () {
pollerIntervalMilliseconds,
rolePermittedAnnotation,
customResourceManifest,
pollingDisabled,
logger
})

Expand Down
1 change: 1 addition & 0 deletions charts/kubernetes-external-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The following table lists the configurable parameters of the `kubernetes-externa
| `env.ROLE_PERMITTED_ANNOTATION` | Specify the annotation key where to lookup the role arn permission boundaries | `iam.amazonaws.com/permitted` |
| `env.POLLER_INTERVAL_MILLISECONDS` | Set POLLER_INTERVAL_MILLISECONDS in Deployment Pod | `10000` |
| `env.VAULT_ADDR` | Endpoint for the Vault backend, if using Vault | `http://127.0.0.1:8200 |
| `env.DISABLE_POLLING` | Disables backend polling and only updates secrets when ExternalSecret is modified, setting this to any value will disable polling | `nil` |
| `envVarsFromSecret.AWS_ACCESS_KEY_ID` | Set AWS_ACCESS_KEY_ID (from a secret) in Deployment Pod | |
| `envVarsFromSecret.AWS_SECRET_ACCESS_KEY` | Set AWS_SECRET_ACCESS_KEY (from a secret) in Deployment Pod | |
| `image.repository` | kubernetes-external-secrets Image name | `godaddy/kubernetes-external-secrets` |
Expand Down
2 changes: 2 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const pollerIntervalMilliseconds = process.env.POLLER_INTERVAL_MILLISECONDS
? Number(process.env.POLLER_INTERVAL_MILLISECONDS) : 10000

const logLevel = process.env.LOG_LEVEL || 'info'
const pollingDisabled = 'DISABLE_POLLING' in process.env

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

Expand All @@ -32,5 +33,6 @@ module.exports = {
pollerIntervalMilliseconds,
metricsPort,
rolePermittedAnnotation,
pollingDisabled,
logLevel
}
3 changes: 3 additions & 0 deletions lib/poller-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PollerFactory {
pollerIntervalMilliseconds,
rolePermittedAnnotation,
customResourceManifest,
pollingDisabled,
logger
}) {
this._logger = logger
Expand All @@ -29,6 +30,7 @@ class PollerFactory {
this._pollerIntervalMilliseconds = pollerIntervalMilliseconds
this._customResourceManifest = customResourceManifest
this._rolePermittedAnnotation = rolePermittedAnnotation
this._pollingDisabled = pollingDisabled
}

/**
Expand All @@ -44,6 +46,7 @@ class PollerFactory {
metrics: this._metrics,
customResourceManifest: this._customResourceManifest,
rolePermittedAnnotation: this._rolePermittedAnnotation,
pollingDisabled: this._pollingDisabled,
externalSecret
})

Expand Down
7 changes: 7 additions & 0 deletions lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Poller {
metrics,
customResourceManifest,
rolePermittedAnnotation,
pollingDisabled,
externalSecret
}) {
this._backends = backends
Expand All @@ -45,6 +46,7 @@ class Poller {
this._logger = logger
this._timeoutId = null
this._metrics = metrics
this._pollingDisabled = pollingDisabled
this._rolePermittedAnnotation = rolePermittedAnnotation
this._customResourceManifest = customResourceManifest

Expand Down Expand Up @@ -221,6 +223,11 @@ class Poller {
return this._setNextPoll(0)
}

// If polling is disabled we only react to changes in the ExternalSecret
if (this._pollingDisabled) {
return
}

const now = Date.now()
const lastPollTime = Date.parse(lastSync) || 0

Expand Down
19 changes: 19 additions & 0 deletions lib/poller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ describe('Poller', () => {
})
})

it('disable interval polling', async () => {
poller = new Poller({
intervalMilliseconds: 5000,
kubeClient: kubeClientMock,
logger: loggerMock,
externalSecret: fakeExternalSecret,
customResourceManifest: fakeCustomResourceManifest,
// Disable polling!
pollingDisabled: true
})

poller._setNextPoll = sinon.stub()

await poller._scheduleNextPoll()

expect(externalSecretsApiMock.status.get.calledWith()).to.equal(true)
sinon.assert.notCalled(poller._setNextPoll)
})

it('logs error if it fails', async () => {
const error = new Error('something boom')
externalSecretsApiMock.status.get = sinon.stub().throws(error)
Expand Down

0 comments on commit 9441216

Please sign in to comment.