Skip to content

chore: address some sonar-reported issues #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public Operator(KubernetesClient kubernetesClient, ConfigurationService configur
.ifPresent(c -> leaderElectionManager.init(c, this.kubernetesClient));
}

/** Adds a shutdown hook that automatically calls {@link #stop()} when the app shuts down. */
/**
* Adds a shutdown hook that automatically calls {@link #stop()} when the app shuts down.
*
* @deprecated This feature should not be used anymore
*/
@Deprecated(forRemoval = true)
public void installShutdownHook() {
if (!leaderElectionManager.isLeaderElectionEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
});
}

@SuppressWarnings("rawtypes")
default ManagedWorkflowFactory getWorkflowFactory() {
return ManagedWorkflowFactory.DEFAULT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand Down Expand Up @@ -65,21 +63,24 @@ protected DefaultWorkflow(Map<String, DependentResourceNode> dependentResourceNo
}

@SuppressWarnings("unchecked")
private Map<String, DependentResourceNode> toMap(
Set<DependentResourceNode> dependentResourceNodes) {
return dependentResourceNodes.stream()
.peek(drn -> {
// add cycle detection?
if (drn.getDependsOn().isEmpty()) {
topLevelResources.add(drn);
} else {
for (DependentResourceNode dependsOn : (List<DependentResourceNode>) drn
.getDependsOn()) {
bottomLevelResource.remove(dependsOn);
}
}
})
.collect(Collectors.toMap(DependentResourceNode::getName, Function.identity()));
private Map<String, DependentResourceNode> toMap(Set<DependentResourceNode> nodes) {
if (nodes == null || nodes.isEmpty()) {
return Collections.emptyMap();
}

final var map = new HashMap<String, DependentResourceNode>(nodes.size());
for (DependentResourceNode node : nodes) {
// add cycle detection?
if (node.getDependsOn().isEmpty()) {
topLevelResources.add(node);
} else {
for (DependentResourceNode dependsOn : (List<DependentResourceNode>) node.getDependsOn()) {
bottomLevelResource.remove(dependsOn);
}
}
map.put(node.getName(), node);
}
return map;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package io.javaoperatorsdk.operator.processing.event.source.informer;

import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -55,8 +60,6 @@ void initSources(MixedOperation<T, KubernetesResourceList<T>, Resource<T>> clien
this.eventHandler = eventHandler;

final var targetNamespaces = configuration.getEffectiveNamespaces();
final var labelSelector = configuration.getLabelSelector();

if (ResourceConfiguration.allNamespacesWatched(targetNamespaces)) {
var source = createEventSourceForNamespace(WATCH_ALL_NAMESPACES);
log.debug("Registered {} -> {} for any namespace", this, source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void start() throws OperatorException {
log.warn("Informer startup error. Will periodically retry. Informer: {}", informer, e);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
thread.interrupt();
throw new IllegalStateException(e);
} finally {
// restore original name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void getDependentResources() {

@Test
void missingAnnotationThrowsException() {
Assertions.assertThrows(OperatorException.class,
() -> configFor(new MissingAnnotationReconciler()));
final var reconciler = new MissingAnnotationReconciler();
Assertions.assertThrows(OperatorException.class, () -> configFor(reconciler));
}

@SuppressWarnings("rawtypes")
Expand All @@ -145,7 +145,8 @@ private Optional<DependentResourceSpec> findByNameOptional(

@Test
void tryingToAddDuplicatedDependentsWithoutNameShouldFail() {
assertThrows(IllegalArgumentException.class, () -> configFor(new DuplicatedDepReconciler()));
final var reconciler = new DuplicatedDepReconciler();
assertThrows(IllegalArgumentException.class, () -> configFor(reconciler));
}

@Test
Expand Down Expand Up @@ -179,8 +180,7 @@ void checkDefaultRateAndRetryConfigurations() {

@Test
void configuringRateAndRetryViaAnnotationsShouldWork() {
var config =
configFor(new ConfigurableRateLimitAndRetryReconciler());
var config = configFor(new ConfigurableRateLimitAndRetryReconciler());
final var retry = config.getRetry();
final var testRetry = assertInstanceOf(TestRetry.class, retry);
assertEquals(12, testRetry.getValue());
Expand Down