gaborgsomogyi commented on code in PR #364:
URL:
https://github.com/apache/flink-kubernetes-operator/pull/364#discussion_r964425155
##########
flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/FlinkOperatorWebhook.java:
##########
@@ -138,19 +134,35 @@ private static SslContext createSslContext() throws
Exception {
return null;
}
- String keystorePassword =
EnvUtils.getRequired(EnvUtils.ENV_WEBHOOK_KEYSTORE_PASSWORD);
String keystoreType =
EnvUtils.getRequired(EnvUtils.ENV_WEBHOOK_KEYSTORE_TYPE);
- KeyStore keyStore = KeyStore.getInstance(keystoreType);
- try (InputStream keyStoreFile =
- Files.newInputStream(new
File(keystorePathOpt.get()).toPath())) {
- keyStore.load(keyStoreFile, keystorePassword.toCharArray());
- }
- final KeyManagerFactory kmf =
-
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- kmf.init(keyStore, keystorePassword.toCharArray());
+ String keystorePassword =
EnvUtils.getRequired(EnvUtils.ENV_WEBHOOK_KEYSTORE_PASSWORD);
+ ReloadableSslContext reloadableSslContext =
+ new ReloadableSslContext(keystorePathOpt.get(), keystoreType,
keystorePassword);
+ stopFsWatchService();
+ final String realKeystoreFileName =
+
Path.of(keystorePathOpt.get()).toRealPath().getFileName().toString();
+ LOG.info("Keystore path is resolved to real filename: " +
realKeystoreFileName);
+ fsWatchService =
+ new
FsWatchService(Path.of(keystorePathOpt.get()).getParent().toString()) {
+ @Override
+ protected void onFileOrDirectoryModified(Path
relativePath) {
+ try {
+ LOG.info("Reloading SSL context because of
certificate change");
+ reloadableSslContext.reload();
+ LOG.info("SSL context reloaded successfully");
+ } catch (Exception e) {
+ LOG.error("SSL context reload received exception:
" + e);
+ }
+ }
+ };
+ fsWatchService.start();
+ return reloadableSslContext;
+ }
- return SslContextBuilder.forServer(kmf)
- .ciphers(Http2SecurityUtil.CIPHERS,
SupportedCipherSuiteFilter.INSTANCE)
- .build();
+ private static void stopFsWatchService() throws InterruptedException {
+ if (fsWatchService != null) {
+ fsWatchService.interrupt();
+ fsWatchService.join();
Review Comment:
Please have a look at the first call of `createSslContext` and you see why
it can be null.
##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/fs/FsWatchService.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.kubernetes.operator.fs;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchKey;
+import java.nio.file.WatchService;
+
+import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
+import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
+import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
+import static java.nio.file.StandardWatchEventKinds.OVERFLOW;
+
+/** Service which is able to watch local filesystem directories. */
+public class FsWatchService extends Thread {
Review Comment:
Renamed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]