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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf5e530aef5aa2090bb6722def02ea09f0727b4445f1fac80391687b4b69c81
4
- data.tar.gz: 69a5f3e755e6c401733ab118944a155a1bc706121588359912f01b937283af53
3
+ metadata.gz: c2bdfad9e4b793eee6f26f74d8de8194d949f3be60217485a8872128a2c55f3a
4
+ data.tar.gz: fe7bc82ccc2d62c47af0f5af51fdc1029906a827a4625b194a7a9ec58e658549
5
5
  SHA512:
6
- metadata.gz: 86af0f3581d589358f6ccedeb9f04c4a39abb4dfc153c2b8e6ba69dd80b2153ffc8bf4183cd194e548e947eac9c12314517c8532ffb809f641f2e75dc1883002
7
- data.tar.gz: f58367aff174456db85719244922b383c3972e796ecb5f6ed2f9295994c3ce323402650ffbd40c677ad851934b54220e129c9fed3216d7742d39e458586980a0
6
+ metadata.gz: 67dd25e229543178fdb51be20948f87ac7f4f0d1be0f12793bce57ef59e10aa4b5c5f433a2180afbda623ccd8ca96d8ffe9797ba3d3beebb3be3fd47abe6b8d3
7
+ data.tar.gz: d4071e90d7bc03ee28f01f94fb2678088be1cc79ba52dd2753c634580fa49fc6e685a1466f00c5259db8eba96229f075102bad548e41262d5c5147a96dce50fe
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class KubernetesLeaderElection
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -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 = @kubeclient.patch_entity(
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
- @kubeclient.create_entity(
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
- @kubeclient.get_entity("leases", @name, namespace)
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
- @kubeclient.delete_entity("leases", @name, namespace)
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.1.2
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: 2021-09-10 00:00:00.000000000 Z
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.2.16
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