Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use authenticated client for getLogsStreamReaderFor #92

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading