simplify runtime logs

This commit is contained in:
Asim Aslam
2020-08-11 22:57:30 +01:00
parent 69a53e8070
commit 375b67ee16
4 changed files with 23 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ type klog struct {
options runtime.LogsOptions
}
func (k *klog) podLogStream(podName string, stream *kubeStream) error {
func (k *klog) podLogs(podName string, stream *kubeStream) error {
p := make(map[string]string)
p["follow"] = "true"
@@ -51,7 +51,7 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) error {
return stream.Error()
default:
if s.Scan() {
record := runtime.LogRecord{
record := runtime.Log{
Message: s.Text(),
}
select {
@@ -101,7 +101,7 @@ func (k *klog) getMatchingPods() ([]string, error) {
return matches, nil
}
func (k *klog) Read() ([]runtime.LogRecord, error) {
func (k *klog) Read() ([]runtime.Log, error) {
pods, err := k.getMatchingPods()
if err != nil {
return nil, err
@@ -110,7 +110,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
return nil, errors.NotFound("runtime.logs", "no such service")
}
var records []runtime.LogRecord
var records []runtime.Log
for _, pod := range pods {
logParams := make(map[string]string)
@@ -145,7 +145,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
s := bufio.NewScanner(logs)
for s.Scan() {
record := runtime.LogRecord{
record := runtime.Log{
Message: s.Text(),
}
// record.Metadata["pod"] = pod
@@ -159,7 +159,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
return records, nil
}
func (k *klog) Stream() (runtime.LogStream, error) {
func (k *klog) Stream() (runtime.Logs, error) {
// find the matching pods
pods, err := k.getMatchingPods()
if err != nil {
@@ -170,14 +170,14 @@ func (k *klog) Stream() (runtime.LogStream, error) {
}
stream := &kubeStream{
stream: make(chan runtime.LogRecord),
stream: make(chan runtime.Log),
stop: make(chan bool),
}
// stream from the individual pods
for _, pod := range pods {
go func(podName string) {
err := k.podLogStream(podName, stream)
err := k.podLogs(podName, stream)
if err != nil {
log.Errorf("Error streaming from pod: %v", err)
}