Skip to content

Commit 39ac7e7

Browse files
committed
fix label selector, update api
1 parent ab3b934 commit 39ac7e7

7 files changed

Lines changed: 35 additions & 20 deletions

File tree

OpenFlow/src/Messages/Message.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ export class Message {
954954
let msg: EnsureNoderedInstanceMessage;
955955
try {
956956
msg = EnsureNoderedInstanceMessage.assign(this.data);
957-
await this._EnsureNoderedInstance(cli, msg._id, false, msg.labels);
957+
await this._EnsureNoderedInstance(cli, msg._id, false);
958958
} catch (error) {
959959
this.data = "";
960960
cli._logger.error(error);
@@ -969,7 +969,7 @@ export class Message {
969969
}
970970
this.Send(cli);
971971
}
972-
private async _EnsureNoderedInstance(cli: WebSocketServerClient, _id: string, skipcreate: boolean, labels: any): Promise<void> {
972+
private async _EnsureNoderedInstance(cli: WebSocketServerClient, _id: string, skipcreate: boolean): Promise<void> {
973973
let user: NoderedUser;
974974
cli._logger.debug("[" + cli.user.username + "] EnsureNoderedInstance");
975975
if (_id === null || _id === undefined || _id === "") _id = cli.user._id;
@@ -1113,16 +1113,24 @@ export class Message {
11131113
}
11141114
}
11151115
}
1116-
if (_deployment && labels && Config.nodered_allow_nodeselector) {
1117-
if (typeof labels === "string") {
1118-
var item = JSON.parse(labels);
1119-
var spec: any = _deployment.spec.template.spec;
1120-
const keys = Object.keys(item);
1121-
if (spec.nodeSelector == null) spec.nodeSelector = {};
1122-
keys.forEach(key => {
1123-
spec.nodeSelector[key] = item[key];
1124-
})
1125-
}
1116+
// if (_deployment && labels && Config.nodered_allow_nodeselector) {
1117+
// if (typeof labels === "string") {
1118+
// let item = JSON.parse(labels);
1119+
// let spec: any = _deployment.spec.template.spec;
1120+
// const keys = Object.keys(item);
1121+
// if (spec.nodeSelector == null) spec.nodeSelector = {};
1122+
// keys.forEach(key => {
1123+
// spec.nodeSelector[key] = item[key];
1124+
// })
1125+
// }
1126+
// }
1127+
if (user.nodered && user.nodered && (user.nodered as any).nodeselector && Config.nodered_allow_nodeselector) {
1128+
var spec: any = _deployment.spec.template.spec;
1129+
const keys = Object.keys((user.nodered as any).nodeselector);
1130+
if (spec.nodeSelector == null) spec.nodeSelector = {};
1131+
keys.forEach(key => {
1132+
spec.nodeSelector[key] = (user.nodered as any).nodeselector[key];
1133+
})
11261134
}
11271135
try {
11281136
await KubeUtil.instance().AppsV1Api.createNamespacedDeployment(namespace, (_deployment as any));
@@ -2145,7 +2153,7 @@ export class Message {
21452153
if (billing.memory != newmemory) {
21462154
billing.memory = newmemory;
21472155
billing = await Config.db._UpdateOne(null, billing, "users", 3, true, rootjwt);
2148-
this._EnsureNoderedInstance(cli, msg.userid, true, null);
2156+
this._EnsureNoderedInstance(cli, msg.userid, true);
21492157
}
21502158
if (customer != null && !NoderedUtil.IsNullEmpty(billing.coupon) && customer.discount != null) {
21512159
if (billing.coupon != customer.discount.coupon.name) {

OpenFlow/src/public/Controllers.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,9 @@ export class NoderedCtrl {
26882688
if (this.user.nodered != null && this.user.nodered.resources != null && this.user.nodered.resources.limits != null) {
26892689
this.limitsmemory = this.user.nodered.resources.limits.memory;
26902690
}
2691+
if (this.user.nodered != null && (this.user.nodered as any).nodeselector != null) {
2692+
this.label = JSON.stringify((this.user.nodered as any).nodeselector);
2693+
}
26912694
this.name = this.name.split("@").join("").split(".").join("");
26922695
this.name = this.name.toLowerCase();
26932696
// this.noderedurl = "https://" + WebSocketClientService.nodered_domain_schema.replace("$nodered_id$", this.name);
@@ -2719,6 +2722,10 @@ export class NoderedCtrl {
27192722
}
27202723
}
27212724
}
2725+
if (this.label) {
2726+
if (this.user.nodered == null) this.user.nodered = new NoderedConfig();
2727+
(this.user.nodered as any).nodeselector = JSON.parse(this.label);
2728+
}
27222729
this.loading = true;
27232730
this.messages = 'Updating ' + this.user.name + "\n" + this.messages;
27242731
if (!this.$scope.$$phase) { this.$scope.$apply(); }
@@ -2795,7 +2802,7 @@ export class NoderedCtrl {
27952802
async EnsureNoderedInstance() {
27962803
try {
27972804
this.errormessage = "";
2798-
await NoderedUtil.EnsureNoderedInstance(this.userid, false, this.label, null);
2805+
await NoderedUtil.EnsureNoderedInstance(this.userid, false, null);
27992806
this.messages = "EnsureNoderedInstance completed" + "\n" + this.messages;
28002807
this.GetNoderedInstance();
28012808
} catch (error) {

OpenFlow/src/public/Nodered.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h1 translate lib="web">nodered</h1>
106106
</div>
107107
</section>
108108
<section>
109-
<div class="form-group" ng-show="menuctrl.hasrole('admins') && ctrl.labels && ctrl.labels.length > 0">
109+
<div class="form-group" ng-show="menuctrl.hasrole('admins') && ctrl.labels && ctrl.keys && ctrl.keys.length > 0">
110110
<label class="col-sm-3 control-label"><span translate lib="web">label</span>: </label>
111111
<div class="col-sm-9">
112112
<select class="form-control" ng-model="ctrl.label">

OpenFlowNodeRED/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/nodered",
3-
"version": "1.1.114",
3+
"version": "1.1.115",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.114
1+
1.1.115

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ gulp.task("latest", shell.task([
7676
'echo "Push openiap/openflow"',
7777
'docker push openiap/openflow:latest',
7878
]));
79-
79+
gulp.task("composelatest", gulp.series("compose", "latest"));
8080

8181
gulp.task("bumpyml1", function () {
8282
return gulp.src(["./*.yml"]).pipe(replace(/openflow:\d+(\.\d+)+/g, 'openflow:' + version)).

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.1.114",
3+
"version": "1.1.115",
44
"description": "Simple wrapper around NodeRed, RabbitMQ and MongoDB to support a more scaleable NodeRed implementation.\r Also the \"backend\" for [OpenRPA](https://github.com/skadefro/OpenRPA)",
55
"main": "index.js",
66
"scripts": {
@@ -65,7 +65,7 @@
6565
"multer": "^1.4.2",
6666
"multer-gridfs-storage": "^4.2.0",
6767
"oauth2-server": "^3.1.1",
68-
"openflow-api": "npm:@openiap/openflow-api@^1.0.52",
68+
"openflow-api": "npm:@openiap/openflow-api@^1.0.53",
6969
"os-service": "^2.2.0",
7070
"passport": "^0.4.1",
7171
"passport-google-oauth20": "^2.0.0",

0 commit comments

Comments
 (0)