From 3b6cd286b0c7ca95ff4f0515bf60be7a075f98b4 Mon Sep 17 00:00:00 2001 From: Isala Piyarisi Date: Fri, 13 Aug 2021 22:59:45 +0530 Subject: [PATCH] Fixed a routing issue with go embed (#57) --- Dockerfile | 2 +- charts/logging-pipeline-plumber/Chart.yaml | 3 --- pkg/webserver/handlers.go | 29 +++++++++++++++++++--- ui/src/App.jsx | 2 +- ui/src/components/FlowList.jsx | 2 +- ui/src/components/TestStatus.jsx | 2 +- ui/src/libs/useQuery.js | 3 +++ ui/src/pages/DetailPage.jsx | 23 +++++++++++------ 8 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 ui/src/libs/useQuery.js diff --git a/Dockerfile b/Dockerfile index fa2d20a..1c32abf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ COPY pkg/ pkg/ COPY controllers/ controllers/ # Copy UI build -COPY --from=uibuild /workspace/build/* pkg/webserver/build/ +COPY --from=uibuild /workspace/build/ pkg/webserver/build/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go diff --git a/charts/logging-pipeline-plumber/Chart.yaml b/charts/logging-pipeline-plumber/Chart.yaml index 4b062e0..3a6da24 100644 --- a/charts/logging-pipeline-plumber/Chart.yaml +++ b/charts/logging-pipeline-plumber/Chart.yaml @@ -1,7 +1,6 @@ apiVersion: v2 name: logging-pipeline-plumber description: A Helm chart for Kubernetes - # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -11,12 +10,10 @@ description: A Helm chart for Kubernetes # a dependency of application charts to inject those utilities and functions into the rendering # pipeline. Library charts do not define any templates and therefore cannot be deployed. type: application - # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) version: 100.100.100-dev - # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/pkg/webserver/handlers.go b/pkg/webserver/handlers.go index 52d824c..991c1ad 100644 --- a/pkg/webserver/handlers.go +++ b/pkg/webserver/handlers.go @@ -7,16 +7,37 @@ import ( "net/http" "net/http/httputil" "net/url" + "os" + "path" "strings" ) -//go:embed build +//go:embed build/* var content embed.FS +type fsFunc func(name string) (fs.File, error) + +func (f fsFunc) Open(name string) (fs.File, error) { + return f(name) +} + func clientHandler() http.Handler { - fsys := fs.FS(content) - contentStatic, _ := fs.Sub(fsys, "build") - return http.FileServer(http.FS(contentStatic)) + handler := fsFunc(func(name string) (fs.File, error) { + assetPath := path.Join("build", name) + + // If we can't find the asset, return the default index.html + // content + f, err := content.Open(assetPath) + if os.IsNotExist(err) { + return content.Open("build/index.html") + } + + // Otherwise assume this is a legitimate request routed + // correctly + return f, err + }) + + return http.FileServer(http.FS(handler)) } func (ws *WebServer) ProxyToKubeAPI(res http.ResponseWriter, req *http.Request) { diff --git a/ui/src/App.jsx b/ui/src/App.jsx index dfb649e..5d3e032 100644 --- a/ui/src/App.jsx +++ b/ui/src/App.jsx @@ -28,7 +28,7 @@ function App() { - + diff --git a/ui/src/components/FlowList.jsx b/ui/src/components/FlowList.jsx index e3647e6..69d6315 100644 --- a/ui/src/components/FlowList.jsx +++ b/ui/src/components/FlowList.jsx @@ -69,7 +69,7 @@ export default function FlowList() { autoHeight disableExtendRowFullWidth onSelectionModelChange={getSelectedFlows} - onRowClick={(row) => history.push(`flowtest/${row.row.namespace}/${row.row.name}`)} + onRowClick={(row) => history.push(`flowtest?namespace=${row.row.namespace}&name=${row.row.name}`)} /> ); diff --git a/ui/src/components/TestStatus.jsx b/ui/src/components/TestStatus.jsx index 8f9b7cb..1227b3c 100644 --- a/ui/src/components/TestStatus.jsx +++ b/ui/src/components/TestStatus.jsx @@ -14,7 +14,7 @@ const TestStatus = ({
{tests?.map((match, index) => ( -
+
{ status[index] ?
Pass
diff --git a/ui/src/libs/useQuery.js b/ui/src/libs/useQuery.js new file mode 100644 index 0000000..905eb24 --- /dev/null +++ b/ui/src/libs/useQuery.js @@ -0,0 +1,3 @@ +export default function useQuery() { + return new URLSearchParams(useLocation().search); +} diff --git a/ui/src/pages/DetailPage.jsx b/ui/src/pages/DetailPage.jsx index 2c8ea48..c903398 100644 --- a/ui/src/pages/DetailPage.jsx +++ b/ui/src/pages/DetailPage.jsx @@ -2,15 +2,22 @@ import React, { useEffect, useState } from 'react'; import { Container, Grid, Paper, } from '@material-ui/core'; -import { useParams } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; import { getFlow, getFlowTest } from '../utils/flowtests/flowDetails'; import TestStatus from '../components/TestStatus'; +function useQuery() { + return new URLSearchParams(useLocation().search); +} + export default function DetailView() { - const { namespace, name } = useParams(); + const query = useQuery(); const [flowTest, setFlowTest] = useState(undefined); const [flow, setFlow] = useState(undefined); + const name = query.get('name'); + const namespace = query.get('namespace'); + useEffect(async () => { if (flowTest?.spec?.referenceFlow) { setFlow(await getFlow( @@ -38,19 +45,19 @@ export default function DetailView() {
Reference Flow
-
{`Kind: ${flowTest?.spec.referenceFlow.kind}`}
-
{`Namespace: ${flowTest?.spec.referenceFlow.namespace}`}
-
{`Name: ${flowTest?.spec.referenceFlow.name}`}
+
{`Kind: ${flowTest?.spec?.referenceFlow?.kind}`}
+
{`Namespace: ${flowTest?.spec?.referenceFlow?.namespace}`}
+
{`Name: ${flowTest?.spec?.referenceFlow?.name}`}
Reference Pod
-
{`Namespace: ${flowTest?.spec.referencePod.namespace}`}
-
{`Name: ${flowTest?.spec.referencePod.name}`}
+
{`Namespace: ${flowTest?.spec?.referencePod?.namespace}`}
+
{`Name: ${flowTest?.spec?.referencePod?.name}`}
Testing Logs
{flowTest?.spec?.sentMessages?.map((message) => ( -
+                
                   { message }
                 
))}