@codefresh-io/kube-integration 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/.deploy/kube-integration/templates/serviceMonitor.yaml +2 -0
  2. package/.deploy/kube-integration/values.yaml +47 -0
  3. package/.github/workflows/validate-pr-title.yaml +1 -1
  4. package/CODEOWNERS +2 -2
  5. package/Dockerfile +1 -1
  6. package/config/index.js +0 -55
  7. package/index.js +4 -0
  8. package/infra/eventbus.js +5 -5
  9. package/infra/express.js +7 -22
  10. package/infra/index.js +20 -19
  11. package/infra/kube.manager.event.handler.js +4 -1
  12. package/infra/middleware.js +2 -1
  13. package/infra/process-events.js +6 -7
  14. package/lib/helm/release/base/pool.js +4 -1
  15. package/lib/helm/release/tests/release.controller.unit.spec.js +3 -0
  16. package/lib/kube-native/namespace/namespace.builder.js +0 -1
  17. package/lib/kube-native/namespace/namespace.js +1 -2
  18. package/lib/kube-native/node/node.js +8 -9
  19. package/lib/kube-native/pod/pod.controller.js +0 -1
  20. package/lib/kube-native/replicaSet/rs.js +3 -4
  21. package/lib/kube-native/replicaSet/rs.status.analyzer.js +5 -6
  22. package/lib/kube-native/secret/image.pull.secret.builder.js +0 -2
  23. package/lib/kube-native/secret/secret.controller.js +4 -1
  24. package/package.json +4 -4
  25. package/server/api/crud.base.controller.js +3 -3
  26. package/server/api/index.js +0 -2
  27. package/server/api/internal/test/index.js +0 -1
  28. package/server/api/kube-native/releases/controller.js +0 -3
  29. package/server/api/kube-native/secrets/controller.js +3 -3
  30. package/server/api/kube-native/services/controller.js +3 -1
  31. package/server/api/native.endpoints.js +4 -4
  32. package/service.yaml +1 -1
  33. package/infra/logging.js +0 -36
@@ -0,0 +1,2 @@
1
+ {{- $templateName := printf "cf-common-%s.serviceMonitor" (index .Subcharts "cf-common").Chart.Version -}}
2
+ {{- include $templateName . -}}
@@ -160,6 +160,38 @@ container:
160
160
  URI_QUERY_MAX_ITEMS: "{{ .Values.global.uriQueryMaxItems }}"
161
161
  URI_QUERY_ARRAY_MAX_ITEMS: "{{ .Values.global.uriQueryArrayMaxItems }}"
162
162
 
163
+ ## Service metadata
164
+ CF_SERVICE_NAME:
165
+ valueFrom:
166
+ fieldRef:
167
+ fieldPath: metadata.labels['app.kubernetes.io/name']
168
+ CF_SERVICE_VERSION: "{{ .Chart.Version }}"
169
+
170
+ ## cf-telemetry config
171
+ A_POD_NAME:
172
+ valueFrom:
173
+ fieldRef:
174
+ fieldPath: metadata.name
175
+ A_NAMESPACE_NAME:
176
+ valueFrom:
177
+ fieldRef:
178
+ fieldPath: metadata.namespace
179
+ # Pyroscope
180
+ CF_TELEMETRY_PYROSCOPE_ENABLE: "false"
181
+ CF_TELEMETRY_PYROSCOPE_TAGS: "pod=$(A_POD_NAME),namespace=$(A_NAMESPACE_NAME)"
182
+ # Prometheus
183
+ CF_TELEMETRY_PROMETHEUS_ENABLE: "false"
184
+ CF_TELEMETRY_PROMETHEUS_ENABLE_PROCESS_METRICS: "true"
185
+ CF_TELEMETRY_PROMETHEUS_HOST: "0.0.0.0"
186
+ CF_TELEMETRY_PROMETHEUS_PORT: "9100"
187
+ CF_TELEMETRY_PROMETHEUS_CONTENT_TYPE: "openmetrics"
188
+ # Logs
189
+ CF_TELEMETRY_LOGS_LEVEL: "info"
190
+ CF_TELEMETRY_LOGS_SYNC: "false"
191
+ CF_TELEMETRY_LOGS_PRETTIFY: "false"
192
+ # OpenTelemetry
193
+ CF_TELEMETRY_OTEL_ENABLE: "false"
194
+
163
195
  extraEnv:
164
196
  EVENTBUS_URI: $(RABBITMQ_PROTOCOL)://$(RABBITMQ_USERNAME):$(RABBITMQ_PASSWORD)@$(RABBITMQ_HOSTNAME)
165
197
 
@@ -221,3 +253,18 @@ service:
221
253
  http:
222
254
  port: 9000
223
255
  protocol: HTTP
256
+ prom-metrics:
257
+ protocol: TCP
258
+ port: 9100
259
+ otel-metrics:
260
+ protocol: TCP
261
+ port: 9464
262
+
263
+ serviceMonitor:
264
+ main:
265
+ enabled: false
266
+ endpoints:
267
+ - path: /metrics
268
+ port: otel-metrics
269
+ - path: /metrics
270
+ port: prom-metrics
@@ -16,7 +16,7 @@ jobs:
16
16
  pull-requests: read
17
17
  statuses: write
18
18
  steps:
19
- - uses: amannn/action-semantic-pull-request@v5.4.0
19
+ - uses: amannn/action-semantic-pull-request@v6.1.1
20
20
  env:
21
21
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22
22
  with:
package/CODEOWNERS CHANGED
@@ -3,7 +3,7 @@
3
3
  * @codefresh-io/Codefresh_Developers
4
4
 
5
5
  # team leads are responsible for the codeowners file and the migration scripts
6
- CODEOWNERS @codefresh-io/teamleads
6
+ CODEOWNERS @codefresh-io/DevOps @codefresh-io/teamleads zhenya.tikhonov@octopus.com
7
7
 
8
8
  # helm charts for DevOps team
9
- .deploy/ @codefresh-io/Codefresh_Developers @codefresh-io/DevOps
9
+ .deploy/ @codefresh-io/DevOps @codefresh-io/Codefresh_Developers
package/Dockerfile CHANGED
@@ -16,7 +16,7 @@ RUN yarn install --production --frozen-lockfile
16
16
  RUN mkdir /logs
17
17
 
18
18
 
19
- FROM octopusdeploy/dhi-node:${DHI_NODE_TAG}_${DHI_NODE_CUSTOMIZATION}@sha256:3a831f3711c6349932c94c9475157444aa1c1452879f34a5d79bcc79e1985b9e AS prod
19
+ FROM octopusdeploy/dhi-node:${DHI_NODE_TAG}_${DHI_NODE_CUSTOMIZATION}@sha256:ad632c0e0c95fe06c45a0deff94899290e0359b547b735469d86203faa1b3d15 AS prod
20
20
  WORKDIR /kube-integration
21
21
  COPY --chown=node:node --chmod=755 --from=prod-deps /kube-integration/ /kube-integration/
22
22
  COPY --chown=node:node --chmod=755 --from=prod-deps /logs/ /logs/
package/config/index.js CHANGED
@@ -13,61 +13,6 @@ base.env = process.env.NODE_ENV || 'kubernetes';
13
13
  base.port = process.env.PORT || 9003;
14
14
  base.name = name;
15
15
 
16
- base.logger = {
17
- filePath: process.env.LOGS_PATH || path.join(__dirname, '../../logs', 'kubernetes-logs.log'),
18
- console: true,
19
- handleExceptions: false,
20
- showNamespace: true,
21
- env_module: `${name}_${os.hostname()}`,
22
- showRequestId: true,
23
- level: "debug",
24
- consoleOptions: {
25
- timestamp: function () {
26
- return new Date().toISOString();
27
- },
28
- formatter: function (options) {
29
- // Return string will be passed to logger.
30
- const shouldFormatOutput = !!process.env['FORMAT_LOGS_TO_ELK'];
31
- if (shouldFormatOutput) {
32
- return JSON.stringify({
33
- metadata: options.meta || {},
34
- data: Object.assign(options.data || {}, { message: options.message }),
35
- });
36
- }
37
- // human readable format
38
- return `${options.timestamp()} ${options.level.toUpperCase()} >> ` +
39
- `${options.message || ''}` +
40
- `${options.meta && Object.keys(options.meta).length ? ` << ${JSON.stringify(options.meta)}` : ''}`;
41
- }
42
- },
43
- basePath: null,
44
- baseNamespace: "codefresh",
45
- fields: {
46
- service: process.env['SERVICE_NAME'] || 'service-base',
47
- time: () => { return new Date().toISOString(); },
48
- correlationId: () => {
49
- try {
50
- return getRequestId();
51
- } catch (err) {
52
- return {};
53
- }
54
- },
55
- user: () => {
56
- try {
57
- const { _user: { name, _id } } = getAuthenticatedEntity();
58
- return { name, _id };
59
- } catch (err) {
60
- return {};
61
- }
62
- }
63
- }
64
- };
65
-
66
- base.httpLogger = {
67
- level: process.env.HTTP_LOGGER_LEVEL || 'debug',
68
- format: 'dev'
69
- };
70
-
71
16
  base.eventbus = {
72
17
  uri: process.env.EVENTBUS_URI || 'amqp://codefresh.dev',
73
18
  reconnectInterval: process.env.EVENTBUS_INTERVAL || 5,
package/index.js CHANGED
@@ -1,4 +1,8 @@
1
1
  'use strict';
2
+ /* eslint-disable global-require */
3
+ // ↓ Should be imported first
4
+ require('@codefresh-io/cf-telemetry/init');
5
+ // ↓ Keep one blank line below to prevent automatic import reordering
2
6
 
3
7
  module.exports = start();
4
8
 
package/infra/eventbus.js CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  const Promise = require('bluebird');
4
4
  const eventBus = require('@codefresh-io/eventbus');
5
- const logger = require('cf-logs').Logger("codefresh:infra:eventbus");
5
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
6
6
  const config = require('./../config');
7
7
 
8
+ const logger = new Logger("codefresh:infra:eventbus");
8
9
 
9
10
  class Eventbus {
10
11
 
@@ -44,15 +45,14 @@ class Eventbus {
44
45
  });
45
46
 
46
47
  eventBus.on('ready', () => {
47
- console.log('Eventbus ready');
48
+ logger.info('Eventbus ready');
48
49
  this.eventbusInitialized = true;
49
50
  deferred.resolve();
50
51
  });
51
52
 
52
53
  eventBus.on('error', (err) => {
53
- const error = new Error(`Eventbus error: ${err.stack}`);
54
- logger.error(error.stack);
55
54
  // monitor.noticeError(error); // Used earlier to report an error to New Relic
55
+ logger.error(`Eventbus error`, err);
56
56
  });
57
57
 
58
58
  return deferred.promise;
@@ -91,8 +91,8 @@ class Eventbus {
91
91
  logger.debug(`Publishing event: ${name}`);
92
92
  eventBus.publish(name, data)
93
93
  .catch((err) => {
94
- logger.error(err.stack);
95
94
  // monitor.noticeError(err); // Used earlier to report an error to New Relic
95
+ logger.error(`Failed to publish event: ${name}`, err);
96
96
  })
97
97
  .done();
98
98
  }
package/infra/express.js CHANGED
@@ -5,8 +5,8 @@ const express = require('express');
5
5
  const compression = require('compression');
6
6
  const methodOverride = require('method-override');
7
7
  const cookieParser = require('cookie-parser');
8
- const morgan = require('morgan');
9
- const logger = require('cf-logs').Logger("codefresh:infra:express");
8
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
9
+ const { httpLoggerMiddlewareFactory } = require(`@codefresh-io/cf-telemetry/logs/express`);
10
10
  const api = require('../server/api');
11
11
  const _ = require('lodash');
12
12
  const middlewares = require('./middleware');
@@ -14,6 +14,7 @@ const httpInfra = require('@codefresh-io/http-infra');
14
14
  const CFError = require('cf-errors');
15
15
  const qs = require('qs')
16
16
 
17
+ const logger = new Logger("codefresh:infra:express");
17
18
 
18
19
  class Express {
19
20
 
@@ -65,6 +66,7 @@ class Express {
65
66
  parameterLimit: this.config.queryString.uriQueryMaxItems,
66
67
  arrayLimit: this.config.queryString.uriQueryArrayMaxItems
67
68
  })});
69
+ app.use(httpLoggerMiddlewareFactory(new Logger('http')));
68
70
  app.use(httpInfra.newDomainMiddleware());
69
71
  app.use(cookieParser());
70
72
  app.use(compression());
@@ -72,23 +74,6 @@ class Express {
72
74
  app.use(express.json());
73
75
  app.use(methodOverride());
74
76
 
75
- if (this.config.httpLogger) {
76
- app.use(morgan(this.config.httpLogger.format, {
77
- skip: (req, res) => {
78
- if (this.config.httpLogger.level === 'debug') {
79
- return false;
80
- }
81
- var code = res.statusCode;
82
- return code < 400;
83
- },
84
- stream: {
85
- write: (str) => {
86
- logger.info(str.substring(0, str.length - 1));
87
- }
88
- }
89
- }));
90
- }
91
-
92
77
  app.get('/api/ping', (req, res) => {
93
78
  res.status(200).send();
94
79
  });
@@ -143,9 +128,9 @@ class Express {
143
128
  if (err instanceof CFError) {
144
129
  if (!err.getFirstValue("recognized")) {
145
130
  // monitor.noticeError(err); // Used earlier to report an error to New Relic
131
+ logger.error(err);
146
132
  }
147
133
  }
148
- logger.error(err.stack);
149
134
  if (res.headersSent) {
150
135
  return next(err);
151
136
  }
@@ -168,10 +153,10 @@ class Express {
168
153
 
169
154
  const server = app.listen(this.config.port, (err) => {
170
155
  if (err) {
171
- console.log(`Failed to load service with message ${err.message}`);
156
+ logger.error(`Failed to load service`, err);
172
157
  reject(err);
173
158
  } else {
174
- console.log(`Express server listening on port ${this.config.port}, in mode ${this.config.env}`);
159
+ logger.info(`Express server listening on port ${this.config.port}, in mode ${this.config.env}`);
175
160
  resolve(server);
176
161
  }
177
162
  });
package/infra/index.js CHANGED
@@ -1,38 +1,39 @@
1
1
  "use strict";
2
2
 
3
- const logging = require('./logging');
3
+ const { terminate } = require('@codefresh-io/cf-telemetry/init');
4
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
4
5
  const config = require('../config');
5
6
  const Promise = require('bluebird'); // jshint ignore:line
6
7
  const processEvents = require('./process-events');
7
8
  const express = require('./express');
8
9
  const eventbus = require('./eventbus');
9
- const logger = require('cf-logs').Logger('codefresh:infra:index');
10
+ const logger = new Logger('codefresh:infra:index');
10
11
 
11
12
  class Microservice {
12
13
 
13
14
  constructor() {}
14
15
 
15
16
  init() {
16
- return logging.init(config)
17
+
18
+ return processEvents.init(config)
17
19
  .then(() => {
18
- return processEvents.init(config)
19
- .then(() => {
20
- processEvents.on('SIGTERM', this.stop.bind(this));
21
- });
20
+ processEvents.on('SIGTERM', this.stop.bind(this, 'SIGTERM'));
22
21
  })
23
22
  .then(() => {
24
- return Promise.all([
25
- eventbus.init(config)
26
- ]);
23
+ processEvents.on('SIGINT', this.stop.bind(this, 'SIGINT'));
24
+ })
25
+ .then(() => {
26
+ return eventbus.init(config)
27
27
  })
28
28
  .then(() => {
29
29
  return express.init(config);
30
30
  })
31
31
  .then(() => {
32
- console.log(`Initialization completed`);
32
+ logger.info(`Initialization completed`);
33
33
  })
34
- .catch((err) => {
35
- console.error(`Initialization error: ${err.stack}`);
34
+ .catch(async (err) => {
35
+ logger.error(`Initialization error`, err);
36
+ await terminate();
36
37
  process.exit(1);
37
38
  })
38
39
  .done();
@@ -42,13 +43,13 @@ class Microservice {
42
43
  // - first phase need to make sure to not accept any new requests/events
43
44
  // - then a decent amount of time will be given to clear all on-going contexts
44
45
  // - second phase will close all dependencies connections like mongo, postgres etc
45
- stop() {
46
- logger.info('Starting shutdown...');
46
+ stop(signal) {
47
+ logger.info(`Starting shutdown due to ${signal}...`);
47
48
  return Promise.all([
48
- express.stop(),
49
- eventbus.stop()
50
- ])
51
- .then(() => {
49
+ express.stop(),
50
+ eventbus.stop()
51
+ ]).then(async () => {
52
+ await terminate(signal);
52
53
  logger.info('Shutdown completed, exiting');
53
54
  });
54
55
  }
@@ -2,6 +2,9 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const publishEvent = require('./../infra/eventbus').publishEvent;
5
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
6
+
7
+ const logger = new Logger("codefresh:infra:event-handler");
5
8
 
6
9
  function handler(account, user) {
7
10
  return function (event, data) {
@@ -15,7 +18,7 @@ function handler(account, user) {
15
18
  userName: user.userName
16
19
  }), ['accountId', 'userId'])
17
20
  };
18
- console.log(`Publishing ${event}, ${JSON.stringify(data)}`);
21
+ logger.debug(`Publishing event: ${event}`,data);
19
22
  publishEvent(event, dataToBeSent);
20
23
  }
21
24
  }
@@ -2,12 +2,13 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const Promise = require('bluebird');
5
- const logger = require('cf-logs').Logger("codefresh:infra:middlewares");
5
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
6
6
  const KubeManager = require('./../lib/kube.manager');
7
7
  const config = require('./../config');
8
8
  const MatchFilter = require('./../server/helpers/filters').Match;
9
9
  const kubeEventHandler = require('./kube.manager.event.handler');
10
10
 
11
+ const logger = new Logger("codefresh:infra:middlewares");
11
12
 
12
13
  function ensureNamespaceId(req, res, next) {
13
14
  const result = req.checkQuery('namespaceId', 'Query must have namespaceId').notEmpty();
@@ -2,7 +2,9 @@
2
2
 
3
3
  const EventEmitter = require('events');
4
4
  const Promise = require('bluebird');
5
- const logger = require('cf-logs').Logger('codefresh:infra:process-events');
5
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
6
+
7
+ const logger = new Logger('codefresh:infra:process-events');
6
8
 
7
9
  class ProcessEvents extends EventEmitter {
8
10
 
@@ -25,12 +27,9 @@ class ProcessEvents extends EventEmitter {
25
27
  this.emit('SIGTERM');
26
28
  });
27
29
 
28
- process.on('unhandledRejection', (err) => {
29
- logger.error(`Unhandled rejection ${err.stack}`);
30
- });
31
-
32
- process.on('uncaughtException', (err) => {
33
- logger.error(`Uncaught Exception: ${err.stack}`);
30
+ process.on('SIGINT', () => {
31
+ logger.info('SIGINT received');
32
+ this.emit('SIGINT');
34
33
  });
35
34
 
36
35
  });
@@ -1,5 +1,8 @@
1
1
  const Promise = require('bluebird');
2
2
  const _ = require('lodash');
3
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
4
+
5
+ const logger = new Logger("codefresh:helm:release");
3
6
 
4
7
  class BasePool {
5
8
  constructor({ Revision, Release }, { sources }) {
@@ -87,7 +90,7 @@ class BasePool {
87
90
  }
88
91
  })
89
92
  .catch(err => {
90
- console.log(err);
93
+ logger.error(`Failed to prepare release`, err);
91
94
  });
92
95
  });
93
96
  }
@@ -23,6 +23,9 @@ class FakeConfigMap {
23
23
  getProperty() {
24
24
  return {};
25
25
  }
26
+ getNamespace() {
27
+ return 'default';
28
+ }
26
29
  };
27
30
 
28
31
  function getFakeController() {
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
3
  const BaseBuilder = require('./../../kube-native/builder.base');
5
4
 
6
5
  class NamespaceBuilder extends BaseBuilder{
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
3
  const BaseEntity = require('./../../kube-native/entity.base');
5
4
 
6
5
  class Namespace extends BaseEntity {
7
6
 
8
7
  getName() {
9
- return _.get(this._getData(), 'metadata.name');
8
+ return this._getData()?.metadata?.name;
10
9
  }
11
10
 
12
11
  getBasicData() {
@@ -1,37 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  const BaseEntity = require('./../entity.base');
4
- const _ = require('lodash');
5
4
 
6
5
  class Node extends BaseEntity {
7
6
 
8
7
  getName() {
9
- return _.get(this._getData(), 'metadata.name');
8
+ return this._getData()?.metadata?.name;
10
9
  }
11
10
 
12
11
  getStatus() {
13
- let conditions = _.get(this._getData(), 'status.conditions') || [];
12
+ let conditions = this._getData()?.status?.conditions || [];
14
13
  return conditions.filter((condition) => condition.type === 'Ready').pop();
15
14
  }
16
15
 
17
16
  getInternalIP() {
18
- let addresses = _.get(this._getData(), 'status.addresses') || [];
17
+ let addresses = this._getData()?.status?.addresses || [];
19
18
  let address = addresses.filter((address) => address.type === 'InternalIP').pop();
20
- return _.get(address, 'address') || 'N/A';
19
+ return address?.address || 'N/A';
21
20
  }
22
21
 
23
22
  getExternalIP() {
24
- let addresses = _.get(this._getData(), 'status.addresses') || [];
23
+ let addresses = this._getData()?.status?.addresses || [];
25
24
  let address = addresses.filter((address) => address.type === 'ExternalIP').pop();
26
- return _.get(address, 'address') || 'N/A';
25
+ return address?.address || 'N/A';
27
26
  }
28
27
 
29
28
  getCreatedAt() {
30
- return _.get(this._getData(), 'metadata.creationTimestamp');
29
+ return this._getData()?.metadata?.creationTimestamp;
31
30
  }
32
31
 
33
32
  getLabels() {
34
- return _.get(this._getData(), 'metadata.labels');
33
+ return this._getData()?.metadata?.labels;
35
34
  }
36
35
 
37
36
  getBasicData() {
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
3
  const Promise = require('bluebird');
5
4
  const ResourceController = require('./../resource.base.controller');
6
5
  const { SquashedPod, SquashedPodPool } = require('./../../internal-components/SquashedPod');
@@ -1,20 +1,19 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
3
  const BaseEntity = require('./../entity.base');
5
4
 
6
5
  class ReplicaSet extends BaseEntity {
7
6
 
8
7
  getName() {
9
- return _.get(this._getData(), 'metadata.name');
8
+ return this._getData()?.metadata?.name;
10
9
  }
11
10
 
12
11
  getReplicas(){
13
- return _.get(this._getData(), 'status.replicas', 0);
12
+ return this._getData()?.status?.replicas || 0;
14
13
  }
15
14
 
16
15
  getNamespace() {
17
- return _.get(this._getData(), 'metadata.namespace');
16
+ return this._getData()?.metadata?.namespace;
18
17
  }
19
18
 
20
19
  getBasicData() {
@@ -14,11 +14,11 @@ class ReplicaSetStatusAnalyzer extends Base {
14
14
  analyze() {
15
15
  this._finalStauts = Base.types.unknown;
16
16
 
17
- const readyReplicas = _.get(this, '_status.readyReplicas');
18
- const fullyLabeledReplicas = _.get(this, '_status.fullyLabeledReplicas');
19
- const observedGeneration = _.get(this, '_status.observedGeneration');
20
- const replicas = _.get(this, '_status.replicas');
21
- const availableReplicas = _.get(this, '_status.availableReplicas');
17
+ const readyReplicas = this._status.readyReplicas;
18
+ const fullyLabeledReplicas = this._status.fullyLabeledReplicas;
19
+ const observedGeneration = this._status.observedGeneration;
20
+ const replicas = this._status.replicas;
21
+ const availableReplicas = this._status.availableReplicas;
22
22
 
23
23
 
24
24
  if (!_.isNumber(replicas)) {
@@ -37,7 +37,6 @@ class ReplicaSetStatusAnalyzer extends Base {
37
37
  });
38
38
  }
39
39
 
40
-
41
40
  }
42
41
 
43
42
 
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const crypto = require('crypto');
4
- const _ = require('lodash');
5
3
  const BaseBuilder = require('./../builder.base');
6
4
 
7
5
  class ImagePullSecretBuilder extends BaseBuilder {
@@ -4,13 +4,16 @@ const _ = require('lodash');
4
4
  const Promise = require('bluebird');
5
5
  const YAML = require('js-yaml');
6
6
  const crypto = require('crypto');
7
- const logger = require('cf-logs').Logger('codefresh:lib:kube-native:secret:secret-controller');
7
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
8
+
8
9
  const ResourceController = require('./../resource.base.controller');
9
10
  const Secret = require('./secret');
10
11
  const ImagePullSecretBuilder = require('./image.pull.secret.builder');
11
12
  const SecretEvents = require('./secret.events');
12
13
  const secretLabels = require('./secret.labels');
13
14
 
15
+ const logger = new Logger('codefresh:lib:kube-native:secret:secret-controller');
16
+
14
17
 
15
18
 
16
19
  class KubeSecretController extends ResourceController {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.0",
2
+ "version": "2.1.0",
3
3
  "name": "@codefresh-io/kube-integration",
4
4
  "main": "index.js",
5
5
  "description": "",
@@ -32,15 +32,16 @@
32
32
  "tough-cookie": "4.1.3",
33
33
  "@kubernetes/client-node": "0.22.1",
34
34
  "**/request/form-data": "^2.4.5",
35
- "**/request/qs": "6.14.2"
35
+ "**/request/qs": "6.15.2",
36
+ "**/postman-request/qs": "6.15.2"
36
37
  },
37
38
  "dependencies": {
39
+ "@codefresh-io/cf-telemetry": "^4.2.1",
38
40
  "@codefresh-io/docker-reference": "^0.1.0",
39
41
  "@codefresh-io/eventbus": "^2.4.0",
40
42
  "@codefresh-io/http-infra": "^1.8.15",
41
43
  "bluebird": "^3.7.2",
42
44
  "cf-errors": "^0.1.17",
43
- "cf-logs": "^1.1.28",
44
45
  "compression": "^1.8.1",
45
46
  "cookie-parser": "^1.4.7",
46
47
  "eventemitter2": "^4.1.2",
@@ -51,7 +52,6 @@
51
52
  "kubernetes-client": "^9.0.0",
52
53
  "lodash": "^4.18.1",
53
54
  "method-override": "^2.3.9",
54
- "morgan": "^1.10.1",
55
55
  "nock": "^12.0.3",
56
56
  "nodegistry": "^1.3.1",
57
57
  "object-hash": "^1.2.0",
@@ -7,13 +7,13 @@ const ResponseHandler = require('./../helpers/ResponseHandler');
7
7
  class CrudController {
8
8
 
9
9
  constructor(data) {
10
- this._shouldLookForNs = _.get(data, 'lookForNamespaces', false);
10
+ this._shouldLookForNs = data?.lookForNamespaces || false;
11
11
  }
12
12
 
13
13
  getAll(request, response, next) {
14
14
  const filters = request.filters;
15
15
  const kubeResourceController = request.kubeResourceController;
16
- const labelSelector = request.query.labelSelector;
16
+ const labelSelector = request.query?.labelSelector;
17
17
  const searchFilter = labelSelector ? { labelSelector } : {};
18
18
  if (this._shouldLookForNs) {
19
19
  const namespaces = request.namespaces;
@@ -39,7 +39,7 @@ class CrudController {
39
39
 
40
40
  describe(request, response, next) {
41
41
  const kubeResourceController = request.kubeResourceController;
42
- let omitFields = _.get(request, 'query.omit', ['']);
42
+ let omitFields = request.query?.omit || [''];
43
43
  if (_.isString(omitFields) && _.includes(omitFields, ',')) {
44
44
  omitFields = omitFields.split(',');
45
45
  }
@@ -7,8 +7,6 @@ const path = require('path');
7
7
  const CONTROLLERS_PATH = './internal';
8
8
  const apis = fs.readdirSync(path.join(__dirname, CONTROLLERS_PATH));
9
9
 
10
- const _ = require('lodash');
11
-
12
10
 
13
11
  function createRoutes(app) {
14
12
  apis.forEach(api => {
@@ -2,7 +2,6 @@
2
2
 
3
3
  const router = require('express').Router();
4
4
  const ResponseHandler = require('./../../../helpers/ResponseHandler');
5
- const KubeManager = require('./../../../../lib/kube.manager');
6
5
 
7
6
 
8
7
  function init() {
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const _ = require('lodash');
4
- const Promise = require('bluebird');
5
- const logger = require('cf-logs');
6
- const ResponseHandler = require('./../../../helpers/ResponseHandler');
7
4
  const BaseCrudController = require('./../../crud.base.controller');
8
5
 
9
6
 
@@ -47,10 +47,10 @@ class Controller extends BaseCrudController {
47
47
  createImagePullSecret(request, response, next) {
48
48
  const account = request.account;
49
49
  const user = request.user;
50
- const bodyRegistries = _.get(request, 'body.accountRegistries');
51
- const resitries = _.get(account, 'integrations.registries', []);
50
+ const bodyRegistries = request.body?.accountRegistries;
51
+ const resitries = account?.integrations?.registries || [];
52
52
  const accountsRegistries = bodyRegistries ? bodyRegistries : resitries;
53
- const registryName = _.get(request, 'body.registry');
53
+ const registryName = request.body?.registry;
54
54
  const namespaces = request.namespaces;
55
55
  const kubeManager = request.kubeManager;
56
56
  const secretController = kubeManager.getSecretController.bind(kubeManager);
@@ -5,6 +5,8 @@ const Promise = require('bluebird');
5
5
  const ResponseHandler = require('./../../../helpers/ResponseHandler');
6
6
  const BaseCrudController = require('./../../crud.base.controller');
7
7
  const StatusAnalyzer = require('./../../../../lib/status.analyzer.base');
8
+ const { Logger } = require('@codefresh-io/cf-telemetry/logs');
9
+ const logger = new Logger("codefresh:api:kube-native:controller");
8
10
 
9
11
  function formatQueryAsString(queryAsStringOrArryay) {
10
12
  if (_.isArray(queryAsStringOrArryay)) {
@@ -240,7 +242,7 @@ class Controller extends BaseCrudController {
240
242
  .catch((err) => {
241
243
  // do not stop the execution if one resource delete request throws an error
242
244
  // todo: think of how to return this information back to the client
243
- console.log(err.stack);
245
+ logger.error(`Failed to delete resource: ${resource.getName()}`, err);
244
246
  return;
245
247
  });
246
248
  });
@@ -63,11 +63,11 @@ function initExpressController(route, options) {
63
63
  let controller;
64
64
 
65
65
  // non standard controller
66
- if (options.expressController) {
66
+ if (options?.expressController) {
67
67
  controller = require(`./kube-native/${options.expressController.path || route}/controller`);
68
68
  } else {
69
69
  controller = new BaseController({
70
- lookForNamespaces: _.get(options, 'baseController.lookForNamespaces', false)
70
+ lookForNamespaces: options?.baseController?.lookForNamespaces || false
71
71
  });
72
72
  }
73
73
  if (!options.resolveNamespacesFromQuery) {
@@ -93,7 +93,7 @@ function initExpressController(route, options) {
93
93
  router.put('/:name', controller.update.bind(controller));
94
94
 
95
95
  //Non standard routes comes here
96
- const extraRoutes = _.get(options, 'expressController.extraRoutes', false);
96
+ const extraRoutes = options?.expressController?.extraRoutes || false;
97
97
  if (extraRoutes) {
98
98
  require(`./kube-native/${options.expressController.path || route}`).init(router, controller);
99
99
  }
@@ -104,7 +104,7 @@ function initExpressController(route, options) {
104
104
 
105
105
 
106
106
  module.exports = {
107
- routes: _.keys(supportedRoutes).map((ep) => `kube-native/${ep}`),
107
+ routes: Object.keys(supportedRoutes).map((ep) => `kube-native/${ep}`),
108
108
 
109
109
  createRoute: (expressApp) => {
110
110
  _.forOwn(supportedRoutes, (options, route) => {
package/service.yaml CHANGED
@@ -1 +1 @@
1
- version: 2.0.0
1
+ version: 2.1.0
package/infra/logging.js DELETED
@@ -1,36 +0,0 @@
1
- 'use strict';
2
-
3
- const Promise = require('bluebird');
4
- const config = require('../config');
5
- const cflogs = require('cf-logs');
6
- cflogs.init(config.logger);
7
- const logger = cflogs.Logger("codefresh");
8
-
9
-
10
- class Logging {
11
-
12
- constructor() {
13
-
14
- }
15
-
16
- init(config) {
17
- return Promise.resolve()
18
- .then(() => {
19
-
20
- // override the default console.log
21
- console.log = function (message) {
22
- logger.log('info', message);
23
- };
24
- console.error = function (message) {
25
- logger.log('error', message);
26
- };
27
- });
28
- }
29
-
30
- stop() {
31
- return Promise.resolve();
32
- }
33
- }
34
-
35
-
36
- module.exports = new Logging();