This is an automated email from the ASF dual-hosted git repository.

gyfora pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new ff5c00c6 FLINK-31140 - Load additional dependencies in operator 
classpath from user
ff5c00c6 is described below

commit ff5c00c695cdf844aca0c68242279da3afad124c
Author: Tamir Sagi <tamirs...@users.noreply.github.com>
AuthorDate: Thu Mar 2 17:08:50 2023 +0200

    FLINK-31140 - Load additional dependencies in operator classpath from user
---
 Dockerfile                              |  6 ++++--
 docker-entrypoint.sh                    |  4 ++--
 docs/content/docs/operations/plugins.md | 15 +++++++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index be926629..02c9f711 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,13 +36,16 @@ RUN cd /app/tools/license; mkdir jars; cd jars; \
 # stage
 FROM eclipse-temurin:11-jre-jammy
 ENV FLINK_HOME=/opt/flink
-ENV FLINK_PLUGINS_DIR=/opt/flink/plugins
+ENV FLINK_PLUGINS_DIR=$FLINK_HOME/plugins
 ENV OPERATOR_VERSION=1.5-SNAPSHOT
 ENV OPERATOR_JAR=flink-kubernetes-operator-$OPERATOR_VERSION-shaded.jar
 ENV AUTOSCALER_JAR=flink-kubernetes-operator-autoscaler-$OPERATOR_VERSION.jar
 ENV WEBHOOK_JAR=flink-kubernetes-webhook-$OPERATOR_VERSION-shaded.jar
 ENV 
FLINK_KUBERNETES_SHADED_JAR=flink-kubernetes-standalone-$OPERATOR_VERSION-shaded.jar
 
+ENV OPERATOR_LIB=$FLINK_HOME/operator-lib
+RUN mkdir -p $OPERATOR_LIB
+
 WORKDIR /flink-kubernetes-operator
 RUN groupadd --system --gid=9999 flink && \
     useradd --system --home-dir $FLINK_HOME --uid=9999 --gid=flink flink
@@ -63,7 +66,6 @@ RUN chown -R flink:flink $FLINK_HOME && \
     chown flink:flink $FLINK_KUBERNETES_SHADED_JAR && \
     chown flink:flink /docker-entrypoint.sh
 
-
 ARG SKIP_OS_UPDATE=true
 
 # Updating Debian
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 756b1d07..71ab065d 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -29,12 +29,12 @@ if [ "$1" = "help" ]; then
 elif [ "$1" = "operator" ]; then
     echo "Starting Operator"
 
-    exec java -cp 
./$FLINK_KUBERNETES_SHADED_JAR:./$OPERATOR_JAR:./$AUTOSCALER_JAR $LOG_CONFIG 
$JVM_ARGS org.apache.flink.kubernetes.operator.FlinkOperator
+    exec java -cp 
"./$FLINK_KUBERNETES_SHADED_JAR:./$OPERATOR_JAR:./$AUTOSCALER_JAR:$OPERATOR_LIB/*"
 $LOG_CONFIG $JVM_ARGS org.apache.flink.kubernetes.operator.FlinkOperator
 elif [ "$1" = "webhook" ]; then
     echo "Starting Webhook"
 
     # Adds the operator shaded jar on the classpath when the webhook starts
-    exec java -cp 
./$FLINK_KUBERNETES_SHADED_JAR:./$OPERATOR_JAR:./$WEBHOOK_JAR $LOG_CONFIG 
$JVM_ARGS org.apache.flink.kubernetes.operator.admission.FlinkOperatorWebhook
+    exec java -cp 
"./$FLINK_KUBERNETES_SHADED_JAR:./$OPERATOR_JAR:./$WEBHOOK_JAR:$OPERATOR_LIB/*" 
$LOG_CONFIG $JVM_ARGS 
org.apache.flink.kubernetes.operator.admission.FlinkOperatorWebhook
 fi
 
 args=("${args[@]}")
diff --git a/docs/content/docs/operations/plugins.md 
b/docs/content/docs/operations/plugins.md
index 855b2deb..efbf34e7 100644
--- a/docs/content/docs/operations/plugins.md
+++ b/docs/content/docs/operations/plugins.md
@@ -109,3 +109,18 @@ In order to enable your custom `FlinkResourceListener` you 
need to:
  1. Implement the interface
  2. Add your listener class to 
`org.apache.flink.kubernetes.operator.listener.FlinkResourceListener` in 
`META-INF/services`
  3. Package your JAR and add it to the plugins directory of your operator 
image (`/opt/flink/plugins`)
+
+
+## Additional Dependencies
+In some cases, users may need to add required dependencies onto the operator 
classpath.
+
+When building the custom image, The additional dependencies shall be copied to 
`/opt/flink/operator-lib` with the environment variable: `OPERATOR_LIB`
+That folder is added to classpath upon initialization.
+
+```shell script
+    FROM apache/flink-kubernetes-operator
+    ARG ARTIFACT1=custom-artifact1.jar
+    ARG ARTIFACT2=custom-artifact2.jar
+    COPY target/$ARTIFACT1 $OPERATOR_LIB
+    COPY target/$ARTIFACT2 $OPERATOR_LIB
+```

Reply via email to