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

Commit

Permalink
fix: status update conflicts should not cause crash, fixes #199 (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flydiverny authored Nov 14, 2019
1 parent 9d6c2f9 commit e6171c8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,25 @@ class Poller {
}

async _updateStatus (status) {
this._logger.debug(`updating status for ${this._namespace}/${this._name} to: ${status}`)
await this._status.put({
body: {
...this._externalSecret,
status: {
lastSync: `${new Date().toISOString()}`,
observedGeneration: this._externalSecret.metadata.generation,
status
try {
this._logger.debug(`updating status for ${this._namespace}/${this._name} to: ${status}`)
await this._status.put({
body: {
...this._externalSecret,
status: {
lastSync: `${new Date().toISOString()}`,
observedGeneration: this._externalSecret.metadata.generation,
status
}
}
})
} catch (err) {
if (err.statusCode !== 409) {
this._logger.error(err, `failure while updating status for externalsecret ${this._namespace}/${this._name}`)
throw err
}
})
this._logger.info(`status update failed for externalsecret ${this._namespace}/${this._name}, due to modification, new poller should start`)
}
}

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

describe('_updateStatus', () => {
it('handles 409 - Conflict', async () => {
const conflictError = new Error('Conflict')
conflictError.statusCode = 409
externalSecretsApiMock.status.put.throws(conflictError)

const poller = pollerFactory()

await poller._updateStatus('SUCCESS')

expect(loggerMock.info.calledWith(`status update failed for externalsecret ${poller._namespace}/${poller._name}, due to modification, new poller should start`)).to.equal(true)
})

it('rethrows other errors', async () => {
const notFoundError = new Error('Not Found')
notFoundError.statusCode = 404
externalSecretsApiMock.status.put.throws(notFoundError)

const poller = pollerFactory()
let error

try {
await poller._updateStatus('SUCCESS')
} catch (err) {
error = err
}

expect(error).to.not.equal(undefined)
expect(error.message).equals('Not Found')
})
})

describe('_scheduleNextPoll', () => {
let poller
let clock
Expand Down

0 comments on commit e6171c8

Please sign in to comment.