{error.message.length !== 0 && (
@@ -85,12 +95,12 @@ const DaemonSet = ({ name, namespace }: Props) => {
orientationMargin="0"
orientation={"left"}
>
- Pods: {daemonSet.pods.length}
+ Replicas: {getPodsLength()}
diff --git a/cyclops-ui/src/components/k8s-resources/Deployment.tsx b/cyclops-ui/src/components/k8s-resources/Deployment.tsx
index c4897309..e94cc92e 100644
--- a/cyclops-ui/src/components/k8s-resources/Deployment.tsx
+++ b/cyclops-ui/src/components/k8s-resources/Deployment.tsx
@@ -3,15 +3,15 @@ import { Col, Divider, Row, Alert } from "antd";
import axios from "axios";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
-import { resourceStream } from "../../utils/api/sse/resources";
import { isStreamingEnabled } from "../../utils/api/common";
interface Props {
name: string;
namespace: string;
+ workload: any;
}
-const Deployment = ({ name, namespace }: Props) => {
+const Deployment = ({ name, namespace, workload }: Props) => {
const [deployment, setDeployment] = useState({
status: "",
pods: [],
@@ -21,14 +21,6 @@ const Deployment = ({ name, namespace }: Props) => {
description: "",
});
- useEffect(() => {
- if (isStreamingEnabled()) {
- resourceStream(`apps`, `v1`, `Deployment`, name, namespace, (r: any) => {
- setDeployment(r);
- });
- }
- }, [name, namespace]);
-
const fetchDeployment = useCallback(() => {
axios
.get(`/api/resources`, {
@@ -52,7 +44,7 @@ const Deployment = ({ name, namespace }: Props) => {
fetchDeployment();
if (isStreamingEnabled()) {
- return () => {};
+ return;
}
const interval = setInterval(() => fetchDeployment(), 15000);
@@ -61,6 +53,24 @@ const Deployment = ({ name, namespace }: Props) => {
};
}, [fetchDeployment]);
+ function getPods() {
+ if (workload && isStreamingEnabled()) {
+ return workload.pods;
+ }
+
+ return deployment.pods;
+ }
+
+ function getPodsLength() {
+ let pods = getPods();
+
+ if (Array.isArray(pods)) {
+ return pods.length;
+ }
+
+ return 0;
+ }
+
return (
{error.message.length !== 0 && (
@@ -84,13 +94,13 @@ const Deployment = ({ name, namespace }: Props) => {
orientationMargin="0"
orientation={"left"}
>
- Replicas: {deployment.pods.length}
+ Replicas: {getPodsLength()}
{}}
/>
diff --git a/cyclops-ui/src/components/k8s-resources/StatefulSet.tsx b/cyclops-ui/src/components/k8s-resources/StatefulSet.tsx
index 8fab853e..a967cfc9 100644
--- a/cyclops-ui/src/components/k8s-resources/StatefulSet.tsx
+++ b/cyclops-ui/src/components/k8s-resources/StatefulSet.tsx
@@ -3,21 +3,16 @@ import { Col, Divider, Row, Alert } from "antd";
import axios from "axios";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
-import { resourceStream } from "../../utils/api/sse/resources";
import { isStreamingEnabled } from "../../utils/api/common";
interface Props {
name: string;
namespace: string;
+ workload: any;
}
-interface Statefulset {
- status: string;
- pods: any[];
-}
-
-const StatefulSet = ({ name, namespace }: Props) => {
- const [statefulSet, setStatefulSet] = useState({
+const StatefulSet = ({ name, namespace, workload }: Props) => {
+ const [statefulSet, setStatefulSet] = useState({
status: "",
pods: [],
});
@@ -27,14 +22,6 @@ const StatefulSet = ({ name, namespace }: Props) => {
description: "",
});
- useEffect(() => {
- if (isStreamingEnabled()) {
- resourceStream(`apps`, `v1`, `StatefulSet`, name, namespace, (r: any) => {
- setStatefulSet(r);
- });
- }
- }, [name, namespace]);
-
const fetchStatefulSet = useCallback(() => {
axios
.get(`/api/resources`, {
@@ -58,7 +45,7 @@ const StatefulSet = ({ name, namespace }: Props) => {
fetchStatefulSet();
if (isStreamingEnabled()) {
- return () => {};
+ return;
}
const interval = setInterval(() => fetchStatefulSet(), 15000);
@@ -67,6 +54,24 @@ const StatefulSet = ({ name, namespace }: Props) => {
};
}, [fetchStatefulSet]);
+ function getPods() {
+ if (workload && isStreamingEnabled()) {
+ return workload.pods;
+ }
+
+ return statefulSet.pods;
+ }
+
+ function getPodsLength() {
+ let pods = getPods();
+
+ if (Array.isArray(pods)) {
+ return pods.length;
+ }
+
+ return 0;
+ }
+
return (
{error.message.length !== 0 && (
@@ -90,13 +95,13 @@ const StatefulSet = ({ name, namespace }: Props) => {
orientationMargin="0"
orientation={"left"}
>
- Replicas: {statefulSet.pods.length}
+ Replicas: {getPodsLength()}
{}}
/>
diff --git a/cyclops-ui/src/components/pages/ModuleDetails.tsx b/cyclops-ui/src/components/pages/ModuleDetails.tsx
index f1b3fd81..612f171b 100644
--- a/cyclops-ui/src/components/pages/ModuleDetails.tsx
+++ b/cyclops-ui/src/components/pages/ModuleDetails.tsx
@@ -60,6 +60,13 @@ import {
RestartButton,
} from "../k8s-resources/common/RestartButton";
import YAML from "yaml";
+import { isStreamingEnabled } from "../../utils/api/common";
+import { resourcesStream } from "../../utils/api/sse/resources";
+import {
+ isWorkload,
+ ResourceRef,
+ resourceRefKey,
+} from "../../utils/resourceRef";
const languages = [
"javascript",
@@ -109,12 +116,9 @@ interface module {
iconURL: string;
}
-interface resourceRef {
- group: string;
- version: string;
- kind: string;
- name: string;
- namespace: string;
+interface workload {
+ status: string;
+ pods: any[];
}
const ModuleDetails = () => {
@@ -138,6 +142,23 @@ const ModuleDetails = () => {
const [deleteResourceVerify, setDeleteResourceVerify] = useState("");
const [resources, setResources] = useState([]);
+ const [workloads, setWorkloads] = useState