Skip to content

Commit 613a7bd

Browse files
authored
make function path consistency when initContainer downloader enabled (#798)
* make function path consistency when initContainer downloader enabled * address comment * fix cve * fmt * fix fmt
1 parent e53faaa commit 613a7bd

File tree

14 files changed

+110
-29
lines changed

14 files changed

+110
-29
lines changed

.github/workflows/bundle-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ jobs:
4949
username: ${{ secrets.DOCKER_USER }}
5050
password: ${{ secrets.DOCKER_PASSWORD }}
5151

52-
- name: Set up GO 1.22.7
52+
- name: Set up GO 1.22.12
5353
uses: actions/setup-go@v1
5454
with:
55-
go-version: 1.22.7
55+
go-version: 1.22.12
5656
id: go
5757

5858
- name: InstallKubebuilder
@@ -180,10 +180,10 @@ jobs:
180180
username: ${{ secrets.DOCKER_USER }}
181181
password: ${{ secrets.DOCKER_PASSWORD }}
182182

183-
- name: Set up GO 1.22.7
183+
- name: Set up GO 1.22.12
184184
uses: actions/setup-go@v1
185185
with:
186-
go-version: 1.22.7
186+
go-version: 1.22.12
187187
id: go
188188

189189
- name: InstallKubebuilder

.github/workflows/olm-verify.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434
- name: checkout
3535
uses: actions/checkout@v2
3636

37-
- name: Set up GO 1.22.7
37+
- name: Set up GO 1.22.12
3838
uses: actions/setup-go@v1
3939
with:
40-
go-version: 1.22.7
40+
go-version: 1.22.12
4141
id: go
4242

4343
- name: InstallKubebuilder

.github/workflows/project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
go-version: [1.21.9, 1.22.7]
21+
go-version: [1.21.9, 1.22.12]
2222
steps:
2323
- name: Free Disk Space (Ubuntu)
2424
uses: jlumbroso/[email protected]

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ jobs:
3737
username: ${{ secrets.DOCKER_USER }}
3838
password: ${{ secrets.DOCKER_PASSWORD }}
3939

40-
- name: Set up GO 1.22.7
40+
- name: Set up GO 1.22.12
4141
uses: actions/setup-go@v1
4242
with:
43-
go-version: 1.22.7
43+
go-version: 1.22.12
4444
id: go
4545

4646
- name: InstallKubebuilder

.github/workflows/test-helm-charts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ jobs:
8383
run: hack/kind-cluster-build.sh --name chart-testing -c 1 -v 10 --k8sVersion v1.23.17
8484
if: steps.list-changed.outputs.changed == 'true'
8585

86-
- name: Set up GO 1.22.7
86+
- name: Set up GO 1.22.12
8787
if: steps.list-changed.outputs.changed == 'true'
8888
uses: actions/setup-go@v1
8989
with:
90-
go-version: 1.22.7
90+
go-version: 1.22.12
9191
id: go
9292

9393
- name: setup kubebuilder 3.6.0

.github/workflows/trivy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434
repository: ${{github.event.pull_request.head.repo.full_name}}
3535
ref: ${{ github.event.pull_request.head.sha }}
3636

37-
- name: Set up GO 1.22.7
37+
- name: Set up GO 1.22.12
3838
uses: actions/setup-go@v1
3939
with:
40-
go-version: 1.22.7
40+
go-version: 1.22.12
4141
id: go
4242

4343
- name: InstallKubebuilder

.github/workflows/trivy_scheduled_master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ jobs:
4545
repository: ${{github.event.pull_request.head.repo.full_name}}
4646
ref: ${{ github.event.pull_request.head.sha }}
4747

48-
- name: Set up GO 1.22.7
48+
- name: Set up GO 1.22.12
4949
uses: actions/setup-go@v1
5050
with:
51-
go-version: 1.22.7
51+
go-version: 1.22.12
5252
id: go
5353

5454
- name: InstallKubebuilder

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22.7-bullseye as builder
2+
FROM golang:1.22.12-bullseye as builder
33

44
WORKDIR /workspace/api
55
COPY api/ .

controllers/spec/common.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,14 +1801,16 @@ func generateDownloaderVolumeMountsForDownloader(javaRuntime *v1alpha1.JavaRunti
18011801
}
18021802

18031803
func generateDownloaderVolumeMountsForRuntime(javaRuntime *v1alpha1.JavaRuntime, pythonRuntime *v1alpha1.PythonRuntime,
1804-
goRuntime *v1alpha1.GoRuntime) []corev1.VolumeMount {
1804+
goRuntime *v1alpha1.GoRuntime, genericRuntime *v1alpha1.GenericRuntime) []corev1.VolumeMount {
18051805
downloadPath := ""
18061806
if javaRuntime != nil && javaRuntime.JarLocation != "" {
18071807
downloadPath = javaRuntime.Jar
18081808
} else if pythonRuntime != nil && pythonRuntime.PyLocation != "" {
18091809
downloadPath = pythonRuntime.Py
18101810
} else if goRuntime != nil && goRuntime.GoLocation != "" {
18111811
downloadPath = goRuntime.Go
1812+
} else if genericRuntime != nil && genericRuntime.FunctionFile != "" {
1813+
downloadPath = genericRuntime.FunctionFile
18121814
}
18131815

18141816
if downloadPath != "" {
@@ -1830,9 +1832,10 @@ func generateDownloaderVolumeMountsForRuntime(javaRuntime *v1alpha1.JavaRuntime,
18301832
SubPath: subPath,
18311833
}}
18321834
}
1835+
idx := strings.LastIndex(mountPath, "/")
18331836
return []corev1.VolumeMount{{
18341837
Name: DownloaderVolume,
1835-
MountPath: mountPath[:len(mountPath)-len(subPath)],
1838+
MountPath: mountPath[:idx],
18361839
}}
18371840
}
18381841
return nil

controllers/spec/function.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package spec
2020
import (
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

Comments
 (0)