Search in sources :

Example 1 with DefaultSecretsProviderConfigurator

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;
}
Also used : AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) HashMap(java.util.HashMap) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ConnectorsManager(org.apache.pulsar.functions.worker.ConnectorsManager)

Example 2 with DefaultSecretsProviderConfigurator

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"));
    }
}
Also used : AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) InstanceConfig(org.apache.pulsar.functions.instance.InstanceConfig) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) ConnectorsManager(org.apache.pulsar.functions.worker.ConnectorsManager)

Example 3 with DefaultSecretsProviderConfigurator

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;
}
Also used : AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) HashMap(java.util.HashMap) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ConnectorsManager(org.apache.pulsar.functions.worker.ConnectorsManager)

Example 4 with DefaultSecretsProviderConfigurator

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"));
    }
}
Also used : AuthenticationConfig(org.apache.pulsar.functions.instance.AuthenticationConfig) DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) InstanceConfig(org.apache.pulsar.functions.instance.InstanceConfig) WorkerConfig(org.apache.pulsar.functions.worker.WorkerConfig) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) ConnectorsManager(org.apache.pulsar.functions.worker.ConnectorsManager)

Example 5 with DefaultSecretsProviderConfigurator

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;
}
Also used : DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) NameAndConfigBasedSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.NameAndConfigBasedSecretsProviderConfigurator) SecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator) DefaultSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator) Gson(com.google.gson.Gson) NameAndConfigBasedSecretsProviderConfigurator(org.apache.pulsar.functions.secretsproviderconfigurator.NameAndConfigBasedSecretsProviderConfigurator)

Aggregations

DefaultSecretsProviderConfigurator (org.apache.pulsar.functions.secretsproviderconfigurator.DefaultSecretsProviderConfigurator)9 AuthenticationConfig (org.apache.pulsar.functions.instance.AuthenticationConfig)6 ConnectorsManager (org.apache.pulsar.functions.worker.ConnectorsManager)6 WorkerConfig (org.apache.pulsar.functions.worker.WorkerConfig)6 Gson (com.google.gson.Gson)3 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)3 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 InstanceConfig (org.apache.pulsar.functions.instance.InstanceConfig)3 NameAndConfigBasedSecretsProviderConfigurator (org.apache.pulsar.functions.secretsproviderconfigurator.NameAndConfigBasedSecretsProviderConfigurator)3 SecretsProviderConfigurator (org.apache.pulsar.functions.secretsproviderconfigurator.SecretsProviderConfigurator)3