Skip to content

Commit

Permalink
Use authenticated client for getLogsStreamReaderFor
Browse files Browse the repository at this point in the history
Instead of manually using http.NewRequest we should use the already existing + authenticated client
  • Loading branch information
faustsec authored Feb 1, 2024
1 parent 1831949 commit 0eb6315
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions proctord/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,25 @@ func (client *client) JobExecutionStatus(jobExecutionID string) (string, error)

func (client *client) getLogsStreamReaderFor(podName string) (io.ReadCloser, error) {
logger.Debug("reading pod logs for: ", podName)

req, err := http.NewRequest("GET", "https://"+config.KubeClusterHostName()+"/api/v1/namespaces/"+namespace+"/pods/"+podName+"/log?follow=true", nil)
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Basic "+config.KubeBasicAuthEncoded())
resp, err := client.httpClient.Do(req)
// req, err := http.NewRequest("GET", "https://"+config.KubeClusterHostName()+"/api/v1/namespaces/"+namespace+"/pods/"+podName+"/log?follow=true", nil)
// if err != nil {
// return nil, err
// }
// req.Header.Set("Authorization", "Basic "+config.KubeBasicAuthEncoded())
// resp, err := client.httpClient.Do(req)
// if err != nil {
// return nil, err
// }
// return resp.Body, err

// Use the authenticated client instead of manually requesting the control plane
clt := client.clientSet.CoreV1()
req := clt.Pods(namespace).GetLogs(podName, &v1.PodLogOptions{
Follow: true,
})
logs, err := req.Stream()
if err != nil {
return nil, err
}
return resp.Body, err
return logs, err
}

0 comments on commit 0eb6315

Please sign in to comment.