Skip to content
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 @@ -18,6 +18,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -132,9 +133,10 @@ private void addTemplatedFile(
targetDir == null ? projectDir : targetDir,
targetFileName == null ? fileName : targetFileName);
FileUtils.forceMkdir(targetFile.getParentFile());
var writer = new FileWriter(targetFile);
mustache.execute(writer, values);
writer.flush();
try (var writer = new FileWriter(targetFile, StandardCharsets.UTF_8)) {
mustache.execute(writer, values);
writer.flush();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ private void addMetadataTags(
addTagOmittingOnEmptyValue(NAMESPACE, resourceID.getNamespace().orElse(null), tags, prefixed);
}
addTag(SCOPE, getScope(resourceID), tags, prefixed);
final var gvk = (GroupVersionKind) metadata.get(Constants.RESOURCE_GVK_KEY);
final var gvk =
metadata == null ? null : (GroupVersionKind) metadata.get(Constants.RESOURCE_GVK_KEY);
if (gvk != null) {
addGVKTags(gvk, tags, prefixed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public ScheduledExecutorService scheduledExecutorService() {
return scheduledExecutorService;
}

public void start(ConfigurationService configurationService) {
public synchronized void start(ConfigurationService configurationService) {
if (!started) {
this.configurationService = configurationService; // used to lazy init workflow executor
this.cachingExecutorService = Executors.newCachedThreadPool();
Expand All @@ -142,7 +142,7 @@ public void start(ConfigurationService configurationService) {
}
}

public void stop(Duration gracefulShutdownTimeout) {
public synchronized void stop(Duration gracefulShutdownTimeout) {
try {
log.debug("Closing executor");
var parallelExec = Executors.newFixedThreadPool(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractEventSourceHolderDependentResource<

private T eventSource;
private final Class<R> resourceType;
private boolean isCacheFillerEventSource;
private volatile boolean isCacheFillerEventSource;
protected String eventSourceNameToUse;

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public abstract class ManagedInformerEventSource<
Configurable<C> {

private static final Logger log = LoggerFactory.getLogger(ManagedInformerEventSource.class);
private InformerManager<R, C> cache;
private volatile InformerManager<R, C> cache;
private final boolean comparableResourceVersions;
private ControllerConfiguration<R> controllerConfiguration;
private volatile ControllerConfiguration<R> controllerConfiguration;
private final C configuration;
private final Map<String, Function<R, List<String>>> indexers = new HashMap<>();
protected TemporaryResourceCache<R> temporaryResourceCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public abstract class AbstractOperatorExtension
protected final boolean preserveNamespaceOnError;
protected final boolean skipNamespaceDeletion;
protected final boolean waitForNamespaceDeletion;
protected final int namespaceDeleteTimeout = DEFAULT_NAMESPACE_DELETE_TIMEOUT;
protected final int namespaceDeleteTimeout;
protected final Function<ExtensionContext, String> namespaceNameSupplier;
protected final Function<ExtensionContext, String> perClassNamespaceNameSupplier;

Expand All @@ -74,6 +74,7 @@ protected AbstractOperatorExtension(
boolean preserveNamespaceOnError,
boolean skipNamespaceDeletion,
boolean waitForNamespaceDeletion,
int namespaceDeleteTimeout,
KubernetesClient kubernetesClient,
KubernetesClient infrastructureKubernetesClient,
Function<ExtensionContext, String> namespaceNameSupplier,
Expand All @@ -90,6 +91,7 @@ protected AbstractOperatorExtension(
this.preserveNamespaceOnError = preserveNamespaceOnError;
this.skipNamespaceDeletion = skipNamespaceDeletion;
this.waitForNamespaceDeletion = waitForNamespaceDeletion;
this.namespaceDeleteTimeout = namespaceDeleteTimeout;
this.namespaceNameSupplier = namespaceNameSupplier;
this.perClassNamespaceNameSupplier = perClassNamespaceNameSupplier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private ClusterDeployedOperatorExtension(
boolean preserveNamespaceOnError,
boolean skipNamespaceDeletion,
boolean waitForNamespaceDeletion,
int namespaceDeleteTimeout,
boolean oneNamespacePerClass,
KubernetesClient kubernetesClient,
KubernetesClient infrastructureKubernetesClient,
Expand All @@ -65,6 +66,7 @@ private ClusterDeployedOperatorExtension(
preserveNamespaceOnError,
skipNamespaceDeletion,
waitForNamespaceDeletion,
namespaceDeleteTimeout,
kubernetesClient,
infrastructureKubernetesClient,
namespaceNameSupplier,
Expand Down Expand Up @@ -231,6 +233,7 @@ public ClusterDeployedOperatorExtension build() {
preserveNamespaceOnError,
skipNamespaceDeletion,
waitForNamespaceDeletion,
namespaceDeleteTimeout,
oneNamespacePerClass,
kubernetesClient,
infrastructureKubernetesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private LocallyRunOperatorExtension(
boolean preserveNamespaceOnError,
boolean skipNamespaceDeletion,
boolean waitForNamespaceDeletion,
int namespaceDeleteTimeout,
boolean oneNamespacePerClass,
KubernetesClient kubernetesClient,
KubernetesClient infrastructureKubernetesClient,
Expand All @@ -103,6 +104,7 @@ private LocallyRunOperatorExtension(
preserveNamespaceOnError,
skipNamespaceDeletion,
waitForNamespaceDeletion,
namespaceDeleteTimeout,
kubernetesClient,
infrastructureKubernetesClient,
namespaceNameSupplier,
Expand Down Expand Up @@ -184,7 +186,8 @@ public static void applyCrd(String resourceTypeName, KubernetesClient client) {
private static void applyCrd(String crdString, String path, KubernetesClient client) {
try {
LOGGER.debug("Applying CRD: {}", crdString);
final var crd = client.load(new ByteArrayInputStream(crdString.getBytes()));
final var crd =
client.load(new ByteArrayInputStream(crdString.getBytes(StandardCharsets.UTF_8)));
crd.serverSideApply();
appliedCRDs.add(new AppliedCRD.FileCRD(crdString, path));
Thread.sleep(CRD_READY_WAIT); // readiness is not applicable for CRD, just wait a little
Expand Down Expand Up @@ -446,7 +449,10 @@ record FileCRD(String crdString, String path) implements AppliedCRD {
public void delete(KubernetesClient client) {
try {
LOGGER.debug("Deleting CRD: {}", crdString);
final var items = client.load(new ByteArrayInputStream(crdString.getBytes())).items();
final var items =
client
.load(new ByteArrayInputStream(crdString.getBytes(StandardCharsets.UTF_8)))
.items();
if (items == null || items.isEmpty() || items.get(0) == null) {
LOGGER.warn("Could not determine CRD name from yaml: {}", path);
return;
Expand Down Expand Up @@ -620,6 +626,7 @@ public LocallyRunOperatorExtension build() {
preserveNamespaceOnError,
skipNamespaceDeletion,
waitForNamespaceDeletion,
namespaceDeleteTimeout,
oneNamespacePerClass,
kubernetesClient,
infrastructureKubernetesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -51,7 +52,8 @@ public AccumulativeMappingWriter loadExistingMappings() {
.getResource(StandardLocation.CLASS_OUTPUT, "", resourcePath);

try (BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(readonlyResource.openInputStream()))) {
new BufferedReader(
new InputStreamReader(readonlyResource.openInputStream(), StandardCharsets.UTF_8))) {
final var existingLines =
bufferedReader
.lines()
Expand Down Expand Up @@ -81,7 +83,7 @@ public void flush() {
processingEnvironment
.getFiler()
.createResource(StandardLocation.CLASS_OUTPUT, "", resourcePath);
printWriter = new PrintWriter(resource.openOutputStream());
printWriter = new PrintWriter(resource.openOutputStream(), false, StandardCharsets.UTF_8);

for (Map.Entry<String, String> entry : mappings.entrySet()) {
printWriter.println(entry.getKey() + "," + entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -69,7 +70,8 @@ static <T, V> Map<T, V> provide(final String resourcePath, T key, V value) {
}

private static List<String> retrieveClassNamePairs(URL url) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
try (BufferedReader br =
new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
return br.lines().collect(Collectors.toList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DependentOperationEventFilterIT {
@RegisterExtension
LocallyRunOperatorExtension operator =
LocallyRunOperatorExtension.builder()
.withNamespaceDeleteTimeout(2)
.withReconciler(new DependentOperationEventFilterCustomResourceTestReconciler())
.build();

Expand Down
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<git-commit-id-maven-plugin.version>10.0.0</git-commit-id-maven-plugin.version>
<jib-maven-plugin.version>3.5.1</jib-maven-plugin.version>
<spotless.version>3.6.0</spotless.version>
<spotbugs-maven-plugin.version>4.9.8.3</spotbugs-maven-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -331,6 +332,11 @@
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -431,6 +437,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<effort>Max</effort>
<threshold>Medium</threshold>
<includeTests>false</includeTests>
<excludeFilterFile>${maven.multiModuleProjectDirectory}/spotbugs-exclude.xml</excludeFilterFile>
</configuration>
<executions>
<execution>
<id>spotbugs-check</id>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.javaoperatorsdk.operator.sample.dependent;

import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void delete(MySQLSchema primary, Context<MySQLSchema> context) {
}

public static String decode(String value) {
return new String(Base64.getDecoder().decode(value.getBytes()));
return new String(Base64.getDecoder().decode(value), StandardCharsets.UTF_8);
}
Comment thread
csviri marked this conversation as resolved.

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.javaoperatorsdk.operator.sample.dependent;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Set;

Expand Down Expand Up @@ -43,7 +44,7 @@ public class SecretDependentResource extends KubernetesDependentResource<Secret,
public static final String MYSQL_SECRET_PASSWORD = "mysql.secret.user.password";

private static String encode(String value) {
return Base64.getEncoder().encodeToString(value.getBytes());
return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
public class OperationsSampleOperator {

private static final Logger log = LoggerFactory.getLogger(OperationsSampleOperator.class);
public static final String JOSDK_CONFIG_CONFIG_YAML = "/config/config.yaml";
public static final String CONFIG_PATH_ENV_VAR = "CONFIG_PATH";

/**
* Based on env variables a different flavor of Reconciler is used, showcasing how the same logic
Expand All @@ -66,7 +68,8 @@ public static void main(String[] args) throws Exception {

var configProviders = new ArrayList<ConfigProvider>();
configProviders.add(new EnvVarConfigProvider());
configProviders.add(new YamlConfigProvider(Path.of("/config/config.yaml")));
var configPath = System.getenv().getOrDefault(CONFIG_PATH_ENV_VAR, JOSDK_CONFIG_CONFIG_YAML);
configProviders.add(new YamlConfigProvider(Path.of(configPath)));
var configLoader = new ConfigLoader(new AggregatePriorityListConfigProvider(configProviders));

Metrics metrics = initOTLPMetrics(isLocal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public UpdateControl<Tomcat> reconcile(Tomcat tomcat, Context<Tomcat> context) {
"Updating status of Tomcat {} in namespace {} to {} ready replicas",
tomcat.getMetadata().getName(),
tomcat.getMetadata().getNamespace(),
tomcat.getStatus() == null ? 0 : tomcat.getStatus().getReadyReplicas());
tomcat.getStatus() == null
? Integer.valueOf(0)
: tomcat.getStatus().getReadyReplicas());
return UpdateControl.patchStatus(updatedTomcat);
})
.orElseGet(UpdateControl::noUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.javaoperatorsdk.operator.sample;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -252,7 +253,7 @@ public void onFailure(Throwable t, Response response) {
@Override
public void onClose(int code, String reason) {
log.debug("Exit with: {} and with reason: {}", code, reason);
data.complete(baos.toString());
data.complete(baos.toString(StandardCharsets.UTF_8));
}
}
}
Loading
Loading