From 312e155da805bc603c77aa527ad79d7ec0d455e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=B0=8F=E9=BE=99?= Date: Wed, 8 Apr 2020 09:07:36 +0800 Subject: [PATCH] Config admin CLI (#6681) Signed-off-by: xiaolong.ran ### Motivation Sometimes, users want to use a customized admin CLI tool. Currently, in the k8s runtime, hardcode is used in `getdownloadcommands()`. This change will support users to configure the CLI tool they want. The default value is: `/bin/pulsar-admin`. ### Modifications - Support config admin CLI --- .gitignore | 2 ++ conf/functions_worker.yml | 3 +++ .../functions/runtime/kubernetes/KubernetesRuntime.java | 7 +++++-- .../runtime/kubernetes/KubernetesRuntimeFactory.java | 7 +++++++ .../runtime/kubernetes/KubernetesRuntimeFactoryConfig.java | 6 ++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d4ec99340e41e..f6c7c3aca2e43 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ pulsar-broker/tmp.* pulsar-broker/src/test/resources/log4j2.yaml pulsar-functions/worker/test-tenant/ pulsar-broker/src/test/resources/pulsar-functions-api-examples.jar +pulsar-functions/runtime/src/test/resources/ +pulsar-functions/worker/src/test/resources/ *.log *.nar diff --git a/conf/functions_worker.yml b/conf/functions_worker.yml index 813cf7a7e70ab..73314e5786e28 100644 --- a/conf/functions_worker.yml +++ b/conf/functions_worker.yml @@ -160,6 +160,9 @@ functionRuntimeFactoryConfigs: # ram: 1073741824 # disk: 10737418240 +## Config admin CLI +#configAdminCLI: + ############################################ # security settings for worker service ############################################ diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntime.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntime.java index 782376d23683f..ca6c3537f5bf3 100644 --- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntime.java +++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntime.java @@ -133,6 +133,7 @@ public class KubernetesRuntime implements Runtime { private final String pulsarDockerImageName; private final String imagePullPolicy; private final String pulsarRootDir; + private final String configAdminCLI; private final String userCodePkgUrl; private final String originalCodeFileName; private final String pulsarAdminUrl; @@ -160,6 +161,7 @@ public class KubernetesRuntime implements Runtime { String instanceFile, String extraDependenciesDir, String logDirectory, + String configAdminCLI, String userCodePkgUrl, String originalCodeFileName, String pulsarServiceUrl, @@ -184,6 +186,7 @@ public class KubernetesRuntime implements Runtime { this.pulsarDockerImageName = pulsarDockerImageName; this.imagePullPolicy = imagePullPolicy; this.pulsarRootDir = pulsarRootDir; + this.configAdminCLI = configAdminCLI; this.userCodePkgUrl = userCodePkgUrl; this.originalCodeFileName = pulsarRootDir + "/" + originalCodeFileName; this.pulsarAdminUrl = pulsarAdminUrl; @@ -804,7 +807,7 @@ private List getDownloadCommand(String tenant, String namespace, String && isNotBlank(authConfig.getClientAuthenticationParameters()) && instanceConfig.getFunctionAuthenticationSpec() != null) { return Arrays.asList( - pulsarRootDir + "/bin/pulsar-admin", + pulsarRootDir + configAdminCLI, "--auth-plugin", authConfig.getClientAuthenticationPlugin(), "--auth-params", @@ -825,7 +828,7 @@ && isNotBlank(authConfig.getClientAuthenticationParameters()) } return Arrays.asList( - pulsarRootDir + "/bin/pulsar-admin", + pulsarRootDir + configAdminCLI, "--admin-url", pulsarAdminUrl, "functions", diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java index 3b9bc7535748a..46a3216650b97 100644 --- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java +++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactory.java @@ -69,6 +69,7 @@ public class KubernetesRuntimeFactory implements RuntimeFactory { private String pulsarDockerImageName; private String imagePullPolicy; private String pulsarRootDir; + private String configAdminCLI; private String pulsarAdminUrl; private String pulsarServiceUrl; private String pythonDependencyRepository; @@ -151,6 +152,11 @@ public void initialize(WorkerConfig workerConfig, AuthenticationConfig authentic } else { this.pulsarRootDir = "/pulsar"; } + if (!isEmpty(factoryConfig.getConfigAdminCLI())) { + this.configAdminCLI = factoryConfig.getConfigAdminCLI(); + } else { + this.configAdminCLI = "/bin/pulsar-admin"; + } this.submittingInsidePod = factoryConfig.getSubmittingInsidePod(); this.installUserCodeDependencies = factoryConfig.getInstallUserCodeDependencies(); @@ -270,6 +276,7 @@ public KubernetesRuntime createContainer(InstanceConfig instanceConfig, String c instanceFile, extraDependenciesDir, logDirectory, + configAdminCLI, codePkgUrl, originalCodeFileName, pulsarServiceUrl, diff --git a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactoryConfig.java b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactoryConfig.java index 085a640194122..f0173422d1817 100644 --- a/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactoryConfig.java +++ b/pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/kubernetes/KubernetesRuntimeFactoryConfig.java @@ -52,6 +52,12 @@ public class KubernetesRuntimeFactoryConfig { + " customized image in `pulsarDockerImageName`, you need to set this setting accordingly" ) protected String pulsarRootDir; + @FieldContext( + doc = "The config admin CLI allows users to customize the configuration of the admin cli tool, such as:" + + " `/bin/pulsar-admin and /bin/pulsarctl`. By default it is `/bin/pulsar-admin`. If you want to use `pulsarctl` " + + " you need to set this setting accordingly" + ) + protected String configAdminCLI; @FieldContext( doc = "This setting only takes effects if `k8Uri` is set to null. If your function worker is" + " also running as a k8s pod, set this to `true` is let function worker to submit functions to"