@Test public void testDynamicConfigMapLoading() throws Exception { String changeConfigMap = "changeMap"; String changeConfigNamespace = "changeConfigNamespace"; KubernetesRuntimeFactory kubernetesRuntimeFactory = getKuberentesRuntimeFactory(); CoreV1Api coreV1Api = Mockito.mock(CoreV1Api.class); V1ConfigMap v1ConfigMap = new V1ConfigMap(); Mockito.doReturn(v1ConfigMap).when(coreV1Api).readNamespacedConfigMap(any(), any(), any(), any(), any()); KubernetesRuntimeFactory.fetchConfigMap(coreV1Api, changeConfigMap, changeConfigNamespace, kubernetesRuntimeFactory); Mockito.verify(coreV1Api, Mockito.times(1)).readNamespacedConfigMap(eq(changeConfigMap), eq(changeConfigNamespace), eq(null), eq(true), eq(false)); KubernetesRuntimeFactory expected = getKuberentesRuntimeFactory(); assertEquals(kubernetesRuntimeFactory, expected); HashMap<String, String> configs = new HashMap<>(); configs.put("pulsarDockerImageName", "test_dockerImage2"); configs.put("imagePullPolicy", "test_imagePullPolicy2"); v1ConfigMap.setData(configs); KubernetesRuntimeFactory.fetchConfigMap(coreV1Api, changeConfigMap, changeConfigNamespace, kubernetesRuntimeFactory); Mockito.verify(coreV1Api, Mockito.times(2)).readNamespacedConfigMap(eq(changeConfigMap), eq(changeConfigNamespace), eq(null), eq(true), eq(false)); assertEquals(kubernetesRuntimeFactory.getPulsarDockerImageName(), "test_dockerImage2"); assertEquals(kubernetesRuntimeFactory.getImagePullPolicy(), "test_imagePullPolicy2"); }
static void fetchConfigMap(CoreV1Api coreClient, String changeConfigMap, String changeConfigMapNamespace, KubernetesRuntimeFactory kubernetesRuntimeFactory) { try { V1ConfigMap v1ConfigMap = coreClient.readNamespacedConfigMap(changeConfigMap, changeConfigMapNamespace, null, true, false); Map<String, String> data = v1ConfigMap.getData(); if (data != null) { overRideKubernetesConfig(data, kubernetesRuntimeFactory); } } catch (Exception e) { log.error("Error while trying to fetch configmap {} at namespace {}", changeConfigMap, changeConfigMapNamespace, e); } }
KubernetesRuntimeFactory implements RuntimeFactory { static void fetchConfigMap(CoreV1Api coreClient, String changeConfigMap, String changeConfigMapNamespace, KubernetesRuntimeFactory kubernetesRuntimeFactory) { try { V1ConfigMap v1ConfigMap = coreClient.readNamespacedConfigMap(changeConfigMap, changeConfigMapNamespace, null, true, false); Map<String, String> data = v1ConfigMap.getData(); if (data != null) { overRideKubernetesConfig(data, kubernetesRuntimeFactory); } } catch (Exception e) { log.error("Error while trying to fetch configmap {} at namespace {}", changeConfigMap, changeConfigMapNamespace, e); } } }
KubernetesRuntimeFactory implements RuntimeFactory { static void fetchConfigMap(CoreV1Api coreClient, String changeConfigMap, String changeConfigMapNamespace, KubernetesRuntimeFactory kubernetesRuntimeFactory) { try { V1ConfigMap v1ConfigMap = coreClient.readNamespacedConfigMap(changeConfigMap, changeConfigMapNamespace, null, true, false); Map<String, String> data = v1ConfigMap.getData(); if (data != null) { overRideKubernetesConfig(data, kubernetesRuntimeFactory); } } catch (Exception e) { log.error("Error while trying to fetch configmap {} at namespace {}", changeConfigMap, changeConfigMapNamespace, e); } }  }
KubernetesRuntimeFactory implements RuntimeFactory { static void fetchConfigMap(CoreV1Api coreClient, String changeConfigMap, String changeConfigMapNamespace, KubernetesRuntimeFactory kubernetesRuntimeFactory) { try { V1ConfigMap v1ConfigMap = coreClient.readNamespacedConfigMap(changeConfigMap, changeConfigMapNamespace, null, true, false); Map<String, String> data = v1ConfigMap.getData(); if (data != null) { overRideKubernetesConfig(data, kubernetesRuntimeFactory); } } catch (Exception e) { log.error("Error while trying to fetch configmap {} at namespace {}", changeConfigMap, changeConfigMapNamespace, e); } }  @Override boolean externallyManaged(); @Override void initialize(WorkerConfig workerConfig, AuthenticationConfig authenticationConfig,
                           SecretsProviderConfigurator secretsProviderConfigurator,
                           Optional<FunctionAuthProvider> functionAuthProvider,
                           Optional<RuntimeCustomizer> runtimeCustomizer); @Override KubernetesRuntime createContainer(InstanceConfig instanceConfig, String codePkgUrl,
                                             String originalCodeFileName,
                                             Long expectedHealthCheckInterval); @Override void close(); @Override void doAdmissionChecks(Function.FunctionDetails functionDetails); @VisibleForTesting void setupClient(); @Override Optional<KubernetesFunctionAuthProvider> getAuthProvider(); @Override Optional<KubernetesManifestCustomizer> getRuntimeCustomizer(); }
KubernetesRuntimeFactory implements RuntimeFactory { static void fetchConfigMap(CoreV1Api coreClient, String changeConfigMap, String changeConfigMapNamespace, KubernetesRuntimeFactory kubernetesRuntimeFactory) { try { V1ConfigMap v1ConfigMap = coreClient.readNamespacedConfigMap(changeConfigMap, changeConfigMapNamespace, null, true, false); Map<String, String> data = v1ConfigMap.getData(); if (data != null) { overRideKubernetesConfig(data, kubernetesRuntimeFactory); } } catch (Exception e) { log.error("Error while trying to fetch configmap {} at namespace {}", changeConfigMap, changeConfigMapNamespace, e); } }  @Override boolean externallyManaged(); @Override void initialize(WorkerConfig workerConfig, AuthenticationConfig authenticationConfig,
                           SecretsProviderConfigurator secretsProviderConfigurator,
                           Optional<FunctionAuthProvider> functionAuthProvider,
                           Optional<RuntimeCustomizer> runtimeCustomizer); @Override KubernetesRuntime createContainer(InstanceConfig instanceConfig, String codePkgUrl,
                                             String originalCodeFileName,
                                             Long expectedHealthCheckInterval); @Override void close(); @Override void doAdmissionChecks(Function.FunctionDetails functionDetails); @VisibleForTesting void setupClient(); @Override Optional<KubernetesFunctionAuthProvider> getAuthProvider(); @Override Optional<KubernetesManifestCustomizer> getRuntimeCustomizer();  }