@codefresh-io/kube-integration 2.0.1 → 2.1.1
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.
- package/.deploy/kube-integration/templates/serviceMonitor.yaml +2 -0
- package/.deploy/kube-integration/values.yaml +47 -0
- package/.github/workflows/validate-pr-title.yaml +1 -1
- package/CODEOWNERS +2 -2
- package/config/index.js +0 -55
- package/index.js +4 -0
- package/infra/eventbus.js +43 -59
- package/infra/express.js +7 -22
- package/infra/index.js +20 -19
- package/infra/kube.manager.event.handler.js +4 -1
- package/infra/middleware.js +2 -1
- package/infra/process-events.js +6 -7
- package/lib/helm/release/base/pool.js +4 -1
- package/lib/helm/release/tests/release.controller.unit.spec.js +3 -0
- package/lib/kube-native/namespace/namespace.builder.js +0 -1
- package/lib/kube-native/namespace/namespace.js +1 -2
- package/lib/kube-native/node/node.js +8 -9
- package/lib/kube-native/pod/pod.controller.js +0 -1
- package/lib/kube-native/replicaSet/rs.js +3 -4
- package/lib/kube-native/replicaSet/rs.status.analyzer.js +5 -6
- package/lib/kube-native/secret/image.pull.secret.builder.js +0 -2
- package/lib/kube-native/secret/secret.controller.js +4 -1
- package/package.json +3 -4
- package/server/api/crud.base.controller.js +3 -3
- package/server/api/index.js +0 -2
- package/server/api/internal/test/index.js +0 -1
- package/server/api/kube-native/releases/controller.js +0 -3
- package/server/api/kube-native/secrets/controller.js +3 -3
- package/server/api/kube-native/services/controller.js +3 -1
- package/server/api/native.endpoints.js +4 -4
- package/service.yaml +1 -1
- package/infra/logging.js +0 -36
|
@@ -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
|
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/
|
|
9
|
+
.deploy/ @codefresh-io/DevOps @codefresh-io/Codefresh_Developers
|
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
package/infra/eventbus.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Promise = require('bluebird');
|
|
4
3
|
const eventBus = require('@codefresh-io/eventbus');
|
|
5
|
-
const
|
|
4
|
+
const { Logger } = require('@codefresh-io/cf-telemetry/logs');
|
|
6
5
|
const config = require('./../config');
|
|
7
6
|
|
|
7
|
+
const logger = new Logger("codefresh:infra:eventbus");
|
|
8
8
|
|
|
9
9
|
class Eventbus {
|
|
10
10
|
|
|
@@ -17,49 +17,43 @@ class Eventbus {
|
|
|
17
17
|
* @returns {*}
|
|
18
18
|
*/
|
|
19
19
|
init(config) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return deferred.promise;
|
|
59
|
-
})
|
|
60
|
-
.then(() => {
|
|
61
|
-
return this._start();
|
|
62
|
-
});
|
|
20
|
+
this.config = config;
|
|
21
|
+
|
|
22
|
+
/** @type {PromiseWithResolvers<void>} */
|
|
23
|
+
const deferred = Promise.withResolvers();
|
|
24
|
+
|
|
25
|
+
//TODO a fallback for case where rabbitmq is not up. should be removed once rabbitmq is fully used
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
deferred.resolve();
|
|
28
|
+
}, 30000);
|
|
29
|
+
|
|
30
|
+
eventBus.init({
|
|
31
|
+
bus: {
|
|
32
|
+
url: this.config.eventbus.uri,
|
|
33
|
+
reconnectInterval: 5
|
|
34
|
+
},
|
|
35
|
+
store: {
|
|
36
|
+
host: this.config.postgres.host,
|
|
37
|
+
database: this.config.postgres.database,
|
|
38
|
+
user: this.config.postgres.user,
|
|
39
|
+
password: this.config.postgres.password,
|
|
40
|
+
port: this.config.postgres.port,
|
|
41
|
+
},
|
|
42
|
+
microServiceName: this.config.eventbus.serviceName
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
eventBus.on('ready', () => {
|
|
46
|
+
logger.info('Eventbus ready');
|
|
47
|
+
this.eventbusInitialized = true;
|
|
48
|
+
deferred.resolve();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
eventBus.on('error', (err) => {
|
|
52
|
+
// monitor.noticeError(error); // Used earlier to report an error to New Relic
|
|
53
|
+
logger.error(`Eventbus error`, err);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return deferred.promise.then(() => this._start());
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
|
|
@@ -71,17 +65,8 @@ class Eventbus {
|
|
|
71
65
|
if (!this.eventbusInitialized) {
|
|
72
66
|
return Promise.resolve();
|
|
73
67
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
eventBus.on('close', () => {
|
|
78
|
-
logger.info('Eventbus client closed');
|
|
79
|
-
deferred.resolve();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
eventBus.quit();
|
|
83
|
-
|
|
84
|
-
return deferred.promise;
|
|
68
|
+
logger.info('Eventbus client closed');
|
|
69
|
+
return eventBus.quit();
|
|
85
70
|
}
|
|
86
71
|
|
|
87
72
|
_start() {}
|
|
@@ -91,10 +76,9 @@ class Eventbus {
|
|
|
91
76
|
logger.debug(`Publishing event: ${name}`);
|
|
92
77
|
eventBus.publish(name, data)
|
|
93
78
|
.catch((err) => {
|
|
94
|
-
logger.error(err.stack);
|
|
95
79
|
// monitor.noticeError(err); // Used earlier to report an error to New Relic
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
logger.error(`Failed to publish event: ${name}`, err);
|
|
81
|
+
});
|
|
98
82
|
}
|
|
99
83
|
|
|
100
84
|
}
|
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
|
|
9
|
-
const
|
|
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
|
-
|
|
156
|
+
logger.error(`Failed to load service`, err);
|
|
172
157
|
reject(err);
|
|
173
158
|
} else {
|
|
174
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
17
|
+
|
|
18
|
+
return processEvents.init(config)
|
|
17
19
|
.then(() => {
|
|
18
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
32
|
+
logger.info(`Initialization completed`);
|
|
33
33
|
})
|
|
34
|
-
.catch((err) => {
|
|
35
|
-
|
|
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(
|
|
46
|
+
stop(signal) {
|
|
47
|
+
logger.info(`Starting shutdown due to ${signal}...`);
|
|
47
48
|
return Promise.all([
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
21
|
+
logger.debug(`Publishing event: ${event}`,data);
|
|
19
22
|
publishEvent(event, dataToBeSent);
|
|
20
23
|
}
|
|
21
24
|
}
|
package/infra/middleware.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
const Promise = require('bluebird');
|
|
5
|
-
const
|
|
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();
|
package/infra/process-events.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events');
|
|
4
4
|
const Promise = require('bluebird');
|
|
5
|
-
const
|
|
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('
|
|
29
|
-
logger.
|
|
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
|
-
|
|
93
|
+
logger.error(`Failed to prepare release`, err);
|
|
91
94
|
});
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -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
|
|
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
|
|
8
|
+
return this._getData()?.metadata?.name;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
getStatus() {
|
|
13
|
-
let 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 =
|
|
17
|
+
let addresses = this._getData()?.status?.addresses || [];
|
|
19
18
|
let address = addresses.filter((address) => address.type === 'InternalIP').pop();
|
|
20
|
-
return
|
|
19
|
+
return address?.address || 'N/A';
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
getExternalIP() {
|
|
24
|
-
let addresses =
|
|
23
|
+
let addresses = this._getData()?.status?.addresses || [];
|
|
25
24
|
let address = addresses.filter((address) => address.type === 'ExternalIP').pop();
|
|
26
|
-
return
|
|
25
|
+
return address?.address || 'N/A';
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
getCreatedAt() {
|
|
30
|
-
return
|
|
29
|
+
return this._getData()?.metadata?.creationTimestamp;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
getLabels() {
|
|
34
|
-
return
|
|
33
|
+
return this._getData()?.metadata?.labels;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
getBasicData() {
|
|
@@ -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
|
|
8
|
+
return this._getData()?.metadata?.name;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
getReplicas(){
|
|
13
|
-
return
|
|
12
|
+
return this._getData()?.status?.replicas || 0;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
getNamespace() {
|
|
17
|
-
return
|
|
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 =
|
|
18
|
-
const fullyLabeledReplicas =
|
|
19
|
-
const observedGeneration =
|
|
20
|
-
const replicas =
|
|
21
|
-
const 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
|
|
|
@@ -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
|
|
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.
|
|
2
|
+
"version": "2.1.1",
|
|
3
3
|
"name": "@codefresh-io/kube-integration",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"**/postman-request/qs": "6.15.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@codefresh-io/cf-telemetry": "^4.2.1",
|
|
39
40
|
"@codefresh-io/docker-reference": "^0.1.0",
|
|
40
|
-
"@codefresh-io/eventbus": "^
|
|
41
|
+
"@codefresh-io/eventbus": "^4.0.1",
|
|
41
42
|
"@codefresh-io/http-infra": "^1.8.15",
|
|
42
43
|
"bluebird": "^3.7.2",
|
|
43
44
|
"cf-errors": "^0.1.17",
|
|
44
|
-
"cf-logs": "^1.1.28",
|
|
45
45
|
"compression": "^1.8.1",
|
|
46
46
|
"cookie-parser": "^1.4.7",
|
|
47
47
|
"eventemitter2": "^4.1.2",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"kubernetes-client": "^9.0.0",
|
|
53
53
|
"lodash": "^4.18.1",
|
|
54
54
|
"method-override": "^2.3.9",
|
|
55
|
-
"morgan": "^1.10.1",
|
|
56
55
|
"nock": "^12.0.3",
|
|
57
56
|
"nodegistry": "^1.3.1",
|
|
58
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 =
|
|
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
|
|
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 =
|
|
42
|
+
let omitFields = request.query?.omit || [''];
|
|
43
43
|
if (_.isString(omitFields) && _.includes(omitFields, ',')) {
|
|
44
44
|
omitFields = omitFields.split(',');
|
|
45
45
|
}
|
package/server/api/index.js
CHANGED
|
@@ -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 =
|
|
51
|
-
const resitries =
|
|
50
|
+
const bodyRegistries = request.body?.accountRegistries;
|
|
51
|
+
const resitries = account?.integrations?.registries || [];
|
|
52
52
|
const accountsRegistries = bodyRegistries ? bodyRegistries : resitries;
|
|
53
|
-
const registryName =
|
|
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
|
-
|
|
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
|
|
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:
|
|
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 =
|
|
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:
|
|
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.
|
|
1
|
+
version: 2.1.1
|
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();
|