Skip to content

Commit

Permalink
fix(runJob): fix output on multi container (#4102) (#4105)
Browse files Browse the repository at this point in the history
fixes a bug where you couldn't fetch output on jobs with multiple
containers. this was because we weren't specifying the exact container
name to fetch. update the method to take the container name.
  • Loading branch information
spinnakerbot authored and louisjimenez committed Oct 17, 2019
1 parent 9dae9f4 commit bd1a453
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ public String logs(
return status.getOutput();
}

public String jobLogs(KubernetesV2Credentials credentials, String namespace, String jobName) {
public String jobLogs(
KubernetesV2Credentials credentials, String namespace, String jobName, String containerName) {
List<String> command = kubectlNamespacedAuthPrefix(credentials, namespace);
command.add("logs");
command.add("job/" + jobName);
command.add("-c=" + containerName);

JobResult<String> status = jobExecutor.runJob(new JobRequest(command));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ public KubernetesV2JobStatus collectJob(String account, String location, String
}

public Map<String, Object> getFileContents(
String account, String location, String id, String filename) {
String account, String location, String id, String containerName) {
KubernetesV2Credentials credentials =
(KubernetesV2Credentials)
accountCredentialsProvider.getCredentials(account).getCredentials();
Map props = null;
try {
V1Job job = getKubernetesJob(account, location, id);
String logContents = credentials.jobLogs(location, job.getMetadata().getName());
String logContents =
credentials.jobLogs(location, job.getMetadata().getName(), containerName);
props = PropertyParser.extractPropertiesFromLog(logContents);
} catch (Exception e) {
log.error("Couldn't parse properties for account {} at {}", account, location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,12 @@ public String logs(String namespace, String podName, String containerName) {
() -> jobExecutor.logs(this, namespace, podName, containerName));
}

public String jobLogs(String namespace, String jobName) {
public String jobLogs(String namespace, String jobName, String containerName) {
return runAndRecordMetrics(
"logs", KubernetesKind.JOB, namespace, () -> jobExecutor.jobLogs(this, namespace, jobName));
"logs",
KubernetesKind.JOB,
namespace,
() -> jobExecutor.jobLogs(this, namespace, jobName, containerName));
}

public void scale(KubernetesKind kind, String namespace, String name, int replicas) {
Expand Down

0 comments on commit bd1a453

Please sign in to comment.