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

Commit ebe860e

Browse files
authored
chore: update log messages to use the same name format: namespace/external-secret-name (#194)
* chore: update log messages to use the same name format: namespace/external-secret-name * chore: improve log message when no role is set * fix: eliminate extended version of secretDescriptor
1 parent 8db1749 commit ebe860e

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

lib/backends/kv-backend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class KVBackend extends AbstractBackend {
2525
*/
2626
_fetchSecretPropertyValues ({ externalData, roleArn }) {
2727
return Promise.all(externalData.map(async secretProperty => {
28-
this._logger.info(`fetching secret property ${secretProperty.name} with role: ${roleArn}`)
28+
this._logger.info(`fetching secret property ${secretProperty.name} with role: ${roleArn || 'no role set'}`)
2929
const value = await this._get({ secretKey: secretProperty.key, roleArn })
3030

3131
if ('property' in secretProperty) {

lib/backends/kv-backend.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ describe('SecretsManagerBackend', () => {
8080
}]
8181
})
8282

83-
expect(loggerMock.info.calledWith('fetching secret property fakePropertyName1 with role: undefined')).to.equal(true)
84-
expect(loggerMock.info.calledWith('fetching secret property fakePropertyName2 with role: undefined')).to.equal(true)
83+
expect(loggerMock.info.calledWith('fetching secret property fakePropertyName1 with role: no role set')).to.equal(true)
84+
expect(loggerMock.info.calledWith('fetching secret property fakePropertyName2 with role: no role set')).to.equal(true)
8585
expect(kvBackend._get.calledWith({
8686
secretKey: 'fakePropertyKey1',
8787
roleArn: undefined

lib/daemon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Daemon {
3939
*/
4040
_removePoller (pollerId) {
4141
if (this._pollers[pollerId]) {
42-
this._logger.info(`stopping and removing poller ${pollerId}`)
42+
this._logger.debug(`stopping and removing poller ${pollerId}`)
4343
this._pollers[pollerId].stop()
4444
delete this._pollers[pollerId]
4545
}
@@ -50,7 +50,7 @@ class Daemon {
5050
}
5151

5252
_addPoller (descriptor) {
53-
this._logger.info('spinning up poller for', descriptor.name, 'in', descriptor.namespace)
53+
this._logger.debug(`spinning up poller for ${descriptor.namespace}/${descriptor.name}`)
5454

5555
const poller = this._pollerFactory.createPoller(descriptor)
5656

lib/daemon.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Daemon', () => {
1515
beforeEach(() => {
1616
loggerMock = sinon.mock()
1717
loggerMock.info = sinon.stub()
18+
loggerMock.debug = sinon.stub()
1819

1920
pollerMock = sinon.mock()
2021
pollerMock.start = sinon.stub().returns(pollerMock)

lib/poller.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ class Poller {
4545
this._customResourceManifest = customResourceManifest
4646

4747
this._externalSecret = externalSecret
48+
this._secretDescriptor = externalSecret.secretDescriptor
4849

4950
const { name, uid, namespace } = externalSecret.metadata
5051

51-
this._secretDescriptor = { ...externalSecret.secretDescriptor, name }
52-
5352
this._ownerReference = {
5453
apiVersion: externalSecret.apiVersion,
5554
controller: true,
@@ -79,7 +78,7 @@ class Poller {
7978
apiVersion: 'v1',
8079
kind: 'Secret',
8180
metadata: {
82-
name: secretDescriptor.name,
81+
name: this._name,
8382
ownerReferences: [
8483
this._ownerReference
8584
]
@@ -94,7 +93,7 @@ class Poller {
9493
* @returns {Promise} Promise object that always resolves.
9594
*/
9695
async _poll () {
97-
this._logger.info(`running poll on the secret ${this._name}`)
96+
this._logger.info(`running poll on the secret ${this._namespace}/${this._name}`)
9897

9998
try {
10099
await this._upsertKubernetesSecret()
@@ -107,7 +106,7 @@ class Poller {
107106
status: 'success'
108107
})
109108
} catch (err) {
110-
this._logger.error(err, `failure while polling the secret ${this._name}`)
109+
this._logger.error(err, `failure while polling the secret ${this._namespace}/${this._name}`)
111110
await this._updateStatus(`ERROR, ${err.message}`)
112111

113112
this._metrics.observeSync({
@@ -131,11 +130,11 @@ class Poller {
131130
const verdict = this._isPermitted(ns.body, this._secretDescriptor)
132131

133132
if (!verdict.allowed) {
134-
throw (new Error(`not allowed to fetch secret: ${this._name}: ${verdict.reason}`))
133+
throw (new Error(`not allowed to fetch secret: ${this._namespace}/${this._name}: ${verdict.reason}`))
135134
}
136135

137136
const secretManifest = await this._createSecretManifest()
138-
this._logger.info(`upserting secret ${this._name} in ${this._namespace}`)
137+
this._logger.info(`upserting secret ${this._namespace}/${this._name}`)
139138

140139
try {
141140
return await kubeNamespace.secrets.post({ body: secretManifest })
@@ -146,6 +145,7 @@ class Poller {
146145
}
147146

148147
async _updateStatus (status) {
148+
this._logger.debug(`updating status for ${this._namespace}/${this._name} to: ${status}`)
149149
await this._status.put({
150150
body: {
151151
...this._externalSecret,
@@ -224,7 +224,7 @@ class Poller {
224224

225225
return this._setNextPoll(nextPollIn)
226226
} catch (err) {
227-
this._logger.error(err, 'status check went boom for %s in %s', this._name, this._namespace)
227+
this._logger.error(err, `status check went boom for ${this._namespace}/${this._name}`)
228228
}
229229
}
230230

@@ -239,7 +239,7 @@ class Poller {
239239
}
240240

241241
this._timeoutId = setTimeout(this._poll.bind(this), nextPollIn)
242-
this._logger.debug('Next poll for %s in %s in %s', this._name, this._namespace, nextPollIn)
242+
this._logger.debug(`next poll for ${this._namespace}/${this._name} in ${nextPollIn} ms`)
243243
}
244244

245245
/**
@@ -250,7 +250,7 @@ class Poller {
250250
start () {
251251
if (this._timeoutId) return this
252252

253-
this._logger.info(`starting poller on the secret ${this._name}`)
253+
this._logger.info(`starting poller for ${this._namespace}/${this._name}`)
254254
this._scheduleNextPoll()
255255

256256
return this
@@ -263,7 +263,7 @@ class Poller {
263263
stop () {
264264
if (!this._timeoutId) return this
265265

266-
this._logger.info(`stopping poller on the secret ${this._name}`)
266+
this._logger.info(`stopping poller for ${this._namespace}/${this._name}`)
267267

268268
clearTimeout(this._timeoutId)
269269
this._timeoutId = null

lib/poller.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('Poller', () => {
218218
poller._upsertKubernetesSecret.resolves()
219219

220220
await poller._poll()
221-
expect(loggerMock.info.calledWith(`running poll on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
221+
expect(loggerMock.info.calledWith(`running poll on the secret ${poller._namespace}/${poller._name}`)).to.equal(true)
222222

223223
expect(metricsMock.observeSync.getCall(0).args[0]).to.deep.equal({
224224
name: 'fakeSecretName',
@@ -241,7 +241,7 @@ describe('Poller', () => {
241241
backend: 'fakeBackendType',
242242
status: 'error' })
243243
expect(poller._updateStatus.calledWith(`ERROR, ${error.message}`)).to.equal(true)
244-
expect(loggerMock.error.calledWith(error, `failure while polling the secret ${poller._secretDescriptor.name}`)).to.equal(true)
244+
expect(loggerMock.error.calledWith(error, `failure while polling the secret ${poller._namespace}/${poller._name}`)).to.equal(true)
245245
})
246246
})
247247

@@ -358,7 +358,7 @@ describe('Poller', () => {
358358
externalSecretsApiMock.status.get = sinon.stub().throws(error)
359359

360360
await poller._scheduleNextPoll()
361-
expect(loggerMock.error.calledWith(error, 'status check went boom for %s in %s', 'fakeSecretName', 'fakeNamespace')).to.equal(true)
361+
expect(loggerMock.error.calledWith(error, 'status check went boom for fakeNamespace/fakeSecretName')).to.equal(true)
362362
})
363363
})
364364

@@ -457,7 +457,7 @@ describe('Poller', () => {
457457
}
458458

459459
expect(error).to.not.equal(undefined)
460-
expect(error.message).equals('not allowed to fetch secret: fakeSecretName: namspace does not allow to assume role arn:aws:iam::123456789012:role/test-role')
460+
expect(error.message).equals('not allowed to fetch secret: fakeNamespace/fakeSecretName: namspace does not allow to assume role arn:aws:iam::123456789012:role/test-role')
461461
})
462462

463463
it('fails storing secret', async () => {
@@ -496,7 +496,7 @@ describe('Poller', () => {
496496

497497
poller.start()
498498

499-
expect(loggerMock.info.calledWith(`starting poller on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
499+
expect(loggerMock.info.calledWith(`starting poller for ${poller._namespace}/${poller._name}`)).to.equal(true)
500500
expect(poller._scheduleNextPoll.called).to.equal(true)
501501
})
502502
})
@@ -516,7 +516,7 @@ describe('Poller', () => {
516516

517517
poller.stop()
518518

519-
expect(loggerMock.info.calledWith(`stopping poller on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
519+
expect(loggerMock.info.calledWith(`stopping poller for ${poller._namespace}/${poller._name}`)).to.equal(true)
520520
expect(poller._timeoutId).to.equal(null)
521521
})
522522
})

0 commit comments

Comments
 (0)