') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Handle error events in watch by fabxc · Pull Request #102 · kubernetes-client/python-base · GitHub
Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Handle error events in watch - #102

Closed
fabxc wants to merge 1 commit into
kubernetes-client:masterfrom
fabxc:error-event
Closed

Handle error events in watch#102
fabxc wants to merge 1 commit into
kubernetes-client:masterfrom
fabxc:error-event

Conversation

@fabxc

Copy link
Copy Markdown

Raise an ApiException for error events that indicate a watch failure
despite the HTTP response indicating success.

Fixes#57

The ApiException constructor indicates that it's intended to be used manually as well. Thus it seemed convenient to use and is the least likely to break any callers that likely have handling for that exception in place already.

@roycaihw

@k8s-ci-robotk8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 15, 2018
@k8s-ci-robotk8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 15, 2018
@fabxc

Copy link
Copy Markdown
Author

/assign roycaihw

Comment threadwatch/watch_test.py
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fabxc
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: roycaihw

If they are not already assigned, you can assign the PR to them by writing /assign @roycaihw in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Raise an ApiException for error events that indicate a watch failure
despite the HTTP response indicating success.
Fixeskubernetes-client#57
Signed-off-by: Fabian Reinartz <freinartz@google.com>
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #102 into master will increase coverage by 0.07%.
The diff coverage is 96%.

Impacted file tree graph

@@ Coverage Diff @@## master #102 +/- ##
==========================================
+ Coverage 92.04% 92.12% +0.07% 
==========================================
Files 13 13 Lines 1182 1206 +24 ==========================================
+ Hits 1088 1111 +23 - Misses 94 95 +1
Impacted FilesCoverage Δ
watch/watch.py100% <100%> (ø)⬆️
watch/watch_test.py97.61% <94.73%> (-0.52%)⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 879ab01...bd98fd4. Read the comment docs.

@mitar

Copy link
Copy Markdown
Contributor

Should we really throw an exception here and not just retry the watch?

@mitar

Copy link
Copy Markdown
Contributor

On a better look, I do not think this fully addresses #57 in any case. To me unmarshal_event already fails because it cannot really convert the response data to API response of a rellevant type. I get:

...
File "/usr/local/lib/python3.6/dist-packages/kubernetes/watch/watch.py", line 141, in stream
yield self.unmarshal_event(line, return_type)
File "/usr/local/lib/python3.6/dist-packages/kubernetes/watch/watch.py", line 94, in unmarshal_event
js['object'] = self._api_client.deserialize(obj, return_type)
File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 236, in deserialize
return self.__deserialize(data, response_type)
File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 276, in __deserialize
return self.__deserialize_model(data, klass)
File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
instance = klass(**kwargs)
File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/models/v1_event.py", line 107, in __init__
self.involved_object = involved_object
File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/models/v1_event.py", line 266, in involved_object
raise ValueError("Invalid value for `involved_object`, must not be `None`")
ValueError: Invalid value for `involved_object`, must not be `None`

So, I think: this should be handled sooner, and it should just automatically resume if possible.

@mitar

Copy link
Copy Markdown
Contributor

I made slightly improved (in my view) version here: master...mitar:retry-watch

Would you maybe be interested in incorporating those changes here and updating tests here to trigger those other conditions as well? For example, I am using list_event_for_all_namespaces and I am getting the error above with just your patch. I had to add a check to not try to unmarshall it. We should have a test to make sure without that check code fails. I do not understand why in your case this does not happen, but maybe you used a different resource type which happens to be able to be unmarshalled even if it is in fact an error.

@fejta-bot

Copy link
Copy Markdown

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robotk8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 12, 2019
@mitarmitar mentioned this pull request May 12, 2019
@fejta-bot

Copy link
Copy Markdown

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robotk8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 11, 2019
@fejta-bot

Copy link
Copy Markdown

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

@fejta-bot: Closed this PR.

Details

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cncf-cla: yesIndicates the PR's author has signed the CNCF CLA.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.size/MDenotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Watch stream should handle HTTP error before unmarshaling event

7 participants

@fabxc@k8s-ci-robot@codecov-io@mitar@fejta-bot@micw523@roycaihw