(ctx *gin.Context)
| 831 | } |
| 832 | |
| 833 | func (m *Modules) GetLogsStream(ctx *gin.Context) { |
| 834 | ctx.Header("Access-Control-Allow-Origin", "*") |
| 835 | |
| 836 | logCount := int64(100) |
| 837 | |
| 838 | logChan := make(chan string) |
| 839 | |
| 840 | go func() { |
| 841 | defer close(logChan) |
| 842 | |
| 843 | err := m.kubernetesClient.GetStreamedPodLogs( |
| 844 | ctx.Request.Context(), // we will have to pass the context for the k8s podClient - so it can stop the stream when the client disconnects |
| 845 | ctx.Param("namespace"), |
| 846 | ctx.Param("container"), |
| 847 | ctx.Param("name"), |
| 848 | &logCount, |
| 849 | logChan, |
| 850 | ) |
| 851 | if err != nil { |
| 852 | return |
| 853 | } |
| 854 | }() |
| 855 | |
| 856 | // stream logs to the client |
| 857 | ctx.Stream(func(w io.Writer) bool { |
| 858 | for { |
| 859 | select { |
| 860 | case log, ok := <-logChan: |
| 861 | if !ok { |
| 862 | return false |
| 863 | } |
| 864 | |
| 865 | ctx.SSEvent("pod-log", trimLogLine(log)) |
| 866 | return true |
| 867 | case <-ctx.Request.Context().Done(): |
| 868 | return false |
| 869 | case <-ctx.Done(): |
| 870 | return false |
| 871 | } |
| 872 | } |
| 873 | }) |
| 874 | } |
| 875 | |
| 876 | func (m *Modules) GetDeploymentLogs(ctx *gin.Context) { |
| 877 | ctx.Header("Access-Control-Allow-Origin", "*") |
nothing calls this directly
no test coverage detected