Skip to content

Commit

Permalink
feat(provider/kubernetes): runJob logs
Browse files Browse the repository at this point in the history
add support for capturing logs as part of `collectJob`. logs are added
to the job status. i'm not sure how well this scales as log size grows
so this may not be the best implementation, but it may work for the
short term. since execution details are persisted to volitile storage
storing them with the jobs status is best since the reference to the job
pod is also stored there.
  • Loading branch information
ethanfrogers committed Nov 20, 2017
1 parent c147e57 commit 9e73b28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class KubernetesJobStatus implements JobStatus, Serializable {
Set<String> securityGroups
@JsonIgnore
Pod pod
String logs

KubernetesJobStatus(Pod pod, String account) {
this.name = pod.metadata.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,27 @@ class KubernetesJobProvider implements JobProvider<KubernetesJobStatus> {
return null
}
def trueCredentials = (credentials as KubernetesNamedAccountCredentials).credentials
def status = new KubernetesJobStatus(trueCredentials.apiAdaptor.getPod(location, id), account)
def pod = trueCredentials.apiAdaptor.getPod(location, id)
def status = new KubernetesJobStatus(pod, account)

String podName = pod.getMetadata().getName()
StringBuilder logs = new StringBuilder()

pod.getSpec().getContainers().collect { container->
logs.append("===== ${container.getName()} =====\n\n")
try {
logs.append(trueCredentials.apiAdaptor.getLog(location, podName, container.getName()))
} catch(Exception e) {
logs.append(e.getMessage())
}
logs.append("\n\n")
}
status.logs = logs.toString()

if (status.jobState in [JobState.Failed, JobState.Succeeded]) {
trueCredentials.apiAdaptor.deletePod(location, id)
}

return status
}

Expand Down

0 comments on commit 9e73b28

Please sign in to comment.