Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Remove an abstraction leak of a Response object — for type-hinting #197

Merged
merged 1 commit into from
Oct 5, 2019

Conversation

nolar
Copy link
Contributor

@nolar nolar commented Oct 1, 2019

Refactor clients-to-reactor communication to prepare for the overall type-hinting.

Issue : #194

Description

Since the switch to pykube-ng (#71 #110), there was an abstraction leak in the list-fetching client wrapper: the requests.Response object was returned, thus exposing the internal implementation of a sibling module.

In this PR, the leak is removed, and the function now exposes only the data needed. It also takes the hacky data recovery (missing apiVersion & kind in the lists) from the Kopf's reactor into the client wrapper.

Having this in place will also simplify future switch to other HTTP clients, such as asyncio (see #176), as there is no such a specific response object in other implementations.

The function is intentionally renamed: to break things if someone for some reason uses this private function in their code — since its signature is now different (another result type).

Types of Changes

  • Refactor/improvements

There are no behavioural changes. Only the code refactoring. The tests show that all the protocols and interfaces are kept in place — except for the imports of the internal modules (not exposed via kopf/__init__.py).

@nolar nolar requested a review from samurang87 as a code owner October 1, 2019 20:17
@zincr
Copy link

zincr bot commented Oct 1, 2019

🤖 zincr found 0 problems , 0 warnings

✅ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

Copy link

@jonathanbeber jonathanbeber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

items = []
resource_version = rsp.get('metadata', {}).get('resourceVersion', None)
for item in rsp['items']:
# FIXME: fix in pykube to inject the missing item's fields from the list's metainfo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find an issue on pykube for that, hasn't it been reported yet?

Copy link
Contributor Author

@nolar nolar Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Not sure it should be there either. It is the way how K8s API works.

@nolar nolar requested a review from jonathanbeber October 4, 2019 16:21
@nolar nolar merged commit 90b4f23 into zalando-incubator:master Oct 5, 2019
@nolar nolar deleted the typehints-hide-response branch October 5, 2019 08:42
@nolar nolar added the refactoring Code cleanup without new features added label Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactoring Code cleanup without new features added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants