-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: upgrade kubernetes client from 11.0.0 -> 24.2.0, implement List+Watch in KubeWatcher #32
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b704490
feat: upgrade kubernetes client from 11.0.0 -> 24.2.0
bodom0015 604fd76
Update requirements.txt
bodom0015 11189b7
fix: supposedly resource_version isnt needed for 410: Gone anymore?
bodom0015 e4a9732
Merge branch 'lambert8/upgrade-kubernetes-client' of https://github.c…
bodom0015 7fb7046
fix: use List+Watch pattern for setting resource_version
bodom0015 b1b99a6
fix: keep outer resource_version for reset logic / handling 410: Gone
bodom0015 4f199b8
fix: syntax error
bodom0015 741d16a
fix: one more syntax error
bodom0015 b3c384c
Update values.prod.yaml
bodom0015 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 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 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 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 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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import json | ||
import time | ||
import threading | ||
|
||
from kubernetes import watch, config as kubeconfig | ||
from kubernetes.client import V1JobList | ||
from kubernetes.client.rest import ApiException | ||
from requests import HTTPError | ||
|
||
|
@@ -70,11 +72,16 @@ def run(self): | |
time.sleep(1) | ||
self.logger.info('KubeWatcher is connecting...') | ||
try: | ||
# Resource version is used to keep track of stream progress (in case of resume) | ||
# List all pods in watched namespace to get resource_version | ||
namespaced_jobs: V1JobList = kubejob.api_batch_v1.list_namespaced_job(namespace=kubejob.get_namespace()) | ||
resource_version = namespaced_jobs.metadata.resource_version if namespaced_jobs.metadata.resource_version else resource_version | ||
|
||
# Then, watch for new events using the most recent resource_version | ||
# Resource version is used to keep track of stream progress (in case of resume/retry) | ||
k8s_event_stream = w.stream(func=kubejob.api_batch_v1.list_namespaced_job, | ||
namespace=kubejob.get_namespace(), | ||
timeout_seconds=timeout_seconds, | ||
resource_version=resource_version) | ||
resource_version=resource_version, | ||
timeout_seconds=timeout_seconds) | ||
Comment on lines
-73
to
+84
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. Attempt to implement List+Watch pattern, as described here: |
||
|
||
self.logger.info('KubeWatcher connected!') | ||
|
||
|
@@ -147,7 +154,7 @@ def run(self): | |
k8s_event_stream = None | ||
if e.status == 410: | ||
# Resource too old | ||
resource_version = None | ||
resource_version = '' | ||
self.logger.warning("Resource too old (410) - reconnecting: " + str(e)) | ||
time.sleep(2) | ||
continue | ||
|
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.
Overriding configuration has changed between versions, but this is not required for how we are using the K8S API client