kubernetes_leader_election 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kubernetes_leader_election/version.rb +1 -1
- data/lib/kubernetes_leader_election.rb +10 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2bdfad9e4b793eee6f26f74d8de8194d949f3be60217485a8872128a2c55f3a
|
4
|
+
data.tar.gz: fe7bc82ccc2d62c47af0f5af51fdc1029906a827a4625b194a7a9ec58e658549
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67dd25e229543178fdb51be20948f87ac7f4f0d1be0f12793bce57ef59e10aa4b5c5f433a2180afbda623ccd8ca96d8ffe9797ba3d3beebb3be3fd47abe6b8d3
|
7
|
+
data.tar.gz: d4071e90d7bc03ee28f01f94fb2678088be1cc79ba52dd2753c634580fa49fc6e685a1466f00c5259db8eba96229f075102bad548e41262d5c5147a96dce50fe
|
@@ -34,11 +34,17 @@ class KubernetesLeaderElection
|
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
+
# allow callers to use any refresh tokens for their kubeclient
|
38
|
+
# see https://github.com/abonas/kubeclient/issues/530 for a better solution
|
39
|
+
def kubeclient
|
40
|
+
@kubeclient.respond_to?(:call) ? @kubeclient.call : @kubeclient
|
41
|
+
end
|
42
|
+
|
37
43
|
# show that we are alive or crash because we cannot reach the api (split-brain az)
|
38
44
|
def signal_alive
|
39
45
|
with_retries(*FAILED_KUBERNETES_REQUEST, times: 3) do
|
40
46
|
patch = { spec: { renewTime: microtime } }
|
41
|
-
reply =
|
47
|
+
reply = kubeclient.patch_entity(
|
42
48
|
"leases", @name, patch, 'strategic-merge-patch', ENV.fetch("POD_NAMESPACE")
|
43
49
|
)
|
44
50
|
|
@@ -65,7 +71,7 @@ class KubernetesLeaderElection
|
|
65
71
|
reraise = ->(e) { e.is_a?(Kubeclient::HttpError) && e.error_code == ALREADY_EXISTS_CODE }
|
66
72
|
|
67
73
|
with_retries(*FAILED_KUBERNETES_REQUEST, reraise: reraise, times: 3) do
|
68
|
-
|
74
|
+
kubeclient.create_entity(
|
69
75
|
"Lease",
|
70
76
|
"leases",
|
71
77
|
metadata: {
|
@@ -93,7 +99,7 @@ class KubernetesLeaderElection
|
|
93
99
|
raise e unless e.error_code == ALREADY_EXISTS_CODE # lease already exists
|
94
100
|
|
95
101
|
lease = with_retries(*FAILED_KUBERNETES_REQUEST, times: 3) do
|
96
|
-
|
102
|
+
kubeclient.get_entity("leases", @name, namespace)
|
97
103
|
rescue Kubeclient::ResourceNotFoundError
|
98
104
|
nil
|
99
105
|
end
|
@@ -109,7 +115,7 @@ class KubernetesLeaderElection
|
|
109
115
|
# see https://github.com/kubernetes/kubernetes/issues/20572
|
110
116
|
@logger.info message: "deleting stale lease"
|
111
117
|
with_retries(*FAILED_KUBERNETES_REQUEST, times: 3) do
|
112
|
-
|
118
|
+
kubeclient.delete_entity("leases", @name, namespace)
|
113
119
|
end
|
114
120
|
false # leader is dead, do not assume leadership here to avoid race condition
|
115
121
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kubernetes_leader_election
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kubeclient
|
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.1.6
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Elect a kubernetes leader using leases for ruby
|