Skip to content

Commit 2868535

Browse files
committed
Set TerminationMessagePolicy on Initializer to use logs as fallback
While not explicitly used, with the removal of the log fetching from the Initializer (Job->Pod->Container) any potential source for verbose information about the error might be lost. The Kubernetes approach to provide more details than the exit code about the reason a container terminated is the termination message (see [1]). Per default this message needs to be explictly written to `/dev/termination-log`, but there also is the option to use the last bit of log output as fallback source. [1] https://kubernetes.io/docs/tasks/debug/debug-application/determine-reason-pod-failure/
1 parent 24d1922 commit 2868535

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

pkg/resources/jobs/initializer.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ func NewInitializerJob(k6 v1alpha1.TestRunI, argLine string) (*batchv1.Job, erro
114114
InitContainers: getInitContainers(k6.GetSpec().Initializer, script),
115115
Containers: []corev1.Container{
116116
{
117-
Image: image,
118-
ImagePullPolicy: k6.GetSpec().Initializer.ImagePullPolicy,
119-
Name: "k6",
120-
Command: command,
121-
Env: env,
122-
Resources: k6.GetSpec().Initializer.Resources,
123-
VolumeMounts: volumeMounts,
124-
EnvFrom: k6.GetSpec().Initializer.EnvFrom,
125-
Ports: ports,
126-
SecurityContext: &k6.GetSpec().Initializer.ContainerSecurityContext,
117+
Image: image,
118+
ImagePullPolicy: k6.GetSpec().Initializer.ImagePullPolicy,
119+
Name: "k6",
120+
Command: command,
121+
Env: env,
122+
Resources: k6.GetSpec().Initializer.Resources,
123+
VolumeMounts: volumeMounts,
124+
EnvFrom: k6.GetSpec().Initializer.EnvFrom,
125+
Ports: ports,
126+
SecurityContext: &k6.GetSpec().Initializer.ContainerSecurityContext,
127+
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
127128
},
128129
},
129130
Volumes: volumes,

pkg/resources/jobs/initializer_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ func TestNewInitializerJob(t *testing.T) {
9393
},
9494
},
9595
},
96-
Resources: corev1.ResourceRequirements{},
97-
VolumeMounts: script.VolumeMount(),
98-
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
99-
SecurityContext: &corev1.SecurityContext{},
96+
Resources: corev1.ResourceRequirements{},
97+
VolumeMounts: volumeMounts,
98+
Ports: []corev1.ContainerPort{{ContainerPort: 6565}},
99+
SecurityContext: &corev1.SecurityContext{},
100+
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
100101
},
101102
},
102103
Volumes: volumes,

0 commit comments

Comments
 (0)