From d3d22192143a4a1a7789fc27f050614d98c846d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81d=C3=A1m=20Sis=C3=A1k?=
<86593861+dzsak@users.noreply.github.com>
Date: Tue, 5 Mar 2024 09:16:51 +0100
Subject: [PATCH] Bug: Undefined error in services without ports (#59)
---
web/src/Service.jsx | 56 ++++++++++++++++++++++++++++-------------
web/src/service.test.js | 55 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+), 17 deletions(-)
create mode 100644 web/src/service.test.js
diff --git a/web/src/Service.jsx b/web/src/Service.jsx
index a5f4953..2d6e449 100644
--- a/web/src/Service.jsx
+++ b/web/src/Service.jsx
@@ -27,21 +27,8 @@ function Service(props) {
const configMapWidgets = configMaps(service.pods, service.svc.metadata.namespace, capacitorClient)
const secretWidgets = secrets(service.pods, service.svc.metadata.namespace, capacitorClient)
- const svcPort = service.svc.spec.ports[0].port
- let hostPort = ""
- if (svcPort) {
- if (svcPort <= 99) {
- hostPort = "100" + svcPort
- } else if (svcPort <= 999) {
- hostPort = "10" + svcPort
- } else {
- hostPort = svcPort
- }
-
- if (hostPort === "10080") { // Connections to HTTP, HTTPS or FTP servers on port 10080 will fail. This is a mitigation for the NAT Slipstream 2.0 attack.
- hostPort = "10081"
- }
- }
+ const appPort = getAppPort(service.svc.spec.ports) ?? "";
+ const hostPort = getHostPort(service.svc.spec.ports) ?? "";
return (
<>
@@ -167,7 +154,7 @@ function Service(props) {
@@ -185,7 +172,7 @@ function Service(props) {
) : null
}
- {svcPort &&
+ {service.svc.spec.ports &&
<>
http://127.0.0.1:{hostPort}