-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP a repro with artificial inconsistency
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
- Loading branch information
Showing
3 changed files
with
108 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,86 @@ | ||
import logging | ||
import kopf | ||
import dataclasses | ||
|
||
|
||
# @kopf.on.login() | ||
# def delayed_k3s(**_): | ||
# conn = kopf.login_via_pykube(logger=logging.getLogger('xxx')) | ||
# if conn: | ||
# return dataclasses.replace(conn, server=conn.server.rsplit(':', 1)[0] + ':11223') | ||
|
||
|
||
@kopf.on.create('kopfexamples') | ||
def create_fn(spec, **kwargs): | ||
print(f"And here we are! Creating: {spec}") | ||
return {'message': 'hello world'} # will be the new status | ||
@kopf.on.update('kopfexamples') | ||
def create_fn(meta, spec, reason, logger, **kwargs): | ||
rv = meta.get('resourceVersion') | ||
logger.warning(f">>> {rv=} And here we are! {reason=}: {spec}") | ||
|
||
|
||
# @kopf.on.create('kopfexamples') | ||
# def create_fn2(spec, **kwargs): | ||
# print(f"And here we are! Creating2: {spec}") | ||
|
||
""" | ||
======================================================================================================================= | ||
Trigger with (delete the object first!): | ||
$ kubectl apply -f examples/obj.yaml && sleep 1 && kubectl patch -f examples/obj.yaml --type merge -p '{"spec": {"field": 2}}' | ||
======================================================================================================================= | ||
Timeline with the watch-stream latency 3s: | ||
/-- kubectl create, object is created (a=s0) | ||
| ... sleep 1s | ||
| /-- kubectl patch, object is patched (b=s0+p1) | ||
| | /-- c=s0+p1+p2 | ||
↓ ↓ | | ||
----+-//-aaaaabbbbbbbccccccccccccccccccc-> which state is stored in kubernetes | ||
↓ ↓ ↑↓ | ||
| | |\----3s----\ | ||
| | | | | ||
| \----3s+---\ | | ||
| | | | | ||
\----3s----\| | | | ||
↓↑ ↓ ↓ | ||
----+-//------------aaaaabbbbbbbbcccccc-> which state is seen by the operator | ||
↓ ↓↑ ↓ ↓ | ||
| || | | | ||
| || | \-- operator gets a watch-event (patched2) | ||
| || | | ||
| || \-- operator gets a watch-event of state "b" (patched1) | ||
| || !BUG!: "c" (p2) is not seen yet, though implied; executes AGAIN! | ||
| || | ||
| |\-- handlers execute, insta-patches as done (p2), created state "c" | ||
| \-- operator gets a watch-event (state a) | ||
\-- watching started | ||
Presumable fix: | ||
/-- kubectl create, object is created (a=s0) | ||
| ... sleep 1s | ||
| /-- kubectl patch, object is patched (b=s0+p1) | ||
| | /-- c=s0+p1+p2 | ||
↓ ↓ | | ||
----+-//-aaaaabbbbbbbccccccccccccccccccc-> which state is stored in kubernetes | ||
↓ ↓ ↑↓ | ||
| | |\----3s----\ | ||
| | | | | ||
| \----3s+---\ | | ||
| | | | | ||
\----3s----\| | | | ||
↓↑⇶⇶⇶⇶⇶⇶⇶⇶⇶⇶⇶⇶↓ (patching p2 sets the consistency expectation for N seconds) | ||
----+-//------------aaaaabbbbbbbbcccccc-> which state does the operator see | ||
↓ ↓↑ ⌇ ↓ | ||
| || ⌇ | | ||
| || ⌇ \-- operator gets a consistent watch-event (patched1+patched2), execute everything | ||
| || ⌇ | ||
| || \-- operator executes ONLY the low-level handlers (seen as patched1) | ||
| || \~~~~~~⨳ inconsistency mode: wait until a new event (then discard it) OR timeout (then process it) | ||
| | | ||
| |\-- operator reacts, starts patching (p2) | ||
| \-- operator gets a watch-event (state a) | ||
\-- watching started | ||
""" |
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