Repository: godaddy/kubernetes-external-secrets
Pull request #146 (2019-08-09 18:07:00)

feat(logging): specified secret names and fixed a couple typos
Fixing the following issue: https://github.com/godaddy/kubernetes-external-secrets/issues/114


Patch:
diff --git a/lib/poller.js b/lib/poller.js
index 9f9c716..7e44a4f 100644
--- a/lib/poller.js
+++ b/lib/poller.js
@@ -67,15 +67,14 @@ class Poller {
 
   /**
    * Poll Kubernetes secrets.
-   * @returns {Promise} Promise object that always resolve.
+   * @returns {Promise} Promise object that always resolves.
    */
   async _poll () {
-    this._logger.info('running poll')
+    this._logger.info(`running poll on the secret ${this._secretDescriptor.name}`)
     try {
       await this._upsertKubernetesSecret()
     } catch (err) {
-      this._logger.error('failure while polling the secrets')
-      this._logger.error(err)
+      this._logger.error(err, `failure while polling the secret ${this._secretDescriptor.name}`)
     }
   }
 
@@ -84,17 +83,15 @@ class Poller {
    * @returns {Promise} Promise object representing operation result.
    */
   async _upsertKubernetesSecret () {
-    const secretDescriptor = this._secretDescriptor
-    const secretName = secretDescriptor.name
     const secretManifest = await this._createSecretManifest()
     const kubeNamespace = this._kubeClient.api.v1.namespaces(this._namespace)
 
-    this._logger.info(`upserting secret ${secretName} in ${this._namespace}`)
+    this._logger.info(`upserting secret ${this._secretDescriptor.name} in ${this._namespace}`)
     try {
       return await kubeNamespace.secrets.post({ body: secretManifest })
     } catch (err) {
       if (err.statusCode !== 409) throw err
-      return kubeNamespace.secrets(secretName).put({ body: secretManifest })
+      return kubeNamespace.secrets(this._secretDescriptor.name).put({ body: secretManifest })
     }
   }
 
@@ -102,15 +99,13 @@ class Poller {
    * Checks if secret exists, if not trigger a poll
    */
   async _checkForSecret () {
-    const secretDescriptor = this._secretDescriptor
-    const secretName = secretDescriptor.name
     const kubeNamespace = this._kubeClient.api.v1.namespaces(this._namespace)
 
     try {
-      await kubeNamespace.secrets(secretName).get()
+      await kubeNamespace.secrets(this._secretDescriptor.name).get()
     } catch (err) {
       if (err.statusCode === 404) {
-        this._logger.info('Secret does not exist, polling right away')
+        this._logger.info(`Secret ${this._secretDescriptor.name} does not exist, polling right away`)
         this._poll()
       }
     }
@@ -130,7 +125,7 @@ class Poller {
       this._checkForSecret()
     }
 
-    this._logger.info('starting poller')
+    this._logger.info(`starting poller on the secret ${this._secretDescriptor.name}`)
     this._interval = setInterval(this._poll.bind(this), this._intervalMilliseconds)
     return this
   }
@@ -141,7 +136,7 @@ class Poller {
    */
   stop () {
     if (!this._interval) return this
-    this._logger.info('stopping poller')
+    this._logger.info(`stopping poller on the secret ${this._secretDescriptor.name}`)
     clearInterval(this._interval)
     this._interval = null
     return this


Test patch:
diff --git a/lib/backends/abstract-backend.test.js b/lib/backends/abstract-backend.test.js
index 10cc736..0c41cae 100644
--- a/lib/backends/abstract-backend.test.js
+++ b/lib/backends/abstract-backend.test.js
@@ -13,7 +13,7 @@ describe('AbstractBackend', () => {
   })
 
   describe('getSecretManifestData', () => {
-    it('thows an error', () => {
+    it('throws an error', () => {
       let error
 
       try {
diff --git a/lib/backends/kv-backend.test.js b/lib/backends/kv-backend.test.js
index c51c79d..5b902e8 100644
--- a/lib/backends/kv-backend.test.js
+++ b/lib/backends/kv-backend.test.js
@@ -93,7 +93,7 @@ describe('SecretsManagerBackend', () => {
   })
 
   describe('_get', () => {
-    it('thows an error', () => {
+    it('throws an error', () => {
       let error
 
       try {
diff --git a/lib/poller.test.js b/lib/poller.test.js
index 672bb98..e8fcc37 100644
--- a/lib/poller.test.js
+++ b/lib/poller.test.js
@@ -161,17 +161,16 @@ describe('Poller', () => {
       poller._upsertKubernetesSecret.resolves()
 
       await poller._poll()
-
-      expect(loggerMock.info.calledWith('running poll')).to.equal(true)
+      expect(loggerMock.info.calledWith(`running poll on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
       expect(poller._upsertKubernetesSecret.calledWith()).to.equal(true)
     })
 
     it('logs error if storing secret operation fails', async () => {
-      poller._upsertKubernetesSecret.throws(new Error('fake error message'))
+      const error = new Error('fake error message')
+      poller._upsertKubernetesSecret.throws(error)
 
       await poller._poll()
-
-      expect(loggerMock.error.calledWith('failure while polling the secrets')).to.equal(true)
+      expect(loggerMock.error.calledWith(error, `failure while polling the secret ${poller._secretDescriptor.name}`)).to.equal(true)
     })
   })
 
@@ -286,7 +285,7 @@ describe('Poller', () => {
       expect(poller._interval).to.equal(null)
       poller.start({ forcePoll: true })
       clock.tick(poller._intervalMilliseconds)
-      expect(loggerMock.info.calledWith('starting poller')).to.equal(true)
+      expect(loggerMock.info.calledWith(`starting poller on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
       expect(poller._interval).to.not.equal(null)
       expect(poller._poll.called).to.equal(true)
     })
@@ -309,7 +308,7 @@ describe('Poller', () => {
     it('stops poller', async () => {
       poller.start({ forcePoll: true })
       poller.stop()
-      expect(loggerMock.info.calledWith('stopping poller')).to.equal(true)
+      expect(loggerMock.info.calledWith(`stopping poller on the secret ${poller._secretDescriptor.name}`)).to.equal(true)
       expect(poller._interval).to.equal(null)
     })
   })