From 513cf66dda5bb6f45ba3fc96749854ba3b74c4aa Mon Sep 17 00:00:00 2001 From: Alex Lewitt <48691328+alewitt2@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:58:22 -0400 Subject: [PATCH] feat(controller): allow default reconcile behavior to be configurable (#372) * chore(dep): razee/kubernetes-util@1.1.0 pick up change to propagate options through the event emitter * chore(dep): razee/razeedeploy-core@1.3.0 Pick up enhancement to the base controller to allow for controlling the reconcile behavior on resources managed by razee * feat(controller): allow default reconcile behavior to be configurable introduces additional environment variables to control the default reconcile behavior of the remote resource controllers The environment variable RR_RECONCILE_BY_DEFAULT will set the reconcile behavior. The default is true if not set Co-authored-by: Eric Satterwhite --- kubernetes/RemoteResource/resource.yaml | 6 ++++++ package-lock.json | 28 ++++++++++++------------- package.json | 4 ++-- src/BackendServiceFactory.js | 19 +++++++---------- src/index.js | 5 ++++- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/kubernetes/RemoteResource/resource.yaml b/kubernetes/RemoteResource/resource.yaml index cddb4773..742d8109 100644 --- a/kubernetes/RemoteResource/resource.yaml +++ b/kubernetes/RemoteResource/resource.yaml @@ -48,6 +48,12 @@ items: value: razee-io/remoteresource - name: USER_AGENT_VERSION value: "{{{TRAVIS_TAG}}}" + - name: RR_RECONCILE_BY_DEFAULT + valueFrom: + configMapKeyRef: + name: razeedeploy-overrides + key: RR_RECONCILE_BY_DEFAULT + optional: true - name: CRD_WATCH_TIMEOUT_SECONDS valueFrom: configMapKeyRef: diff --git a/package-lock.json b/package-lock.json index 26323f9e..a9afccf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "0.0.0-dev", "license": "Apache-2.0", "dependencies": { - "@razee/kubernetes-util": "^1.0.1", - "@razee/razeedeploy-core": "^1.2.2", + "@razee/kubernetes-util": "^1.1.0", + "@razee/razeedeploy-core": "^1.3.0", "axios": "^0.27.2", "bunyan": "^1.8.15", "clone": "^2.1.2", @@ -718,9 +718,9 @@ } }, "node_modules/@razee/kubernetes-util": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@razee/kubernetes-util/-/kubernetes-util-1.0.2.tgz", - "integrity": "sha512-LPH/PuZVFOVCRzdnr9DAhA6NsvHTzk+xQ/YLtFg2iLTRGpWmfHPG09F5NLTSxefGiIIBanri/O0cdD+OzOcFBA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@razee/kubernetes-util/-/kubernetes-util-1.1.0.tgz", + "integrity": "sha512-EfB8MpF0ROxgMYxLA95lSM57eTr7F/CfMAH3oTwFtlkrtf+WNqwotyd4Iupiu+PJQFt/DZmnmo23fVZ/vtQ1tQ==", "dependencies": { "@kubernetes/client-node": "^0.16.3", "bunyan": "^1.8.15", @@ -737,9 +737,9 @@ } }, "node_modules/@razee/razeedeploy-core": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@razee/razeedeploy-core/-/razeedeploy-core-1.2.2.tgz", - "integrity": "sha512-ht8ubNnIBBKOf/G3R+5Xl7BqsvQ9bmbOYmZ5b6O5fyApTGL5d4bSyD/x+3aDcXRx5qnuY1/BmC8573GzNQu7Bg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@razee/razeedeploy-core/-/razeedeploy-core-1.3.0.tgz", + "integrity": "sha512-ioqBXrgxObfV1DK7uymyjZNDP2naTaWScXiNMN6nhtBEqHl37nXo531LoUWvTTKNr3C08gky/0a7EpkjfuWVBA==", "dependencies": { "@razee/kubernetes-util": "^1.0.2", "bunyan": "^1.8.15", @@ -6649,9 +6649,9 @@ "integrity": "sha512-UdkG3mLEqXgnlKsWanWcgb6dOjUzJ+XC5f+aWw30qrtjxeNUSfKX1cd5FBzOaXQumoe9nIqeZUvrRJS03HCCtw==" }, "@razee/kubernetes-util": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@razee/kubernetes-util/-/kubernetes-util-1.0.2.tgz", - "integrity": "sha512-LPH/PuZVFOVCRzdnr9DAhA6NsvHTzk+xQ/YLtFg2iLTRGpWmfHPG09F5NLTSxefGiIIBanri/O0cdD+OzOcFBA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@razee/kubernetes-util/-/kubernetes-util-1.1.0.tgz", + "integrity": "sha512-EfB8MpF0ROxgMYxLA95lSM57eTr7F/CfMAH3oTwFtlkrtf+WNqwotyd4Iupiu+PJQFt/DZmnmo23fVZ/vtQ1tQ==", "requires": { "@kubernetes/client-node": "^0.16.3", "bunyan": "^1.8.15", @@ -6668,9 +6668,9 @@ } }, "@razee/razeedeploy-core": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@razee/razeedeploy-core/-/razeedeploy-core-1.2.2.tgz", - "integrity": "sha512-ht8ubNnIBBKOf/G3R+5Xl7BqsvQ9bmbOYmZ5b6O5fyApTGL5d4bSyD/x+3aDcXRx5qnuY1/BmC8573GzNQu7Bg==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@razee/razeedeploy-core/-/razeedeploy-core-1.3.0.tgz", + "integrity": "sha512-ioqBXrgxObfV1DK7uymyjZNDP2naTaWScXiNMN6nhtBEqHl37nXo531LoUWvTTKNr3C08gky/0a7EpkjfuWVBA==", "requires": { "@razee/kubernetes-util": "^1.0.2", "bunyan": "^1.8.15", diff --git a/package.json b/package.json index 03d1f53a..71c5f726 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ }, "license": "Apache-2.0", "dependencies": { - "@razee/kubernetes-util": "^1.0.1", - "@razee/razeedeploy-core": "^1.2.2", + "@razee/kubernetes-util": "^1.1.0", + "@razee/razeedeploy-core": "^1.3.0", "axios": "^0.27.2", "bunyan": "^1.8.15", "clone": "^2.1.2", diff --git a/src/BackendServiceFactory.js b/src/BackendServiceFactory.js index ef7fa7f8..d69e2bd3 100644 --- a/src/BackendServiceFactory.js +++ b/src/BackendServiceFactory.js @@ -20,20 +20,17 @@ const objectPath = require('object-path'); module.exports = class BackendServiceFactory { constructor(params) { this.eventParams = params; + const backendService = objectPath.get(this.eventParams, 'eventData.object.spec.backendService', '').toLowerCase(); + + let controllerString = 'RemoteResource'; + if (backendService == 's3') controllerString = 'RemoteResourceS3'; + if (backendService == 'git') controllerString = 'RemoteResourceGit'; + this.controllerString = controllerString; } async execute() { - const backendService = objectPath.get(this.eventParams, 'eventData.object.spec.backendService', '').toLowerCase(); - let controllerString; - if (backendService === 's3') { - controllerString = 'RemoteResourceS3'; - } else if (backendService === 'git') { - controllerString = 'RemoteResourceGit'; - } else { // generic - controllerString = 'RemoteResource'; - } - this.eventParams.logger.info(`Running ${controllerString}Controller.`); - const Controller = require(`./${controllerString}Controller`); + this.eventParams.logger.info(`Running ${this.controllerString}Controller.`); + const Controller = require(`./${this.controllerString}Controller`); const controller = new Controller(this.eventParams); return await controller.execute(); } diff --git a/src/index.js b/src/index.js index db277ea5..2a6ee25f 100644 --- a/src/index.js +++ b/src/index.js @@ -31,7 +31,10 @@ async function createNewEventHandler(kc) { kubeClass: kc, logger: log, requestOptions: { qs: { timeoutSeconds: process.env.CRD_WATCH_TIMEOUT_SECONDS || 300 } }, - livenessInterval: true + livenessInterval: true, + options: { + reconcileByDefault: process.env.RR_RECONCILE_BY_DEFAULT || true + } }; result = new EventHandler(params); } else {