Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, detai
memory, extraDependenciesDir, authProvided, tlsProvided), " ")
if downloadPath != "" {
// prepend download command if the downPath is provided
downloadCommand := strings.Join(getDownloadCommand(downloadPath, packageFile), " ")
downloadCommand := strings.Join(getDownloadCommand(downloadPath, packageFile, authProvided, tlsProvided), " ")
processCommand = downloadCommand + " && " + processCommand
}
return []string{"sh", "-c", processCommand}
Expand All @@ -166,7 +166,7 @@ func MakePythonFunctionCommand(downloadPath, packageFile, name, clusterName, det
details, authProvided, tlsProvided), " ")
if downloadPath != "" {
// prepend download command if the downPath is provided
downloadCommand := strings.Join(getDownloadCommand(downloadPath, packageFile), " ")
downloadCommand := strings.Join(getDownloadCommand(downloadPath, packageFile, authProvided, tlsProvided), " ")
processCommand = downloadCommand + " && " + processCommand
}
return []string{"sh", "-c", processCommand}
Expand All @@ -177,39 +177,58 @@ func MakeGoFunctionCommand(downloadPath, goExecFilePath string, function *v1alph
strings.Join(getProcessGoRuntimeArgs(goExecFilePath, function), " ")
if downloadPath != "" {
// prepend download command if the downPath is provided
downloadCommand := strings.Join(getDownloadCommand(downloadPath, goExecFilePath), " ")
downloadCommand := strings.Join(getDownloadCommand(downloadPath, goExecFilePath, function.Spec.Pulsar.AuthSecret != "", function.Spec.Pulsar.TLSSecret != ""), " ")
processCommand = downloadCommand + " && ls -al && pwd &&" + processCommand
}
return []string{"sh", "-c", processCommand}
}

func getDownloadCommand(downloadPath, componentPackage string) []string {
func getDownloadCommand(downloadPath, componentPackage string, authProvided, tlsProvided bool) []string {
// The download path is the path that the package saved in the pulsar.
// By default, it's the path that the package saved in the pulsar, we can use package name
// to replace it for downloading packages from packages management service.
args := []string{
PulsarAdminExecutableFile,
"--admin-url",
"$webServiceURL",
}
if authProvided {
args = append(args, []string{
"--auth-plugin",
"$clientAuthenticationPlugin",
"--auth-params",
"$clientAuthenticationParameters"}...)
}

if tlsProvided {
args = append(args, []string{
"--tls-allow-insecure",
"$tlsAllowInsecureConnection",
"--tls-enable-hostname-verification",
"$tlsHostnameVerificationEnable",
"--tls-trust-cert-path",
"$tlsTrustCertsFilePath",
}...)
}
if hasPackageNamePrefix(downloadPath) {
return []string{
PulsarAdminExecutableFile,
"--admin-url",
"$webServiceURL",
args = append(args, []string{
"packages",
"download",
downloadPath,
"--path",
componentPackage,
}
}...)
return args
}
return []string{
PulsarAdminExecutableFile, // TODO configurable pulsar ROOTDIR and adminCLI
"--admin-url",
"$webServiceURL",
args = append(args, []string{
"functions",
"download",
"--path",
downloadPath,
"--destination-file",
componentPackage,
}
}...)
return args
}

// TODO: do a more strict check for the package name https://github.com/streamnative/function-mesh/issues/49
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func TestGetDownloadCommand(t *testing.T) {
doTest := func(downloadPath, componentPackage string, expectedCommand []string) {
actualResult := getDownloadCommand(downloadPath, componentPackage)
actualResult := getDownloadCommand(downloadPath, componentPackage, false, false)
assert.Equal(t, expectedCommand, actualResult)
}

Expand Down