Skip to content

Commit

Permalink
fix(testworkflows): storing logs for the services (#5656)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Jul 11, 2024
1 parent a15368d commit aa1326b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/testworkflows/testworkflowcontroller/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
})
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowcontroller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
KubernetesLogTimeFormat = "2006-01-02T15:04:05.999999999Z"
KubernetesLogTimeFormat = "2006-01-02T15:04:05.000000000Z"
KubernetesTimezoneLogTimeFormat = KubernetesLogTimeFormat + "07:00"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowprocessor/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa1326b

Please sign in to comment.