@@ -20,6 +20,7 @@ package spec
2020import (
2121 "context"
2222 "regexp"
23+ "strings"
2324
2425 "github.com/streamnative/function-mesh/api/compute/v1alpha1"
2526 "github.com/streamnative/function-mesh/utils"
@@ -177,7 +178,7 @@ func makeFunctionContainer(function *v1alpha1.Function) *corev1.Container {
177178 mounts := makeFunctionVolumeMounts (function , function .Spec .Pulsar .AuthConfig )
178179 if utils .EnableInitContainers {
179180 mounts = append (mounts ,
180- generateDownloaderVolumeMountsForRuntime (function .Spec .Java , function .Spec .Python , function .Spec .Golang )... )
181+ generateDownloaderVolumeMountsForRuntime (function .Spec .Java , function .Spec .Python , function .Spec .Golang , function . Spec . GenericRuntime )... )
181182 }
182183 return & corev1.Container {
183184 // TODO new container to pull user code image and upload jars into bookkeeper
@@ -230,7 +231,8 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
230231 }
231232 if spec .Java != nil {
232233 if spec .Java .Jar != "" {
233- return MakeJavaFunctionCommand (spec .Java .JarLocation , spec .Java .Jar ,
234+ mountPath := extractMountPath (spec .Java .Jar )
235+ return MakeJavaFunctionCommand (spec .Java .JarLocation , mountPath ,
234236 spec .Name , spec .ClusterName ,
235237 GenerateJavaLogConfigCommand (spec .Java , spec .LogTopicAgent ),
236238 parseJavaLogLevel (spec .Java ),
@@ -246,7 +248,8 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
246248 }
247249 } else if spec .Python != nil {
248250 if spec .Python .Py != "" {
249- return MakePythonFunctionCommand (spec .Python .PyLocation , spec .Python .Py ,
251+ mountPath := extractMountPath (spec .Python .Py )
252+ return MakePythonFunctionCommand (spec .Python .PyLocation , mountPath ,
250253 spec .Name , spec .ClusterName ,
251254 generatePythonLogConfigCommand (spec .Name , spec .Python , spec .LogTopicAgent ),
252255 generateFunctionDetailsInJSON (function ), string (function .UID ), hasPulsarctl , hasWget ,
@@ -255,11 +258,13 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
255258 }
256259 } else if spec .Golang != nil {
257260 if spec .Golang .Go != "" {
258- return MakeGoFunctionCommand (spec .Golang .GoLocation , spec .Golang .Go , function )
261+ mountPath := extractMountPath (spec .Golang .Go )
262+ return MakeGoFunctionCommand (spec .Golang .GoLocation , mountPath , function )
259263 }
260264 } else if spec .GenericRuntime != nil {
261265 if spec .GenericRuntime .FunctionFile != "" {
262- return MakeGenericFunctionCommand (spec .GenericRuntime .FunctionFileLocation , spec .GenericRuntime .FunctionFile ,
266+ mountPath := extractMountPath (spec .GenericRuntime .FunctionFile )
267+ return MakeGenericFunctionCommand (spec .GenericRuntime .FunctionFileLocation , mountPath ,
263268 spec .GenericRuntime .Language , spec .ClusterName ,
264269 generateFunctionDetailsInJSON (function ), string (function .UID ),
265270 spec .Pulsar .AuthSecret != "" , spec .Pulsar .TLSSecret != "" , function .Spec .SecretsMap ,
@@ -280,3 +285,18 @@ func generateFunctionDetailsInJSON(function *v1alpha1.Function) string {
280285 log .Info (string (json ))
281286 return string (json )
282287}
288+
289+ func extractMountPath (p string ) string {
290+ if utils .EnableInitContainers {
291+ mountPath := p
292+ // for relative path, volume should be mounted to the WorkDir
293+ // and path also should be under the $WorkDir dir
294+ if ! strings .HasPrefix (p , "/" ) {
295+ mountPath = WorkDir + p
296+ } else if ! strings .HasPrefix (p , WorkDir ) {
297+ mountPath = strings .Replace (p , "/" , WorkDir , 1 )
298+ }
299+ return mountPath
300+ }
301+ return p
302+ }
0 commit comments