Comments (3)
So far so good. The switch to pykube-ng is now fully implemented. The legacy kubernetes official client library is supported optionally (if installed) for auto-authentication, but is not used anywhere else — and I consider removing it completely.
The missing pykube-ng's parts are simulated inside kopf.k8s.classes
(e.g. obj.patch()
method), and eventually should move into pykube-ng itself.
The codebase seems functional. And clean. Arbitrary k8s resources (custom and builtin) are supported transparently, as it was prototyped above. The k8s-events are sent, all is fine.
What is left: all preceding PRs, on which it is based (all are pending for a review); and some cleanup in general plus the remaining TODOs marks (to be sure nothing is forgotten); and maybe a test-drive for few days in our testing infrastructure with real tasks.
Diff (still the same): nolar/kopf@wip/master/20190606...pykube — The diff is huge mostly because of tests (massive changes).
from kopf.
So far, a list of issues detected while trying to switch to pykube:
pykube.HTTPClient
object is needed on every call, there is no implicit config (as in the official client). Has to be stored globally and reused all over the code.pykube.HTTPClient
has a default timeout of 10s for any connection, including the watching. Can be overridden explicitly withtimeout=None
, but requires a separatepykube.HTTPClient
instance for that.pykube.HTTPClient
raises exceptions fromrequests
on timeouts, not its own.- Watch-call terminates after the connection is lost for any reason, no internal reconnection or
while True
. Has to be caught and repeated. In the official K8s client, it is done internally: the watch is eternal. object_factory()
prints a list of discovered resources to stdout, this is a visual garbage.object_factory()
assumes that the resource always exists, and fails onresource['namespaced']
whenresource
isNone
.object_factory()
requires akind
, and notplural
; would be better if plural, singular, kind, and all aliases are accepted.apiextensions.k8s.io/v1beta1/customresourcedefinitions
does not exist in the cluster in a listing of resources, though is accessible. Pykube should assume that the developer knows what they are doing, and create the classes properly (but: only with plural name).- Patching is implemented as
obj.update()
, where the whole body of the object is used for a patch. And this involves the resourceVersion checking for non-conflicting patches. We need the partial patches onstatus
field only (or finalizers, or annotations), not on the whole body. And we need no conflict resolution.
On a good side:
- It was able to handle a custom resource
KopfExample
and a built-in resourcePod
via the same code, no {resource=>classes+methods} mapping was needed. Both event-spy-handler and regular cause-handlers worked on pods.
Basically, the whole trick is achieved by this snippet (undoable in the official K8s client library):
version = kwargs.pop("version", "v1")
if version == "v1":
base = kwargs.pop("base", "/api")
elif "/" in version:
base = kwargs.pop("base", "/apis")
else:
This alone justifies the effort to continue switching.
Preview branch: https://github.com/nolar/kopf/tree/pykube (based on "resume-handlers" not yet merged branch).
Diff: nolar/kopf@wip/master/20190606...pykube
from kopf.
After #71, almost all Kubernetes-related code is consolidated in one package: kopf.k8s
, where it is easy to be replaced by any other implementation. The only thing outside of this package is authentication (kopf.config.login()
).
However, the whole codebase of Kopf assumes that the objects manipulated as dicts. Not even the Kubernetes client's "models". A lot of .get('metadata', {}).get('something')
and .setdefault('status', {}).setdefault('kopf', {})
and similar lines are all around. It will be difficult to change that and to support both dicts & client's classes. It is better not to do so.
In addition, Kopf promises to hide implementation details from the user ⟹ which means that the user should not know which Kubernetes client is used under the hood ⟹ which means that the internal models/classes must not be exposed ⟹ which means they have to be converted to dicts on arrival.
Another tricky part will be watch-streaming. The official Kubernetes client does that in the while True
cycle, and reconnects all the time. Pykube-ng exits after the first disconnection, which happens roughly ~5s, or as specified by a timeout query arg. The connection cannot stay forever, so either the client, or Kopf should handle the reconnections. Some partial workarounds can be found in #96 (pre-listing and resourceVersion
usage).
from kopf.
Related Issues (20)
- Force-kill the operator from inside if stuck at exiting HOT 1
- Resource grows too big with multiple operators for same resource HOT 5
- Watch for changes in array items.
- Resources filtered out in event handlers still get annotated by Kopf HOT 1
- Field handler is trigger even if the field does not exist in the resource at the time. HOT 2
- Question: run-time registration of handlers? HOT 2
- Need advice on the way to achieve service monitoring using a daemon HOT 3
- Is there any real world use of kopf,like rook/ceph? HOT 3
- Root task 'watcher of kopfexamples.zalando.org' is failed: 403, message='Forbidden' - EKS HOT 2
- Can't apply turtorial crd.yaml example,The CustomResourceDefinition "ephemeralvolumeclaims.zalando.org" is invalid HOT 1
- Creating a filter based on metadata.ownerReferences.kind == Statefulset HOT 1
- Subhandler states are not cleared at the end of handling cycle HOT 3
- All handlers succeeded for creation despite raising kopf.HandlerFatalError HOT 3
- Docs use wrong name for kopf.AnnotationsDiffBaseStorage HOT 1
- @kopf.timer continues to run after CR is deleted HOT 2
- client_timeout on watch results in a fatal error HOT 1
- AttributeError: 'NoneType' object has no attribute 'loader' HOT 1
- Reload / Restart all Kopf handlers when a configmap changes.
- Dedicated channel for asking questions regarding kopf usage?
- Exceptions for kopf on event for network connectivity delayed / issues
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kopf.