Skip to content

Commit 8795845

Browse files
feat: export DownloadServiceConfig and GeneratePythonLogConfigCommand (#835)
* feat: export DownloadServiceConfig and GeneratePythonLogConfigCommand * export more
1 parent 55d45ca commit 8795845

2 files changed

Lines changed: 40 additions & 40 deletions

File tree

controllers/spec/common.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -216,48 +216,48 @@ func prefixedDownloadCommandEnvNames(prefix string) downloadCommandEnvNames {
216216
}
217217
}
218218

219-
type downloadServiceConfig struct {
219+
type DownloadServiceConfig struct {
220220
pulsar *v1alpha1.PulsarMessaging
221221
envPrefix string
222-
envNames downloadCommandEnvNames
223-
oauth2Mount string
222+
EnvNames downloadCommandEnvNames
223+
Oauth2Mount string
224224
tlsMount string
225225
}
226226

227-
func NewDownloadServiceConfig(packageService, messaging *v1alpha1.PulsarMessaging) downloadServiceConfig {
227+
func NewDownloadServiceConfig(packageService, messaging *v1alpha1.PulsarMessaging) DownloadServiceConfig {
228228
if packageService != nil {
229-
return downloadServiceConfig{
229+
return DownloadServiceConfig{
230230
pulsar: packageService,
231231
envPrefix: PackageServiceEnvPrefix,
232-
envNames: prefixedDownloadCommandEnvNames(PackageServiceEnvPrefix),
233-
oauth2Mount: PackageOAuth2MountPath,
232+
EnvNames: prefixedDownloadCommandEnvNames(PackageServiceEnvPrefix),
233+
Oauth2Mount: PackageOAuth2MountPath,
234234
tlsMount: PackageTLSMountPath,
235235
}
236236
}
237-
return downloadServiceConfig{
237+
return DownloadServiceConfig{
238238
pulsar: messaging,
239-
envNames: defaultDownloadCommandEnvNames(),
240-
oauth2Mount: "",
239+
EnvNames: defaultDownloadCommandEnvNames(),
240+
Oauth2Mount: "",
241241
tlsMount: "",
242242
}
243243
}
244244

245-
func (d downloadServiceConfig) authProvided() bool {
245+
func (d DownloadServiceConfig) AuthProvided() bool {
246246
return d.pulsar != nil && d.pulsar.AuthSecret != ""
247247
}
248248

249-
func (d downloadServiceConfig) tlsProvided() bool {
249+
func (d DownloadServiceConfig) TLSProvided() bool {
250250
return d.pulsar != nil && d.pulsar.TLSSecret != ""
251251
}
252252

253-
func (d downloadServiceConfig) authConfig() *v1alpha1.AuthConfig {
253+
func (d DownloadServiceConfig) AuthConfig() *v1alpha1.AuthConfig {
254254
if d.pulsar == nil {
255255
return nil
256256
}
257257
return d.pulsar.AuthConfig
258258
}
259259

260-
func (d downloadServiceConfig) tlsConfig() TLSConfig {
260+
func (d DownloadServiceConfig) TLSConfig() TLSConfig {
261261
if d.pulsar == nil || d.pulsar.TLSConfig == nil {
262262
return nil
263263
}
@@ -270,7 +270,7 @@ func (d downloadServiceConfig) tlsConfig() TLSConfig {
270270
}
271271
}
272272

273-
func (d downloadServiceConfig) envFrom() []corev1.EnvFromSource {
273+
func (d DownloadServiceConfig) EnvFrom() []corev1.EnvFromSource {
274274
if d.pulsar == nil {
275275
return nil
276276
}
@@ -352,7 +352,7 @@ func MakeHeadlessServiceName(serviceName string) string {
352352

353353
func MakeStatefulSet(objectMeta *metav1.ObjectMeta, replicas *int32, downloaderImage string, container *corev1.Container,
354354
volumes []corev1.Volume, labels map[string]string, policy v1alpha1.PodPolicy, runtimeMessaging *v1alpha1.PulsarMessaging,
355-
downloadConfig downloadServiceConfig,
355+
downloadConfig DownloadServiceConfig,
356356
javaRuntime *v1alpha1.JavaRuntime,
357357
pythonRuntime *v1alpha1.PythonRuntime, goRuntime *v1alpha1.GoRuntime, env []corev1.EnvVar, logTopic, filebeatImage string,
358358
logTopicAgent v1alpha1.LogTopicAgent, definedVolumeMounts []corev1.VolumeMount, volumeClaimTemplates []corev1.PersistentVolumeClaim,
@@ -390,16 +390,16 @@ func MakeStatefulSet(objectMeta *metav1.ObjectMeta, replicas *int32, downloaderI
390390

391391
// mount auth and tls related VolumeMounts when download package from pulsar
392392
if !hasHTTPPrefix(downloadPath) {
393-
if authConfig := downloadConfig.authConfig(); authConfig != nil && authConfig.OAuth2Config != nil {
393+
if authConfig := downloadConfig.AuthConfig(); authConfig != nil && authConfig.OAuth2Config != nil {
394394
oauth2MountPath := authConfig.OAuth2Config.GetMountPath()
395-
if downloadConfig.oauth2Mount != "" {
396-
oauth2MountPath = downloadConfig.oauth2Mount
395+
if downloadConfig.Oauth2Mount != "" {
396+
oauth2MountPath = downloadConfig.Oauth2Mount
397397
}
398398
volumeMounts = appendVolumeMountIfNotExists(volumeMounts, generateVolumeMountFromOAuth2ConfigWithMountPath(authConfig.OAuth2Config, oauth2MountPath))
399399
podVolumes = appendVolumeIfNotExists(podVolumes, generateVolumeFromOAuth2Config(authConfig.OAuth2Config))
400400
}
401401

402-
tlsConfig := downloadConfig.tlsConfig()
402+
tlsConfig := downloadConfig.TLSConfig()
403403
if !isNilTLSConfig(tlsConfig) && tlsConfig.HasSecretVolume() {
404404
volumeMounts = appendVolumeMountIfNotExists(volumeMounts, generateVolumeMountFromTLSConfig(tlsConfig))
405405
podVolumes = appendVolumeIfNotExists(podVolumes, generateVolumeFromTLSConfig(tlsConfig))
@@ -419,15 +419,15 @@ func MakeStatefulSet(objectMeta *metav1.ObjectMeta, replicas *int32, downloaderI
419419
Image: image,
420420
Command: []string{"sh", "-c",
421421
strings.Join(GetDownloadCommandWithEnv(downloadPath, componentPackage, true, true,
422-
downloadConfig.authProvided(), downloadConfig.tlsProvided(), downloadConfig.tlsConfig(),
423-
downloadConfig.authConfig(), downloadConfig.envNames, downloadConfig.oauth2Mount), " ")},
422+
downloadConfig.AuthProvided(), downloadConfig.TLSProvided(), downloadConfig.TLSConfig(),
423+
downloadConfig.AuthConfig(), downloadConfig.EnvNames, downloadConfig.Oauth2Mount), " ")},
424424
VolumeMounts: volumeMounts,
425425
ImagePullPolicy: corev1.PullIfNotPresent,
426426
Env: []corev1.EnvVar{{
427427
Name: "HOME",
428428
Value: "/tmp",
429429
}},
430-
EnvFrom: downloadConfig.envFrom(),
430+
EnvFrom: downloadConfig.EnvFrom(),
431431
}
432432
podVolumes = appendVolumeIfNotExists(podVolumes, corev1.Volume{
433433
Name: DownloaderVolume,
@@ -670,7 +670,7 @@ func GenerateAffinity(affinity *corev1.Affinity, labels map[string]string, disab
670670
}
671671

672672
func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, logLevel, details, extraDependenciesDir, connectorsDirectory, uid string,
673-
memory *resource.Quantity, javaOpts []string, hasPulsarctl, hasWget bool, downloadConfig downloadServiceConfig,
673+
memory *resource.Quantity, javaOpts []string, hasPulsarctl, hasWget bool, downloadConfig DownloadServiceConfig,
674674
authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
675675
state *v1alpha1.Stateful,
676676
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig,
@@ -682,15 +682,15 @@ func MakeJavaFunctionCommand(downloadPath, packageFile, name, clusterName, gener
682682
if downloadPath != "" && !utils.EnableInitContainers {
683683
// prepend download command if the downPath is provided
684684
downloadCommand := strings.Join(GetDownloadCommandWithEnv(downloadPath, packageFile, hasPulsarctl, hasWget,
685-
downloadConfig.authProvided(), downloadConfig.tlsProvided(), downloadConfig.tlsConfig(),
686-
downloadConfig.authConfig(), downloadConfig.envNames, downloadConfig.oauth2Mount), " ")
685+
downloadConfig.AuthProvided(), downloadConfig.TLSProvided(), downloadConfig.TLSConfig(),
686+
downloadConfig.AuthConfig(), downloadConfig.EnvNames, downloadConfig.Oauth2Mount), " ")
687687
processCommand = downloadCommand + " && " + processCommand
688688
}
689689
return []string{"bash", "-c", processCommand}
690690
}
691691

692692
func MakePythonFunctionCommand(downloadPath, packageFile, name, clusterName, generateLogConfigCommand, details, uid string,
693-
hasPulsarctl, hasWget bool, downloadConfig downloadServiceConfig, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
693+
hasPulsarctl, hasWget bool, downloadConfig DownloadServiceConfig, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
694694
state *v1alpha1.Stateful,
695695
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig) []string {
696696
processCommand := setShardIDEnvironmentVariableCommand() + " && " + generateLogConfigCommand +
@@ -699,15 +699,15 @@ func MakePythonFunctionCommand(downloadPath, packageFile, name, clusterName, gen
699699
if downloadPath != "" && !utils.EnableInitContainers {
700700
// prepend download command if the downPath is provided
701701
downloadCommand := strings.Join(GetDownloadCommandWithEnv(downloadPath, packageFile, hasPulsarctl, hasWget,
702-
downloadConfig.authProvided(),
703-
downloadConfig.tlsProvided(), downloadConfig.tlsConfig(), downloadConfig.authConfig(),
704-
downloadConfig.envNames, downloadConfig.oauth2Mount), " ")
702+
downloadConfig.AuthProvided(),
703+
downloadConfig.TLSProvided(), downloadConfig.TLSConfig(), downloadConfig.AuthConfig(),
704+
downloadConfig.EnvNames, downloadConfig.Oauth2Mount), " ")
705705
processCommand = downloadCommand + " && " + processCommand
706706
}
707707
return []string{"bash", "-c", processCommand}
708708
}
709709

710-
func MakeGoFunctionCommand(downloadPath, goExecFilePath string, function *v1alpha1.Function, downloadConfig downloadServiceConfig) []string {
710+
func MakeGoFunctionCommand(downloadPath, goExecFilePath string, function *v1alpha1.Function, downloadConfig DownloadServiceConfig) []string {
711711
processCommand := setShardIDEnvironmentVariableCommand() + " && " +
712712
strings.Join(getProcessGoRuntimeArgs(goExecFilePath, function), " ")
713713
if downloadPath != "" && !utils.EnableInitContainers {
@@ -719,15 +719,15 @@ func MakeGoFunctionCommand(downloadPath, goExecFilePath string, function *v1alph
719719
hasWget = true
720720
}
721721
downloadCommand := strings.Join(GetDownloadCommandWithEnv(downloadPath, goExecFilePath,
722-
hasPulsarctl, hasWget, downloadConfig.authProvided(),
723-
downloadConfig.tlsProvided(), downloadConfig.tlsConfig(), downloadConfig.authConfig(),
724-
downloadConfig.envNames, downloadConfig.oauth2Mount), " ")
722+
hasPulsarctl, hasWget, downloadConfig.AuthProvided(),
723+
downloadConfig.TLSProvided(), downloadConfig.TLSConfig(), downloadConfig.AuthConfig(),
724+
downloadConfig.EnvNames, downloadConfig.Oauth2Mount), " ")
725725
processCommand = downloadCommand + " && ls -al && pwd &&" + processCommand
726726
}
727727
return []string{"bash", "-c", processCommand}
728728
}
729729

730-
func MakeGenericFunctionCommand(downloadPath, functionFile, language, clusterName, details, uid string, downloadConfig downloadServiceConfig, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
730+
func MakeGenericFunctionCommand(downloadPath, functionFile, language, clusterName, details, uid string, downloadConfig DownloadServiceConfig, authProvided, tlsProvided bool, secretMaps map[string]v1alpha1.SecretRef,
731731
state *v1alpha1.Stateful,
732732
tlsConfig TLSConfig, authConfig *v1alpha1.AuthConfig) []string {
733733
processCommand := setShardIDEnvironmentVariableCommand() + " && " +
@@ -736,9 +736,9 @@ func MakeGenericFunctionCommand(downloadPath, functionFile, language, clusterNam
736736
if downloadPath != "" && !utils.EnableInitContainers {
737737
// prepend download command if the downPath is provided
738738
downloadCommand := strings.Join(GetDownloadCommandWithEnv(downloadPath, functionFile, true, true,
739-
downloadConfig.authProvided(),
740-
downloadConfig.tlsProvided(), downloadConfig.tlsConfig(), downloadConfig.authConfig(),
741-
downloadConfig.envNames, downloadConfig.oauth2Mount), " ")
739+
downloadConfig.AuthProvided(),
740+
downloadConfig.TLSProvided(), downloadConfig.TLSConfig(), downloadConfig.AuthConfig(),
741+
downloadConfig.EnvNames, downloadConfig.Oauth2Mount), " ")
742742
processCommand = downloadCommand + " && " + processCommand
743743
}
744744
return []string{"sh", "-c", processCommand}
@@ -1278,7 +1278,7 @@ func renderJavaInstanceLog4jXMLTemplate(runtime *v1alpha1.JavaRuntime, agent v1a
12781278
return tpl.String(), nil
12791279
}
12801280

1281-
func generatePythonLogConfigCommand(name string, runtime *v1alpha1.PythonRuntime, agent v1alpha1.LogTopicAgent) string {
1281+
func GeneratePythonLogConfigCommand(name string, runtime *v1alpha1.PythonRuntime, agent v1alpha1.LogTopicAgent) string {
12821282
commands := "sed -i.bak 's/^ Log.setLevel/#&/' /pulsar/instances/python-instance/log.py && "
12831283
if runtime == nil || (runtime.Log != nil && runtime.Log.LogConfig != nil) {
12841284
return commands

controllers/spec/function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func makeFunctionCommand(function *v1alpha1.Function) []string {
273273
mountPath := extractMountPath(spec.Python.Py)
274274
return MakePythonFunctionCommand(spec.Python.PyLocation, mountPath,
275275
spec.Name, spec.ClusterName,
276-
generatePythonLogConfigCommand(spec.Name, spec.Python, spec.LogTopicAgent),
276+
GeneratePythonLogConfigCommand(spec.Name, spec.Python, spec.LogTopicAgent),
277277
generateFunctionDetailsInJSON(function), string(function.UID), hasPulsarctl, hasWget, downloadConfig,
278278
spec.Pulsar.AuthSecret != "", spec.Pulsar.TLSSecret != "", spec.SecretsMap,
279279
spec.StateConfig, spec.Pulsar.TLSConfig, spec.Pulsar.AuthConfig)

0 commit comments

Comments
 (0)