Skip to content

Commit

Permalink
Upgrade to osm 1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangcheng870518 committed Mar 14, 2023
1 parent 3e5e2fa commit 3f9ce6f
Show file tree
Hide file tree
Showing 37 changed files with 324 additions and 109 deletions.
4 changes: 2 additions & 2 deletions packages/server/config/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function syncRegistries () {
try {
strapi.service("api::registry.registry").sync(data);
} catch (err) {
strapi.log.error(err.message);
console.error(err.message);
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ async function syncOsm () {
}
}
} catch (error) {
strapi.log.error(error);
console.error(error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
await k8sApi.deleteNamespacedSecret(data.name, data.namespace.name);
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},
};
4 changes: 2 additions & 2 deletions packages/server/src/api/clickhouse/services/clickhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const { createCoreService } = require('@strapi/strapi').factories;

const axios = require('axios');
axios.defaults.timeout = 1000
axios.defaults.timeout = 3000
const querystring = require('querystring');
const fs = require('fs');

Expand Down Expand Up @@ -150,7 +150,7 @@ module.exports = createCoreService('api::clickhouse.clickhouse', {
}
}
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"kind": "collectionType",
"collectionName": "custom_events",
"info": {
"singularName": "custom-event",
"pluralName": "custom-events",
"displayName": "customEvent",
"description": ""
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"action": {
"type": "string"
},
"content": {
"type": "json"
},
"organization": {
"type": "relation",
"relation": "manyToOne",
"target": "api::organization.organization",
"inversedBy": "customEvents"
},
"user": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.user",
"inversedBy": "customEvents"
},
"type": {
"type": "string"
},
"from": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* custom-event controller
*/

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::custom-event.custom-event');
9 changes: 9 additions & 0 deletions packages/server/src/api/custom-event/routes/custom-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* custom-event router
*/

const { createCoreRouter } = require('@strapi/strapi').factories;

module.exports = createCoreRouter('api::custom-event.custom-event');
9 changes: 9 additions & 0 deletions packages/server/src/api/custom-event/services/custom-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* custom-event service
*/

const { createCoreService } = require('@strapi/strapi').factories;

module.exports = createCoreService('api::custom-event.custom-event');
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
try {
await strapi.service("api::clickhouse.clickhouse").createTable(event.result);
} catch (error) {
strapi.log.error(error);
console.error(error);
}
}
},
Expand Down Expand Up @@ -127,7 +127,6 @@ module.exports = {
try {
const { result } = event;


if (result.type === 'clickhouse') {
const clickhouses = await strapi.db.query('api::fleet.fleet').findOne({
where: {
Expand Down Expand Up @@ -165,7 +164,7 @@ module.exports = {
}
}
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},

Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/api/ingress/services/ingress.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = createCoreService('api::ingress.ingress',{
args.data.content
);
} catch (error) {
strapi.log.error(error?.response?.body)
console.error(error?.response?.body)
if (error?.response?.body?.message) {
throw new Error(error?.response?.body?.message);
} else {
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = createCoreService('api::ingress.ingress',{
values.content.metadata.namespace
);
} catch (error) {
strapi.log.error(error?.response?.body)
console.error(error?.response?.body)
}

return await strapi.db.query("api::" + type + "." + type).delete({where: { id: args.id }});
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/api/mesh/services/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = createCoreService('api::mesh.mesh',{
// -- Address of the remote logging service (must contain the namespace). When left empty, this is computed in helper template to "remote-logging-service.<osm-namespace>.svc.cluster.local".
result.options.osm.remoteLogging.address = ch.content.host;
// -- Port of the remote logging service
result.options.osm.remoteLogging.port = ch.content.port;
result.options.osm.remoteLogging.port = Number(ch.content.port);
// -- The authorization for remote logging service
const base64Str = new Buffer.from(
ch.content.user + ':' + ch.content.password
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports = createCoreService('api::mesh.mesh',{
});

if (result.mcsEnable) {
let helmFsmCmd = `helm repo add fsm https://charts.flomesh.io && helm install --namespace ${namespace.name} --kubeconfig ${kubeconfigPath} --set fsm.logLevel=5 --version=0.2.1 fsm fsm/fsm --create-namespace`;
let helmFsmCmd = `helm repo add fsm https://charts.flomesh.io && helm install --namespace ${namespace.name} --kubeconfig ${kubeconfigPath} --set fsm.logLevel=5 --version=0.2.3 fsm fsm/fsm --create-namespace`;

if (result.timeout) {
helmFsmCmd += ' --timeout ${result.timeout}';
Expand Down Expand Up @@ -226,7 +226,7 @@ module.exports = createCoreService('api::mesh.mesh',{
);
}
} catch (error) {
strapi.log.error(error)
console.error(error)
}
strapi.log.info('add cluster', res.body.status.loadBalancer);
};
Expand Down Expand Up @@ -462,7 +462,7 @@ module.exports = createCoreService('api::mesh.mesh',{
);
}
} catch (error) {
strapi.log.error(error)
console.error(error)
}
strapi.log.info('del cluster', name);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/namespace/services/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = createCoreService('api::namespace.namespace',{
});
});
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = {
}
}
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
"relation": "oneToMany",
"target": "api::event.event",
"mappedBy": "organization"
},
"customEvents": {
"type": "relation",
"relation": "oneToMany",
"target": "api::custom-event.custom-event",
"mappedBy": "organization"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
}
});
} catch (error) {
strapi.log.error(error);
console.error(error);
}
},
beforeCreate: async (event) => {
Expand Down Expand Up @@ -100,22 +100,23 @@ module.exports = {
}
},
afterUpdate: async (event) => {
const { result, params } = event;
const { result } = event;
if (result.type == 'k8s') {
try {
strapi.log.info('fetch k8s namespace');
await strapi.service('api::registry.registry').fetchK8sNamespace(result);
} catch (error) {
strapi.log.error(error)
console.error(error)
}
} else if (result.type == 'eureka') {
strapi.service('api::registry.registry').fetchEurekaServices(result.id, params, true);
}
}
// already done it at beforeUpdate()
// else if (result.type == 'eureka') {
// strapi.service('api::registry.registry').fetchEurekaServices(result.id, params, true);
// }
},
beforeUpdate: async (event) => {
const { params } = event;

const data = await strapi.db.query("api::registry.registry").findOne(params.where.id);
const data = await strapi.entityService.findOne('api::registry.registry', params.where.id);
if (data.type == 'k8s') {
if (data.config) {
const json = YAML.parse(data.config)
Expand All @@ -124,8 +125,7 @@ module.exports = {
data.address = cluster.cluster.server
}
} else if (data.type == 'eureka') {
await strapi.service('api::registry.registry').fetchEurekaServices(
data, true);
await strapi.service('api::registry.registry').fetchEurekaServices(data, true);
} else {
strapi.log.info('fetch xxx namespace');
}
Expand Down
17 changes: 9 additions & 8 deletions packages/server/src/api/registry/controllers/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ module.exports = createCoreController('api::registry.registry', ({ strapi }) =>

async refresh(ctx, args) {
await strapi.db.query("api::registry.registry").update({where:{...args}, data: {updated_at: new Date()}})
try {
ctx.koaContext.request.header.schema_id = args.id;
ctx.koaContext.request.header.namespace = '_all';
ctx.koaContext.request.header.schema_type = 'k8s';
await strapi.service('api::service.service').fetchServices(ctx, args);
} catch (error) {
strapi.log.error(error)
}
// already done it at afterUpdate()
// try {
// ctx.koaContext.request.header.schema_id = args.id;
// ctx.koaContext.request.header.namespace = '_all';
// ctx.koaContext.request.header.schema_type = 'k8s';
// await strapi.service('api::service.service').fetchServices(ctx, args);
// } catch (error) {
// console.error(error)
// }
return true;
},
}));
Loading

0 comments on commit 3f9ce6f

Please sign in to comment.