MCPcopy
hub / github.com/1Panel-dev/KubePi / startLogProcess

Function startLogProcess

pkg/logging/logging.go:121–155  ·  view source on GitHub ↗
(k8sClient kubernetes.Interface, namespace string, pod string, container string, tailLines int64, follow bool, previous bool,timestamps bool,session LogSession)

Source from the content-addressed store, hash-verified

119}
120
121func startLogProcess(k8sClient kubernetes.Interface, namespace string, pod string, container string, tailLines int64, follow bool, previous bool,timestamps bool,session LogSession) error {
122 reader, err := k8sClient.CoreV1().
123 Pods(namespace).
124 GetLogs(pod, &v1.PodLogOptions{
125 Container: container,
126 Follow: follow,
127 TailLines: &tailLines,
128 Previous : previous,
129 Timestamps:timestamps,
130 }).Stream(context.TODO())
131 if err != nil {
132 return err
133 }
134
135 ss := session.sockJSSession
136 for {
137 buf := make([]byte, 2048)
138 numBytes, err := reader.Read(buf)
139 if numBytes > 0 {
140 message := string(buf[:numBytes])
141 for _, val := range strings.Split(message, "\n") {
142 if strings.TrimSpace(val) == "" {
143 continue
144 }
145 err = ss.Send(strings.TrimSpace(val) + "\r\n")
146 if err != nil {
147 fmt.Println(err)
148 }
149 }
150 }
151 if err != nil {
152 return err
153 }
154 }
155}

Callers 1

WaitForLoggingStreamFunction · 0.85

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected