Skip to content

Commit 094eae7

Browse files
authored
add extraDependenciesDir for java runtime (#155)
1 parent 8712305 commit 094eae7

12 files changed

Lines changed: 65 additions & 30 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bin
1919

2020
# editor and IDE paraphernalia
2121
.idea
22+
*.iml
2223
*.swp
2324
*.swo
2425
*~

api/v1alpha1/common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ type Runtime struct {
8484
}
8585

8686
type JavaRuntime struct {
87-
Jar string `json:"jar,omitempty"`
88-
JarLocation string `json:"jarLocation,omitempty"`
87+
Jar string `json:"jar,omitempty"`
88+
JarLocation string `json:"jarLocation,omitempty"`
89+
ExtraDependenciesDir string `json:"extraDependenciesDir,omitempty"`
8990
}
9091

9192
type PythonRuntime struct {

config/crd/bases/compute.functionmesh.io_functionmeshes.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ spec:
132132
type: object
133133
java:
134134
properties:
135+
extraDependenciesDir:
136+
type: string
135137
jar:
136138
type: string
137139
jarLocation:
@@ -2360,6 +2362,8 @@ spec:
23602362
type: object
23612363
java:
23622364
properties:
2365+
extraDependenciesDir:
2366+
type: string
23632367
jar:
23642368
type: string
23652369
jarLocation:
@@ -4455,6 +4459,8 @@ spec:
44554459
type: string
44564460
java:
44574461
properties:
4462+
extraDependenciesDir:
4463+
type: string
44584464
jar:
44594465
type: string
44604466
jarLocation:

config/crd/bases/compute.functionmesh.io_functions.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ spec:
133133
type: object
134134
java:
135135
properties:
136+
extraDependenciesDir:
137+
type: string
136138
jar:
137139
type: string
138140
jarLocation:

config/crd/bases/compute.functionmesh.io_sinks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ spec:
127127
type: object
128128
java:
129129
properties:
130+
extraDependenciesDir:
131+
type: string
130132
jar:
131133
type: string
132134
jarLocation:

config/crd/bases/compute.functionmesh.io_sources.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ spec:
4949
type: string
5050
java:
5151
properties:
52+
extraDependenciesDir:
53+
type: string
5254
jar:
5355
type: string
5456
jarLocation:

config/samples/compute_v1alpha1_function.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ spec:
5959
java:
6060
jar: pulsar-functions-api-examples.jar
6161
jarLocation: public/default/nlu-test-java-function
62+
extraDependenciesDir: random-dir/
6263
# use package name:
6364
# jarLocation: function://public/default/nul-test-java-function@v1
6465
# to be delete & use admission hook

controllers/spec/common.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ func MakePodTemplate(container *corev1.Container, volumes []corev1.Volume,
161161
}
162162
}
163163

164-
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, details, memory string, authProvided bool) []string {
164+
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, details, memory, extraDependenciesDir string, authProvided bool) []string {
165165
processCommand := setShardIDEnvironmentVariableCommand() + " && " +
166-
strings.Join(getProcessJavaRuntimeArgs(name, packageFile, clusterName, details, memory, authProvided), " ")
166+
strings.Join(getProcessJavaRuntimeArgs(name, packageFile, clusterName, details, memory, extraDependenciesDir, authProvided), " ")
167167
if downloadPath != "" {
168168
// prepend download command if the downPath is provided
169169
downloadCommand := strings.Join(getDownloadCommand(downloadPath, packageFile), " ")
@@ -235,12 +235,16 @@ func setShardIDEnvironmentVariableCommand() string {
235235
return fmt.Sprintf("%s=${POD_NAME##*-} && echo shardId=${%s} && %s", EnvShardID, EnvShardID, tlsCommand)
236236
}
237237

238-
func getProcessJavaRuntimeArgs(name string, packageName string, clusterName string, details string, memory string, authProvided bool) []string {
238+
func getProcessJavaRuntimeArgs(name, packageName, clusterName, details, memory, extraDependenciesDir string, authProvided bool) []string {
239+
classPath := "/pulsar/instances/java-instance.jar"
240+
if extraDependenciesDir != "" {
241+
classPath = fmt.Sprintf("%s:%s/*", classPath, extraDependenciesDir)
242+
}
239243
args := []string{
240244
"exec",
241245
"java",
242246
"-cp",
243-
"/pulsar/instances/java-instance.jar",
247+
classPath,
244248
fmt.Sprintf("-D%s=%s", FunctionsInstanceClasspath, "/pulsar/lib/*"),
245249
"-Dlog4j.configurationFile=kubernetes_instance_log4j2.xml", // todo
246250
"-Dpulsar.function.log.dir=logs/functions",
@@ -255,7 +259,7 @@ func getProcessJavaRuntimeArgs(name string, packageName string, clusterName stri
255259
return args
256260
}
257261

258-
func getProcessPythonRuntimeArgs(name string, packageName string, clusterName string, details string, authProvided bool) []string {
262+
func getProcessPythonRuntimeArgs(name, packageName, clusterName, details string, authProvided bool) []string {
259263
args := []string{
260264
"exec",
261265
"python",

controllers/spec/function.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,25 @@ func makeFunctionLabels(function *v1alpha1.Function) map[string]string {
9898
}
9999

100100
func makeFunctionCommand(function *v1alpha1.Function) []string {
101-
if function.Spec.Java != nil {
102-
if function.Spec.Java.Jar != "" {
103-
return MakeJavaFunctionCommand(function.Spec.Java.JarLocation, function.Spec.Java.Jar,
104-
function.Spec.Name, function.Spec.ClusterName, generateFunctionDetailsInJSON(function),
105-
function.Spec.Resources.Requests.Memory().String(), function.Spec.Pulsar.AuthConfig != "")
101+
spec := function.Spec
102+
103+
if spec.Java != nil {
104+
if spec.Java.Jar != "" {
105+
return MakeJavaFunctionCommand(spec.Java.JarLocation, spec.Java.Jar,
106+
spec.Name, spec.ClusterName, generateFunctionDetailsInJSON(function),
107+
spec.Resources.Requests.Memory().String(), spec.Java.ExtraDependenciesDir,
108+
spec.Pulsar.AuthConfig != "")
106109
}
107-
108-
} else if function.Spec.Golang != nil {
109-
if function.Spec.Golang.Go != "" {
110-
return MakeGoFunctionCommand(function.Spec.Golang.GoLocation, function.Spec.Golang.Go,
111-
function)
110+
} else if spec.Python != nil {
111+
if spec.Python.Py != "" {
112+
return MakePythonFunctionCommand(spec.Python.PyLocation, spec.Python.Py,
113+
spec.Name, spec.ClusterName, generateFunctionDetailsInJSON(function),
114+
spec.Pulsar.AuthConfig != "")
112115
}
113-
} else if function.Spec.Python != nil {
114-
if function.Spec.Python.Py != "" {
115-
return MakePythonFunctionCommand(function.Spec.Python.PyLocation, function.Spec.Python.Py,
116-
function.Spec.Name, function.Spec.ClusterName, generateFunctionDetailsInJSON(function),
117-
function.Spec.Pulsar.AuthConfig != "")
116+
} else if spec.Golang != nil {
117+
if spec.Golang.Go != "" {
118+
return MakeGoFunctionCommand(spec.Golang.GoLocation, spec.Golang.Go,
119+
function)
118120
}
119121
}
120122

controllers/spec/sink.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ func makeSinkVolumeMounts(sink *v1alpha1.Sink) []corev1.VolumeMount {
9090
}
9191

9292
func MakeSinkCommand(sink *v1alpha1.Sink) []string {
93-
return MakeJavaFunctionCommand(sink.Spec.Java.JarLocation, sink.Spec.Java.Jar,
94-
sink.Spec.Name, sink.Spec.ClusterName, generateSinkDetailsInJSON(sink),
95-
sink.Spec.Resources.Requests.Memory().ToDec().String(),
96-
sink.Spec.Pulsar.AuthConfig != "")
93+
spec := sink.Spec
94+
return MakeJavaFunctionCommand(spec.Java.JarLocation, spec.Java.Jar,
95+
spec.Name, spec.ClusterName, generateSinkDetailsInJSON(sink),
96+
spec.Resources.Requests.Memory().ToDec().String(), spec.Java.ExtraDependenciesDir,
97+
spec.Pulsar.AuthConfig != "")
9798
}
9899

99100
func generateSinkDetailsInJSON(sink *v1alpha1.Sink) string {

0 commit comments

Comments
 (0)