use of org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator in project pulsar by apache.
the class KubernetesRuntimeFactoryTest method getKuberentesRuntimeFactory.
private KubernetesRuntimeFactory getKuberentesRuntimeFactory() {
KubernetesRuntimeFactory kubernetesRuntimeFactory = new KubernetesRuntimeFactory();
WorkerConfig workerConfig = new WorkerConfig();
Map<String, String> imageNames = new HashMap<>();
imageNames.put("JAVA", "test-java-function-docker-image");
imageNames.put("PYTHON", "test-python-function-docker-image");
imageNames.put("GO", "test-go-function-docker-image");
KubernetesRuntimeFactoryConfig kubernetesRuntimeFactoryConfig = new KubernetesRuntimeFactoryConfig();
kubernetesRuntimeFactoryConfig.setK8Uri("test_k8uri");
kubernetesRuntimeFactoryConfig.setJobNamespace("test_jobNamespace");
kubernetesRuntimeFactoryConfig.setJobName("test_jobName");
kubernetesRuntimeFactoryConfig.setPulsarDockerImageName("test_dockerImage");
kubernetesRuntimeFactoryConfig.setFunctionDockerImages(imageNames);
kubernetesRuntimeFactoryConfig.setImagePullPolicy("test_imagePullPolicy");
workerConfig.setFunctionRuntimeFactoryClassName(KubernetesRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(kubernetesRuntimeFactoryConfig, Map.class));
AuthenticationConfig authenticationConfig = AuthenticationConfig.builder().build();
kubernetesRuntimeFactory.initialize(workerConfig, authenticationConfig, new DefaultSecretsProviderConfigurator(), Mockito.mock(ConnectorsManager.class), Optional.empty(), Optional.empty());
return kubernetesRuntimeFactory;
}
use of org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator in project pulsar by apache.
the class KubernetesRuntimeTest method assertMetricsPortConfigured.
private void assertMetricsPortConfigured(Map<String, Object> functionRuntimeFactoryConfigs, int expectedPort) throws Exception {
KubernetesRuntimeFactory kubernetesRuntimeFactory = new KubernetesRuntimeFactory();
WorkerConfig workerConfig = new WorkerConfig();
workerConfig.setFunctionRuntimeFactoryClassName(KubernetesRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(functionRuntimeFactoryConfigs);
AuthenticationConfig authenticationConfig = AuthenticationConfig.builder().build();
kubernetesRuntimeFactory.initialize(workerConfig, authenticationConfig, new DefaultSecretsProviderConfigurator(), Mockito.mock(ConnectorsManager.class), Optional.empty(), Optional.empty());
InstanceConfig config = createJavaInstanceConfig(FunctionDetails.Runtime.JAVA, true);
KubernetesRuntime container = kubernetesRuntimeFactory.createContainer(config, userJarFile, userJarFile, 30l);
V1PodTemplateSpec template = container.createStatefulSet().getSpec().getTemplate();
Map<String, String> annotations = template.getMetadata().getAnnotations();
if (expectedPort != -1) {
// metrics port should be passed to k8s annotation for prometheus scraping
assertEquals(annotations.get("prometheus.io/port"), String.valueOf(expectedPort));
// scraping annotation should exist
assertEquals(annotations.get("prometheus.io/scrape"), "true");
// metrics port should be passed to JavaInstanceStarter with --metrics_port argument
assertTrue(container.getProcessArgs().stream().collect(Collectors.joining(" ")).contains("--metrics_port " + expectedPort));
} else {
// No prometheus annotations should exist
assertFalse(annotations.containsKey("prometheus.io/scrape"));
assertFalse(annotations.containsKey("prometheus.io/port"));
// metrics will be started on random port when the port isn't specified
// check that "--metrics_port 0" argument is passed
assertTrue(container.getProcessArgs().stream().collect(Collectors.joining(" ")).contains("--metrics_port 0"));
}
}
use of org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator in project incubator-pulsar by apache.
the class KubernetesRuntimeFactoryTest method getKuberentesRuntimeFactory.
private KubernetesRuntimeFactory getKuberentesRuntimeFactory() {
KubernetesRuntimeFactory kubernetesRuntimeFactory = new KubernetesRuntimeFactory();
WorkerConfig workerConfig = new WorkerConfig();
Map<String, String> imageNames = new HashMap<>();
imageNames.put("JAVA", "test-java-function-docker-image");
imageNames.put("PYTHON", "test-python-function-docker-image");
imageNames.put("GO", "test-go-function-docker-image");
KubernetesRuntimeFactoryConfig kubernetesRuntimeFactoryConfig = new KubernetesRuntimeFactoryConfig();
kubernetesRuntimeFactoryConfig.setK8Uri("test_k8uri");
kubernetesRuntimeFactoryConfig.setJobNamespace("test_jobNamespace");
kubernetesRuntimeFactoryConfig.setJobName("test_jobName");
kubernetesRuntimeFactoryConfig.setPulsarDockerImageName("test_dockerImage");
kubernetesRuntimeFactoryConfig.setFunctionDockerImages(imageNames);
kubernetesRuntimeFactoryConfig.setImagePullPolicy("test_imagePullPolicy");
workerConfig.setFunctionRuntimeFactoryClassName(KubernetesRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(kubernetesRuntimeFactoryConfig, Map.class));
AuthenticationConfig authenticationConfig = AuthenticationConfig.builder().build();
kubernetesRuntimeFactory.initialize(workerConfig, authenticationConfig, new DefaultSecretsProviderConfigurator(), Mockito.mock(ConnectorsManager.class), Optional.empty(), Optional.empty());
return kubernetesRuntimeFactory;
}
use of org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator in project incubator-pulsar by apache.
the class KubernetesRuntimeTest method assertMetricsPortConfigured.
private void assertMetricsPortConfigured(Map<String, Object> functionRuntimeFactoryConfigs, int expectedPort) throws Exception {
KubernetesRuntimeFactory kubernetesRuntimeFactory = new KubernetesRuntimeFactory();
WorkerConfig workerConfig = new WorkerConfig();
workerConfig.setFunctionRuntimeFactoryClassName(KubernetesRuntimeFactory.class.getName());
workerConfig.setFunctionRuntimeFactoryConfigs(functionRuntimeFactoryConfigs);
AuthenticationConfig authenticationConfig = AuthenticationConfig.builder().build();
kubernetesRuntimeFactory.initialize(workerConfig, authenticationConfig, new DefaultSecretsProviderConfigurator(), Mockito.mock(ConnectorsManager.class), Optional.empty(), Optional.empty());
InstanceConfig config = createJavaInstanceConfig(FunctionDetails.Runtime.JAVA, true);
KubernetesRuntime container = kubernetesRuntimeFactory.createContainer(config, userJarFile, userJarFile, 30l);
V1PodTemplateSpec template = container.createStatefulSet().getSpec().getTemplate();
Map<String, String> annotations = template.getMetadata().getAnnotations();
if (expectedPort != -1) {
// metrics port should be passed to k8s annotation for prometheus scraping
assertEquals(annotations.get("prometheus.io/port"), String.valueOf(expectedPort));
// scraping annotation should exist
assertEquals(annotations.get("prometheus.io/scrape"), "true");
// metrics port should be passed to JavaInstanceStarter with --metrics_port argument
assertTrue(container.getProcessArgs().stream().collect(Collectors.joining(" ")).contains("--metrics_port " + expectedPort));
} else {
// No prometheus annotations should exist
assertFalse(annotations.containsKey("prometheus.io/scrape"));
assertFalse(annotations.containsKey("prometheus.io/port"));
// metrics will be started on random port when the port isn't specified
// check that "--metrics_port 0" argument is passed
assertTrue(container.getProcessArgs().stream().collect(Collectors.joining(" ")).contains("--metrics_port 0"));
}
}
use of org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator in project incubator-pulsar by apache.
the class LocalRunner method getSecretsProviderConfigurator.
private SecretsProviderConfigurator getSecretsProviderConfigurator() {
SecretsProviderConfigurator secretsProviderConfigurator;
if (secretsProviderClassName != null) {
Map<String, String> config = null;
if (secretsProviderConfig != null) {
config = (Map<String, String>) new Gson().fromJson(secretsProviderConfig, Map.class);
}
secretsProviderConfigurator = new NameAndConfigBasedSecretsProviderConfigurator(secretsProviderClassName, config);
} else {
secretsProviderConfigurator = new DefaultSecretsProviderConfigurator();
}
return secretsProviderConfigurator;
}
Aggregations