Răsfoiți Sursa

logs integrated with projects organization

sunguroku 5 ani în urmă
părinte
comite
90e6b1ddfe

+ 0 - 29
dashboard/src/main/home/cluster-dashboard/expanded-chart/LogSection.tsx

@@ -1,29 +0,0 @@
-import React, { Component } from 'react';
-import styled from 'styled-components';
-
-type PropsType = {
-};
-
-type StateType = {
-};
-
-export default class LogSection extends Component<PropsType, StateType> {
-  state = {
-  }
-
-  render() {
-    return (
-      <StyledLogSection>
-        (Logs unimplemented)
-      </StyledLogSection>
-    );
-  }
-}
-
-const StyledLogSection = styled.div`
-  width: 100%;
-  height: 100%;
-  background: #202227;
-  position: relative;
-  padding: 20px;
-`;

+ 6 - 2
dashboard/src/main/home/cluster-dashboard/expanded-chart/log/LogSection.tsx

@@ -45,11 +45,15 @@ export default class LogSection extends Component<PropsType, StateType> {
 
   componentDidMount() {
     const { selectors } = this.props;
+    let { currentCluster, currentProject } = this.context;
 
     api.getMatchingPods('<token>', { 
-      context: this.context.currentCluster,
+      cluster_id: currentCluster.id,
+      service_account_id: currentCluster.service_account_id,
       selectors,
-    }, {}, (err: any, res: any) => {
+    }, {
+      id: currentProject.id
+    }, (err: any, res: any) => {
       this.setState({pods: res.data, selectedPod: res.data[0]})
     })
   }

+ 6 - 4
dashboard/src/main/home/cluster-dashboard/expanded-chart/log/Logs.tsx

@@ -11,12 +11,12 @@ type StateType = {
 };
 
 export default class Logs extends Component<PropsType, StateType> {
+  
   state = {
     logs: [] as string[],
   }
 
   scrollRef = React.createRef<HTMLDivElement>()
-  ws = new WebSocket(`ws://localhost:8080/api/k8s/default/pod/${this.props.selectedPod}/logs?context=${this.context.currentCluster}`)
 
   scrollToBottom = () => {
     this.scrollRef.current.scrollTop = this.scrollRef.current.scrollHeight
@@ -29,11 +29,14 @@ export default class Logs extends Component<PropsType, StateType> {
   }
 
   componentDidMount() {
-    this.ws.onopen = () => {
+    let { currentCluster, currentProject } = this.context;
+    let ws = new WebSocket(`ws://localhost:8080/api/projects/${currentProject.id}/k8s/default/pod/${this.props.selectedPod}/logs?cluster_id=${currentCluster.id}&service_account_id=${currentCluster.service_account_id}`)
+
+    ws.onopen = () => {
       console.log('connected to websocket')
     }
 
-    this.ws.onmessage = evt => {
+    ws.onmessage = evt => {
       this.setState({ logs: [...this.state.logs, evt.data] }, () => {
         this.scrollToBottom()
       })
@@ -51,7 +54,6 @@ export default class Logs extends Component<PropsType, StateType> {
 
 Logs.contextType = Context;
 
-
 const LogStream = styled.div`
   width: 70%;
   height: 100%;

+ 5 - 2
dashboard/src/shared/api.tsx

@@ -79,9 +79,12 @@ const getNamespaces = baseApi<{
 });
 
 const getMatchingPods = baseApi<{
-  context: string,
+  cluster_id: number,
+  service_account_id: number,
   selectors: string[]
-}>('GET', `/api/k8s/pods`);
+}, { id: number }>('GET', pathParams => {
+  return `/api/projects/${pathParams.id}/k8s/pods`;
+});
 
 const getRevisions = baseApi<{
   namespace: string,

+ 2 - 0
server/api/k8s_handler.go

@@ -129,6 +129,8 @@ func (app *App) HandleGetPodLogs(w http.ResponseWriter, r *http.Request) {
 		agent, err = kubernetes.GetAgentOutOfClusterConfig(form.OutOfClusterConfig)
 	}
 
+	upgrader.CheckOrigin = func(r *http.Request) bool { return true }
+
 	// upgrade to websocket.
 	conn, err := upgrader.Upgrade(w, r, nil)