|
25 | 25 |
|
26 | 26 | """ |
27 | 27 | This package implements leader election using an annotation in a Kubernetes object. |
28 | | -The onstarted_leading function is run in a thread and when it returns, if it does |
| 28 | +The onstarted_leading function is run in a thread and when it returns, if it does |
29 | 29 | it might not be safe to run it again in a process. |
30 | 30 |
|
31 | 31 | At first all candidates are considered followers. The one to create a lock or update |
@@ -115,17 +115,13 @@ def try_acquire_or_renew(self): |
115 | 115 |
|
116 | 116 | # A lock is not created with that name, try to create one |
117 | 117 | if not lock_status: |
118 | | - # To be removed when support for python2 will be removed |
119 | | - if sys.version_info > (3, 0): |
120 | | - if json.loads(old_election_record.body)['code'] != HTTPStatus.NOT_FOUND: |
121 | | - logger.info("Error retrieving resource lock {} as {}".format(self.election_config.lock.name, |
122 | | - old_election_record.reason)) |
123 | | - return False |
124 | | - else: |
125 | | - if json.loads(old_election_record.body)['code'] != HTTPStatus.NOT_FOUND: |
126 | | - logger.info("Error retrieving resource lock {} as {}".format(self.election_config.lock.name, |
127 | | - old_election_record.reason)) |
128 | | - return False |
| 118 | + if json.loads(old_election_record.body)[ |
| 119 | + 'code'] != HTTPStatus.NOT_FOUND: |
| 120 | + logger.info( |
| 121 | + "Error retrieving resource lock {} as {}".format( |
| 122 | + self.election_config.lock.name, |
| 123 | + old_election_record.reason)) |
| 124 | + return False |
129 | 125 |
|
130 | 126 | logger.info("{} is trying to create a lock".format(leader_election_record.holder_identity)) |
131 | 127 | create_status = self.election_config.lock.create(name=self.election_config.lock.name, |
|
0 commit comments