From f44d150a29ae6439c7943bfe3480cc40696e54b4 Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Thu, 11 Jul 2024 10:59:18 +0200 Subject: [PATCH 1/2] fix(testworkflows): displaying events (#5652) --- pkg/testworkflows/testworkflowcontroller/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testworkflows/testworkflowcontroller/utils.go b/pkg/testworkflows/testworkflowcontroller/utils.go index ad54220b0ca..77bb22bc4ef 100644 --- a/pkg/testworkflows/testworkflowcontroller/utils.go +++ b/pkg/testworkflows/testworkflowcontroller/utils.go @@ -12,7 +12,7 @@ import ( ) const ( - KubernetesLogTimeFormat = "2006-01-02T15:04:05.999999999Z" + KubernetesLogTimeFormat = "2006-01-02T15:04:05.000000000Z" KubernetesTimezoneLogTimeFormat = KubernetesLogTimeFormat + "07:00" ) From 1db9d5652eed2558424d4f1491e4353f78da3655 Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Thu, 11 Jul 2024 14:21:17 +0200 Subject: [PATCH 2/2] fix(testworkflows): storing logs for the services (#5656) --- pkg/testworkflows/testworkflowcontroller/logs.go | 10 +++++----- .../testworkflowcontroller/watchinstrumentedpod.go | 2 +- pkg/testworkflows/testworkflowprocessor/container.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/testworkflows/testworkflowcontroller/logs.go b/pkg/testworkflows/testworkflowcontroller/logs.go index 7fd97ef4bdc..b72b8b36807 100644 --- a/pkg/testworkflows/testworkflowcontroller/logs.go +++ b/pkg/testworkflows/testworkflowcontroller/logs.go @@ -43,7 +43,7 @@ type ContainerLog struct { // getContainerLogsStream is getting logs stream, and tries to reinitialize the stream on EOF. // EOF may happen not only on the actual container end, but also in case of the log rotation. // @see {@link https://stackoverflow.com/a/68673451} -func getContainerLogsStream(ctx context.Context, clientSet kubernetes.Interface, namespace, podName, containerName string, pod Channel[*corev1.Pod], since *time.Time) (io.Reader, error) { +func getContainerLogsStream(ctx context.Context, clientSet kubernetes.Interface, namespace, podName, containerName string, follow bool, pod Channel[*corev1.Pod], since *time.Time) (io.Reader, error) { // Fail immediately if the context is finished if ctx.Err() != nil { return nil, ctx.Err() @@ -58,7 +58,7 @@ func getContainerLogsStream(ctx context.Context, clientSet kubernetes.Interface, // Create logs stream request req := clientSet.CoreV1().Pods(namespace).GetLogs(podName, &corev1.PodLogOptions{ Container: containerName, - Follow: true, + Follow: follow, Timestamps: true, SinceTime: sinceTime, }) @@ -103,7 +103,7 @@ func getContainerLogsStream(ctx context.Context, clientSet kubernetes.Interface, return stream, nil } -func WatchContainerLogs(parentCtx context.Context, clientSet kubernetes.Interface, namespace, podName, containerName string, bufferSize int, pod Channel[*corev1.Pod]) Channel[ContainerLog] { +func WatchContainerLogs(parentCtx context.Context, clientSet kubernetes.Interface, namespace, podName, containerName string, follow bool, bufferSize int, pod Channel[*corev1.Pod]) Channel[ContainerLog] { ctx, ctxCancel := context.WithCancel(parentCtx) w := newChannel[ContainerLog](ctx, bufferSize) @@ -119,7 +119,7 @@ func WatchContainerLogs(parentCtx context.Context, clientSet kubernetes.Interfac var since *time.Time // Create logs stream request - stream, err := getContainerLogsStream(ctx, clientSet, namespace, podName, containerName, pod, since) + stream, err := getContainerLogsStream(ctx, clientSet, namespace, podName, containerName, follow, pod, since) hadAnyContent := false if err == io.EOF { return @@ -241,7 +241,7 @@ func WatchContainerLogs(parentCtx context.Context, clientSet kubernetes.Interfac } // Reinitialize logs stream since = common.Ptr(tsReader.ts.Add(1)) - stream, err = getContainerLogsStream(ctx, clientSet, namespace, podName, containerName, pod, since) + stream, err = getContainerLogsStream(ctx, clientSet, namespace, podName, containerName, follow, pod, since) if err != nil { return } diff --git a/pkg/testworkflows/testworkflowcontroller/watchinstrumentedpod.go b/pkg/testworkflows/testworkflowcontroller/watchinstrumentedpod.go index c98dd7b0678..1ae190e2f08 100644 --- a/pkg/testworkflows/testworkflowcontroller/watchinstrumentedpod.go +++ b/pkg/testworkflows/testworkflowcontroller/watchinstrumentedpod.go @@ -102,7 +102,7 @@ func WatchInstrumentedPod(parentCtx context.Context, clientSet kubernetes.Interf // Watch the container logs follow := common.ResolvePtr(opts.Follow, true) && !state.IsFinished(ref) - for v := range WatchContainerLogs(ctx, clientSet, podObj.Namespace, podObj.Name, ref, 10, pod).Channel() { + for v := range WatchContainerLogs(ctx, clientSet, podObj.Namespace, podObj.Name, ref, follow, 10, pod).Channel() { if v.Error != nil { s.Error(v.Error) } else if v.Value.Output != nil { diff --git a/pkg/testworkflows/testworkflowprocessor/container.go b/pkg/testworkflows/testworkflowprocessor/container.go index 7566a3a1061..1546965341b 100644 --- a/pkg/testworkflows/testworkflowprocessor/container.go +++ b/pkg/testworkflows/testworkflowprocessor/container.go @@ -468,7 +468,7 @@ func (c *container) Resolve(m ...expressions.Machine) error { } env := c.Env() name = name[4:] - for i := range env { + for i := len(env) - 1; i >= 0; i-- { if env[i].Name == name && env[i].ValueFrom == nil { value, err := expressions.EvalTemplate(env[i].Value) if err == nil {