Skip to content

Commit c9dfa76

Browse files
committed
refactor: minor improvements
Signed-off-by: Chris Laprun <metacosm@gmail.com>
1 parent dca45df commit c9dfa76

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/LeaderElectionManager.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.javaoperatorsdk.operator;
1717

18-
import java.util.Arrays;
1918
import java.util.Collection;
19+
import java.util.List;
2020
import java.util.UUID;
2121
import java.util.concurrent.CompletableFuture;
2222
import java.util.function.Predicate;
@@ -39,6 +39,7 @@
3939
public class LeaderElectionManager {
4040

4141
private static final Logger log = LoggerFactory.getLogger(LeaderElectionManager.class);
42+
private static final List<String> REQUIRED_VERBS = List.of("create", "update", "get");
4243

4344
public static final String NO_PERMISSION_TO_LEASE_RESOURCE_MESSAGE =
4445
"No permission to lease resource.";
@@ -153,7 +154,6 @@ public void stop() {
153154
}
154155

155156
private void checkLeaseAccess() {
156-
var verbsRequired = Arrays.asList("create", "update", "get");
157157
SelfSubjectRulesReview review = new SelfSubjectRulesReview();
158158
review.setSpec(new SelfSubjectRulesReviewSpecBuilder().withNamespace(leaseNamespace).build());
159159
var reviewResult = configurationService.getKubernetesClient().resource(review).create();
@@ -168,16 +168,15 @@ private void checkLeaseAccess() {
168168
|| rule.getResourceNames().contains(leaseName))
169169
.map(ResourceRule::getVerbs)
170170
.flatMap(Collection::stream)
171-
.distinct()
172-
.collect(Collectors.toList());
173-
if (verbsAllowed.contains(UNIVERSAL_VALUE) || verbsAllowed.containsAll(verbsRequired)) {
171+
.collect(Collectors.toUnmodifiableSet());
172+
if (verbsAllowed.contains(UNIVERSAL_VALUE) || verbsAllowed.containsAll(REQUIRED_VERBS)) {
174173
return;
175174
}
176175

177176
var missingVerbs =
178-
verbsRequired.stream()
177+
REQUIRED_VERBS.stream()
179178
.filter(Predicate.not(verbsAllowed::contains))
180-
.collect(Collectors.toList());
179+
.collect(Collectors.joining(","));
181180

182181
throw new OperatorException(
183182
NO_PERMISSION_TO_LEASE_RESOURCE_MESSAGE

0 commit comments

Comments
 (0)