-
Notifications
You must be signed in to change notification settings - Fork 3.8k
K8s mm less fixes #14028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
K8s mm less fixes #14028
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b7f8422
Upgrade the fabric client to support newer versions of k8s, add abili…
churromorales ae4248f
Fix dependencies check in build
churromorales c77cb94
Have to remove the concrete dependency and keep the api
churromorales 922afaa
Forgot to update the expected file in this commit
churromorales e655777
Adding code coverage, fixing some inspections
churromorales 9d14e46
Made a mistake on which mocks to call verify on
churromorales 9be2a23
Have to add the client back as a runtime dependency, otherwise we get…
churromorales 4d76e5f
Last change and some log fixes to work with k8s 1.25
churromorales 1e97768
Update docs/development/extensions-contrib/k8s-jobs.md
churromorales 55875f2
Changes per PR review
churromorales 4b836f3
Merge branch 'master' into k8s-mm-less-fixes
churromorales 4e8bb9d
Update docs/development/extensions-contrib/k8s-jobs.md
churromorales c28d260
Small fix to make the config match the docs and fixed a typo in the t…
churromorales 79c1e6b
Merge branch 'master' into k8s-mm-less-fixes
churromorales 82e316a
Removing the un-needed code coverage happy test
churromorales 2871150
Merge conflicts due to the PodTemplateTaskAdapter commit
churromorales de4378d
Merge remote-tracking branch 'upstream/master' into k8s-mm-less-fixes
12cce38
Fabric8 upgrade for PodTemplateTaskAdapter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,13 +25,11 @@ | |
| import io.fabric8.kubernetes.api.model.PodList; | ||
| import io.fabric8.kubernetes.api.model.batch.v1.Job; | ||
| import io.fabric8.kubernetes.client.KubernetesClient; | ||
| import org.apache.commons.io.input.ReaderInputStream; | ||
| import io.fabric8.kubernetes.client.dsl.LogWatch; | ||
| import org.apache.druid.java.util.common.RetryUtils; | ||
| import org.apache.druid.java.util.emitter.EmittingLogger; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.io.Reader; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.Timestamp; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
@@ -78,7 +76,7 @@ public Pod launchJobAndWaitForStart(Job job, long howLong, TimeUnit timeUnit) | |
| long start = System.currentTimeMillis(); | ||
| // launch job | ||
| return clientApi.executeRequest(client -> { | ||
| client.batch().v1().jobs().inNamespace(namespace).create(job); | ||
| client.batch().v1().jobs().inNamespace(namespace).resource(job).create(); | ||
| K8sTaskId taskId = new K8sTaskId(job.getMetadata().getName()); | ||
| log.info("Successfully submitted job: %s ... waiting for job to launch", taskId); | ||
| // wait until the pod is running or complete or failed, any of those is fine | ||
|
|
@@ -106,7 +104,8 @@ public JobResponse waitForJobCompletion(K8sTaskId taskId, long howLong, TimeUnit | |
| .inNamespace(namespace) | ||
| .withName(taskId.getK8sTaskId()) | ||
| .waitUntilCondition( | ||
| x -> (x == null) || (x.getStatus() != null && x.getStatus().getActive() == null), | ||
| x -> (x == null) || (x.getStatus() != null && x.getStatus().getActive() == null | ||
| && (x.getStatus().getFailed() != null || x.getStatus().getSucceeded() != null)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this makes sense to me but what was the reasoning for adding this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More context here |
||
| howLong, | ||
| unit | ||
| ); | ||
|
|
@@ -116,6 +115,7 @@ public JobResponse waitForJobCompletion(K8sTaskId taskId, long howLong, TimeUnit | |
| if (job.getStatus().getSucceeded() != null) { | ||
| return new JobResponse(job, PeonPhase.SUCCEEDED); | ||
| } | ||
| log.warn("Task %s failed with status %s", taskId, job.getStatus()); | ||
| return new JobResponse(job, PeonPhase.FAILED); | ||
| }); | ||
| } | ||
|
|
@@ -124,12 +124,12 @@ public JobResponse waitForJobCompletion(K8sTaskId taskId, long howLong, TimeUnit | |
| public boolean cleanUpJob(K8sTaskId taskId) | ||
| { | ||
| if (!debugJobs) { | ||
| Boolean result = clientApi.executeRequest(client -> client.batch() | ||
| .v1() | ||
| .jobs() | ||
| .inNamespace(namespace) | ||
| .withName(taskId.getK8sTaskId()) | ||
| .delete()); | ||
| Boolean result = clientApi.executeRequest(client -> !client.batch() | ||
| .v1() | ||
| .jobs() | ||
| .inNamespace(namespace) | ||
| .withName(taskId.getK8sTaskId()) | ||
| .delete().isEmpty()); | ||
| if (result) { | ||
| log.info("Cleaned up k8s task: %s", taskId); | ||
| } else { | ||
|
|
@@ -146,23 +146,24 @@ public boolean cleanUpJob(K8sTaskId taskId) | |
| @Override | ||
| public Optional<InputStream> getPeonLogs(K8sTaskId taskId) | ||
| { | ||
| KubernetesClient k8sClient = clientApi.getClient(); | ||
| try { | ||
| return clientApi.executeRequest(client -> { | ||
| Reader reader = client.batch() | ||
| .v1() | ||
| .jobs() | ||
| .inNamespace(namespace) | ||
| .withName(taskId.getK8sTaskId()) | ||
| .inContainer("main") | ||
| .getLogReader(); | ||
| if (reader == null) { | ||
| return Optional.absent(); | ||
| } | ||
| return Optional.of(new ReaderInputStream(reader, StandardCharsets.UTF_8)); | ||
| }); | ||
| LogWatch logWatch = k8sClient.batch() | ||
| .v1() | ||
| .jobs() | ||
| .inNamespace(namespace) | ||
| .withName(taskId.getK8sTaskId()) | ||
| .inContainer("main") | ||
| .watchLog(); | ||
| if (logWatch == null) { | ||
| k8sClient.close(); | ||
| return Optional.absent(); | ||
| } | ||
| return Optional.of(new LogWatchInputStream(k8sClient, logWatch)); | ||
| } | ||
| catch (Exception e) { | ||
| log.error(e, "Error streaming logs from task: %s", taskId); | ||
| k8sClient.close(); | ||
| return Optional.absent(); | ||
| } | ||
| } | ||
|
|
@@ -183,17 +184,17 @@ public List<Job> listAllPeonJobs() | |
| public List<Pod> listPeonPods(Set<PeonPhase> phases) | ||
| { | ||
| return listPeonPods().stream() | ||
| .filter(x -> phases.contains(PeonPhase.getPhaseFor(x))) | ||
| .collect(Collectors.toList()); | ||
| .filter(x -> phases.contains(PeonPhase.getPhaseFor(x))) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Pod> listPeonPods() | ||
| { | ||
| PodList podList = clientApi.executeRequest(client -> client.pods().inNamespace(namespace)) | ||
| .withLabel(DruidK8sConstants.LABEL_KEY) | ||
| .list(); | ||
| return podList.getItems(); | ||
| return clientApi.executeRequest(client -> client.pods().inNamespace(namespace) | ||
| .withLabel(DruidK8sConstants.LABEL_KEY) | ||
| .list().getItems()); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -203,7 +204,12 @@ public int cleanCompletedJobsOlderThan(long howFarBack, TimeUnit timeUnit) | |
| return clientApi.executeRequest(client -> { | ||
| List<Job> jobs = getJobsToCleanup(listAllPeonJobs(), howFarBack, timeUnit); | ||
| jobs.forEach(x -> { | ||
| if (client.batch().v1().jobs().inNamespace(namespace).withName(x.getMetadata().getName()).delete()) { | ||
| if (!client.batch() | ||
| .v1() | ||
| .jobs() | ||
| .inNamespace(namespace) | ||
| .withName(x.getMetadata().getName()) | ||
| .delete().isEmpty()) { | ||
| numDeleted.incrementAndGet(); | ||
| } | ||
| }); | ||
|
|
@@ -257,5 +263,4 @@ Pod getMainJobPod(KubernetesClient client, K8sTaskId taskId) | |
| throw new KubernetesResourceNotFoundException("K8s pod with label: job-name=" + k8sTaskId + " not found"); | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this log line left in on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was part of the original PR, IMO this should be a debug log.