Skip to content

Commit da322a4

Browse files
committed
Fix issue with kubernetes 1.22.3 and beta1Api
1 parent 7e4fa7e commit da322a4

5 files changed

Lines changed: 86 additions & 36 deletions

File tree

OpenFlow/src/KubeUtil.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CoreV1Api, AppsV1Api, ExtensionsV1beta1Api, VoidAuth, ApiKeyAuth, V1PodList } from "@kubernetes/client-node";
1+
import { CoreV1Api, AppsV1Api, ExtensionsV1beta1Api, VoidAuth, ApiKeyAuth, V1PodList, NetworkingV1Api } from "@kubernetes/client-node";
22
import http = require('http');
33
const localVarRequest = require("request");
44
let defaultBasePath = 'https://localhost';
@@ -8,6 +8,7 @@ export class KubeUtil {
88
public AppsV1Api: AppsV1Api = null; // kc.makeApiClient(k8s.AppsV1Api);
99
public ExtensionsV1beta1Api: ExtensionsV1beta1Api = null; // kc.makeApiClient(k8s.ExtensionsV1beta1Api);
1010
public Metricsv1beta1Api: Metricsv1beta1Api = null;
11+
public NetworkingV1Api: NetworkingV1Api = null; // kc.makeApiClient(k8s.NetworkingV1Api);
1112

1213
private static _instance: KubeUtil = null;
1314
public static instance(): KubeUtil {
@@ -39,6 +40,7 @@ export class KubeUtil {
3940
this.AppsV1Api = kc.makeApiClient(k8s.AppsV1Api);
4041
this.ExtensionsV1beta1Api = kc.makeApiClient(k8s.ExtensionsV1beta1Api);
4142
this.Metricsv1beta1Api = kc.makeApiClient(Metricsv1beta1Api);
43+
this.NetworkingV1Api = kc.makeApiClient(NetworkingV1Api);
4244
}
4345

4446
async GetStatefulSet(namespace, name) {
@@ -92,6 +94,14 @@ export class KubeUtil {
9294
}
9395
return null;
9496
}
97+
async GetIngressV1(namespace, name) {
98+
const list = await this.NetworkingV1Api.listNamespacedIngress(namespace);
99+
for (let i = 0; i < list.body.items.length; i++) {
100+
const item = list.body.items[i];
101+
if (item.metadata.name == name) return item;
102+
}
103+
return null;
104+
}
95105

96106
async GetPodMetrics(namespace, name) {
97107
var list = await this.Metricsv1beta1Api.GetPod(namespace, name);

OpenFlow/src/Messages/Message.ts

Lines changed: 72 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,17 +2347,18 @@ export class Message {
23472347
await KubeUtil.instance().CoreV1Api.createNamespacedService(namespace, _service);
23482348
}
23492349
Logger.instanse.debug("[" + _tuser.username + "] GetIngress useringress");
2350-
const ingress = await KubeUtil.instance().GetIngressV1beta1(namespace, "useringress");
2351-
if (ingress !== null) {
2352-
let rule = null;
2353-
for (let i = 0; i < ingress.spec.rules.length; i++) {
2354-
if (ingress.spec.rules[i].host == hostname) {
2355-
rule = ingress.spec.rules[i];
2350+
2351+
if (Config.use_ingress_beta1_syntax) {
2352+
const ingress = await KubeUtil.instance().GetIngressV1beta1(namespace, "useringress");
2353+
if (ingress !== null) {
2354+
let rule = null;
2355+
for (let i = 0; i < ingress.spec.rules.length; i++) {
2356+
if (ingress.spec.rules[i].host == hostname) {
2357+
rule = ingress.spec.rules[i];
2358+
}
23562359
}
2357-
}
2358-
if (rule == null) {
2359-
Logger.instanse.debug("[" + _tuser.username + "] ingress " + hostname + " not found in useringress creating it");
2360-
if (Config.use_ingress_beta1_syntax) {
2360+
if (rule == null) {
2361+
Logger.instanse.debug("[" + _tuser.username + "] ingress " + hostname + " not found in useringress creating it");
23612362
rule = {
23622363
host: hostname,
23632364
http: {
@@ -2371,39 +2372,78 @@ export class Message {
23712372
}
23722373
}
23732374
ingress.spec.rules.push(rule);
2374-
} else {
2375-
rule = {
2376-
host: hostname,
2377-
http: {
2378-
paths: [{
2379-
path: "/",
2380-
pathType: "Prefix",
2381-
backend: {
2382-
service: {
2383-
name: servicename,
2384-
port: {
2385-
number: port
2375+
delete ingress.metadata.creationTimestamp;
2376+
delete ingress.status;
2377+
Logger.instanse.debug("[" + _tuser.username + "] replaceNamespacedIngress");
2378+
await KubeUtil.instance().ExtensionsV1beta1Api.replaceNamespacedIngress("useringress", namespace, ingress);
2379+
}
2380+
} else {
2381+
Logger.instanse.error("[" + _tuser.username + "] failed locating useringress");
2382+
throw new Error("failed locating useringress");
2383+
}
2384+
} else {
2385+
const ingress = await KubeUtil.instance().GetIngressV1(namespace, "useringress");
2386+
if (ingress !== null) {
2387+
let rule = null;
2388+
for (let i = 0; i < ingress.spec.rules.length; i++) {
2389+
if (ingress.spec.rules[i].host == hostname) {
2390+
rule = ingress.spec.rules[i];
2391+
}
2392+
}
2393+
if (rule == null) {
2394+
Logger.instanse.debug("[" + _tuser.username + "] ingress " + hostname + " not found in useringress creating it");
2395+
if (Config.use_ingress_beta1_syntax) {
2396+
rule = {
2397+
host: hostname,
2398+
http: {
2399+
paths: [{
2400+
path: "/",
2401+
backend: {
2402+
serviceName: servicename,
2403+
servicePort: "www"
2404+
}
2405+
}]
2406+
}
2407+
}
2408+
ingress.spec.rules.push(rule);
2409+
} else {
2410+
rule = {
2411+
host: hostname,
2412+
http: {
2413+
paths: [{
2414+
path: "/",
2415+
pathType: "Prefix",
2416+
backend: {
2417+
service: {
2418+
name: servicename,
2419+
port: {
2420+
number: port
2421+
}
23862422
}
23872423
}
2388-
}
2389-
}]
2424+
}]
2425+
}
23902426
}
2427+
ingress.spec.rules.push(rule);
23912428
}
2392-
ingress.spec.rules.push(rule);
2429+
delete ingress.metadata.creationTimestamp;
2430+
delete ingress.status;
2431+
Logger.instanse.debug("[" + _tuser.username + "] replaceNamespacedIngress");
2432+
await KubeUtil.instance().NetworkingV1Api.replaceNamespacedIngress("useringress", namespace, ingress);
23932433
}
2394-
delete ingress.metadata.creationTimestamp;
2395-
delete ingress.status;
2396-
Logger.instanse.debug("[" + _tuser.username + "] replaceNamespacedIngress");
2397-
await KubeUtil.instance().ExtensionsV1beta1Api.replaceNamespacedIngress("useringress", namespace, ingress);
2434+
} else {
2435+
Logger.instanse.error("[" + _tuser.username + "] failed locating useringress");
2436+
throw new Error("failed locating useringress");
23982437
}
2399-
} else {
2400-
Logger.instanse.error("[" + _tuser.username + "] failed locating useringress");
2401-
throw new Error("failed locating useringress");
24022438
}
2439+
24032440
} catch (error) {
24042441
if (error.response && error.response.body && error.response.body.message) {
24052442
Logger.instanse.error(new Error(error.response.body.message));
24062443
error.message = error.response.body.message;
2444+
} else if (error.response && error.response.body) {
2445+
Logger.instanse.error(new Error(error.response.body));
2446+
error.message = error.response.body;
24072447
}
24082448
span?.recordException(error);
24092449
throw error;

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.3.105",
3+
"version": "1.3.106",
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.3.105
1+
1.3.106

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openiap/openflow",
3-
"version": "1.3.105",
3+
"version": "1.3.106",
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": {

0 commit comments

Comments
 (0)