Title: Add LeaseLock for leader election (upstream #1877) · Issue #1 · chala2001/python · GitHub
Open Graph Title: Add LeaseLock for leader election (upstream #1877) · Issue #1 · chala2001/python
X Title: Add LeaseLock for leader election (upstream #1877) · Issue #1 · chala2001/python
Description: Goal Add LeaseLock to kubernetes/base/leaderelection/resourcelock/, so leader election can use the Kubernetes coordination.k8s.io/v1 Lease resource instead of only ConfigMap. Upstream issue: kubernetes-client#1877 Why client-go moved lea...
Open Graph Description: Goal Add LeaseLock to kubernetes/base/leaderelection/resourcelock/, so leader election can use the Kubernetes coordination.k8s.io/v1 Lease resource instead of only ConfigMap. Upstream issue: kubern...
X Description: Goal Add LeaseLock to kubernetes/base/leaderelection/resourcelock/, so leader election can use the Kubernetes coordination.k8s.io/v1 Lease resource instead of only ConfigMap. Upstream issue: kubern...
Opengraph URL: https://github.com/chala2001/python/issues/1
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add LeaseLock for leader election (upstream #1877)","articleBody":"## Goal\n\nAdd `LeaseLock` to `kubernetes/base/leaderelection/resourcelock/`, so leader election can use the\nKubernetes `coordination.k8s.io/v1` `Lease` resource instead of only `ConfigMap`.\n\nUpstream issue: kubernetes-client/python#1877\n\n## Why\n\n`client-go` moved leader election to `Lease` and **removed** ConfigMap support entirely\n(`kubernetes/client-go` commit 276ea3ed). The Python client still only ships `ConfigMapLock`.\nThree separate people have asked for this, including one porting it to `kubernetes_asyncio`.\n\n## Prior art — this is a takeover, not a fresh start\n\nPR kubernetes-client/python#2314 by **@rvlane** (Dec 2024, +139/-7) implemented this.\n\n- `roycaihw` reviewed it: **\"LGTM overall. Could you add a test?\"**\n- The test was never added.\n- `k8s-triage-robot` auto-closed it 2025-11-21 after `lifecycle/stale` -> `lifecycle/rotten`.\n\n**The approach was approved. Only the test was missing.** rvlane's work is Apache-2.0 (CLA signed,\nconfirmed in the thread) and must be credited with a `Co-authored-by` trailer.\n\nReference implementation: `kubernetes/client-go` `tools/leaderelection/resourcelock/leaselock.go`.\n\n## Contract a lock must satisfy\n\nRead from `leaderelection.py`:\n\n- `get(name, namespace) -> (bool, LeaderElectionRecord | ApiException)`\n- `create(name, namespace, election_record) -> bool`\n- `update(name, namespace, updated_record) -> bool`\n- `.name`, `.namespace`, `.identity` attributes\n\n`LeaderElectionRecord` fields as written by `try_acquire_or_renew`:\n\n| field | written as |\n| --- | --- |\n| `holder_identity` | `str` |\n| `lease_duration` | `str(config.lease_duration)` |\n| `acquire_time` | `str(datetime)` -> `\"YYYY-MM-DD HH:MM:SS.ffffff\"` |\n| `renew_time` | same |\n\n**Critical:** `leaderelection.py` compares `old_election_record.__dict__ != self.observed_record.__dict__`.\nSo a value written and then read back **must compare equal**. The record round-trip through\n`V1LeaseSpec` (which stores real datetimes, not strings) is the main correctness risk and is what\nthe test must cover.\n\n## Changes needed on top of rvlane's version\n\n1. **Named logger.** rvlane's file calls `logging.basicConfig(level=logging.INFO)` at import and\n uses `logging.info(...)`. Since that PR, this package moved to `logger =\n logging.getLogger(\"leaderelection\")` (see `configmaplock.py:21`, `leaderelection.py`). Calling\n `basicConfig` from a library reconfigures the **root logger of the importing application** — it\n must not ship. Use the named logger.\n2. **Set `lease_reference` after a successful `create`**, so a following `update` in the same cycle\n has a reference to work from.\n3. **Do not silently swallow a time parse failure** — `time_str_to_iso` currently logs and returns\n `None`, which would write a null `acquireTime`.\n4. **Leave `configmaplock.py` alone.** rvlane's diff also removed unused imports there; that is\n unrelated to the feature and widens the diff. Keep this PR focused.\n\n## Test plan (the missing piece roycaihw asked for)\n\nNew tests in `leaderelection_test.py`, mocking `CoordinationV1Api`:\n\n1. `create` builds a `V1Lease` with the right name and a spec carrying holder identity, duration\n and both times.\n2. `get` on a missing lease returns `(False, ApiException)`.\n3. `get` on an existing lease returns a `LeaderElectionRecord` with the right holder identity.\n4. **Round-trip:** a record written by `create`/`update` and read back by `get` compares equal\n field-for-field to what `leaderelection.py` would have written. This is the test that protects\n the `__dict__` comparison above.\n5. `update` returns `False` (not raising) when the API raises `ApiException`.\n\n## Out of scope\n\n- Deprecating or removing `ConfigMapLock`.\n- Any change to `leaderelection.py` itself.\n- The asyncio client.\n","author":{"url":"https://github.com/chala2001","@type":"Person","name":"chala2001"},"datePublished":"2026-08-28T18:46:47Z","url":"https://github.com/chala2001/python/issues/1"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:46fd8875-0624-e202-679a-09f09c51f263 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC72:8FE13:32B50D:440C6A:6AFE9D2D |
| html-safe-nonce | cd1b0409f354c6c6aa130560ca8e1e9e5bf6f8ef223f30cc9d409cb7cf799c98 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzcyOjhGRTEzOjMyQjUwRDo0NDBDNkE6NkFGRTlEMkQiLCJ2aXNpdG9yX2lkIjoiMjgxNzU0ODA4MTgyODg5NjA0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 188c2cb079ad2c3c7739a4e046c4c1bd3b05a9ce238685266c045e27ef8158db |
| hovercard-subject-tag | issue:5281270755 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/chala2001/python/1/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1b45e6272d325daac6ce0bc1f46a7266b0de067a2a9d2b3aec13dfc7514431ea/chala2001/python/issues/1 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1b45e6272d325daac6ce0bc1f46a7266b0de067a2a9d2b3aec13dfc7514431ea/chala2001/python/issues/1 |
| og:image:alt | Goal Add LeaseLock to kubernetes/base/leaderelection/resourcelock/, so leader election can use the Kubernetes coordination.k8s.io/v1 Lease resource instead of only ConfigMap. Upstream issue: kubern... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | chala2001 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/chala2001/python git https://github.com/chala2001/python.git |
| octolytics-dimension-user_id | 150885184 |
| octolytics-dimension-user_login | chala2001 |
| octolytics-dimension-repository_id | 1348432992 |
| octolytics-dimension-repository_nwo | chala2001/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 72473727 |
| octolytics-dimension-repository_parent_nwo | kubernetes-client/python |
| octolytics-dimension-repository_network_root_id | 72473727 |
| octolytics-dimension-repository_network_root_nwo | kubernetes-client/python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width