Tuesday, August 4, 2020

Stream Store With TLS (continued)

Sample Implementation:
+    public CompletableFuture<Object> setupTLS() {
+            V1ConfigMap configMap = Futures.getThrowingException(k8sClient.getConfigMap(PRAVEGA_CONTROLLER_CONFIG_MAP, NAMESPACE));
+            return k8sClient.deleteConfigMap(PRAVEGA_CONTROLLER_CONFIG_MAP, NAMESPACE)
+                        .thenCompose(v -> k8sClient.createConfigMap(NAMESPACE, addDefaultTlsConfiguration(configMap)));
+    }
+
+    private V1ConfigMap addDefaultTlsConfiguration(V1ConfigMap configMap) {
+            return configMap
+                        .putDataItem("TLS_ENABLED", "true")
+                        .putDataItem("TLS_KEY_FILE", "/etc/secret-volume/controller01.key.pem")
+                        .putDataItem("TLS_CERT_FILE", "/opt/pravega/conf/server-key.key")
+                        .putDataItem("TLS_TRUST_STORE", "/opt/pravega/conf/client.truststore.jks")
+                        .putDataItem("TLS_ENABLED_FOR_SEGMENT_STORE", "true")
+                        .putDataItem("REST_KEYSTORE_FILE_PATH", "/opt/pravega/conf/server.keystore.jks")
+                        .putDataItem("REST_KEYSTORE_PASSWORD_FILE_PATH", "/opt/pravega/conf/server.keystore.jks.passwd");
+
+    }


     /**
+     * Method to get V1ConfigMap
+     * @param name Name of the ConfigMap.
+     * @param namespace Namespace on which the pod(s) reside.
+     * @return Future representing the V1ConfigMap.
+     */
+    @SneakyThrows(ApiException.class)
+    public CompletableFuture<V1ConfigMap> getConfigMap(String name, String namespace) {
+        CoreV1Api api = new CoreV1Api();
+        K8AsyncCallback<V1ConfigMap> callback = new K8AsyncCallback<>("readNamespacedConfigMap");
+        api.readNamespacedConfigMapAsync(name, namespace, PRETTY_PRINT, false, false, callback);
+        return callback.getFuture();
+    }
+
+    /**
+     * Method to create V1ConfigMap
+     * @param name Name of the ConfigMap.
+     * @param namespace Namespace on which the pod(s) reside.
+     * @param configMap V1ConfigMap to create
+     * @return Future representing the V1ConfigMap.
+     */
"a.txt" 143L, 7941C                                                                                                                        1,1           Top
+     * @return Future representing the V1ConfigMap.
+     */
+    @SneakyThrows(ApiException.class)
+    public CompletableFuture<V1ConfigMap> createConfigMap(String namespace, V1ConfigMap configMap) {
+        CoreV1Api api = new CoreV1Api();
+        K8AsyncCallback<V1ConfigMap> callback = new K8AsyncCallback<>("createNamespacedConfigMap");
+        api.createNamespacedConfigMapAsync(namespace, configMap, PRETTY_PRINT, null, false, callback);
+        return callback.getFuture();
+    }
+
+    /**
+     * Method to delete V1ConfigMap
+     * @param name Name of the ConfigMap.
+     * @param namespace Namespace on which the pod(s) reside.
+     * @return Future representing the V1ConfigMap.
+     */
+    @SneakyThrows(ApiException.class)
+    public CompletableFuture<V1Status> deleteConfigMap(String name, String namespace) {
+        CoreV1Api api = new CoreV1Api();
+        K8AsyncCallback<V1Status> callback = new K8AsyncCallback<>("deleteNamespacedConfigMap");
+        api.deleteNamespacedConfigMapAsync(name, namespace, PRETTY_PRINT, null, 0, false, null, null, callback);
+        return callback.getFuture();
+    }
+

No comments:

Post a Comment