diff --git a/example/framework/basic/batchstatefulfailed.yaml b/example/framework/basic/batchstatefulfailed.yaml index 58a75720..054b6e88 100644 --- a/example/framework/basic/batchstatefulfailed.yaml +++ b/example/framework/basic/batchstatefulfailed.yaml @@ -27,18 +27,19 @@ spec: # To locate a specific Task during its whole lifecycle regardless of # any retry: # Consistent Identity: - # PodName = {FrameworkName}-{TaskRoleName}-{TaskIndex} # PodNamespace = {FrameworkNamespace} + # PodName = {FrameworkName}-{TaskRoleName}-{TaskIndex} # Consistent Environment Variable Value: - # ${FRAMEWORK_NAME}, ${TASKROLE_NAME}, ${TASK_INDEX} - # ${CONFIGMAP_NAME}, ${POD_NAME}, ${POD_NAMESPACE} + # ${FC_FRAMEWORK_NAMESPACE}, + # ${FC_FRAMEWORK_NAME}, ${FC_TASKROLE_NAME}, ${FC_TASK_INDEX}, + # ${FC_CONFIGMAP_NAME}, ${FC_POD_NAME} # # To locate a specific execution attempt of a specific Task: # Attempt Specific Environment Variable Value: - # ${FRAMEWORK_ATTEMPT_ID}, ${TASK_ATTEMPT_ID} + # ${FC_FRAMEWORK_ATTEMPT_ID}, ${FC_TASK_ATTEMPT_ID} # # To locate a specific execution attempt instance of a specific Task: # Attempt Instance Specific Environment Variable Value: - # ${FRAMEWORK_ATTEMPT_INSTANCE_UID}, ${CONFIGMAP_UID} - # ${TASK_ATTEMPT_INSTANCE_UID}, ${POD_UID} + # ${FC_FRAMEWORK_ATTEMPT_INSTANCE_UID}, ${FC_CONFIGMAP_UID} + # ${FC_TASK_ATTEMPT_INSTANCE_UID}, ${FC_POD_UID} command: ["sh", "-c", "printenv && sleep 60 && exit 1"] diff --git a/example/framework/basic/service.yaml b/example/framework/basic/service.yaml index ac66660d..68326276 100644 --- a/example/framework/basic/service.yaml +++ b/example/framework/basic/service.yaml @@ -38,8 +38,8 @@ metadata: spec: selector: # Using predefined labels - FRAMEWORK_NAME: service - TASKROLE_NAME: server + FC_FRAMEWORK_NAME: service + FC_TASKROLE_NAME: server # Also can use customized labels #app: server ports: diff --git a/example/framework/basic/servicestateful.yaml b/example/framework/basic/servicestateful.yaml index b883d297..8ad4ac32 100644 --- a/example/framework/basic/servicestateful.yaml +++ b/example/framework/basic/servicestateful.yaml @@ -43,8 +43,8 @@ metadata: spec: selector: # See comments in service.yaml - FRAMEWORK_NAME: servicestateful - TASKROLE_NAME: serverstateful + FC_FRAMEWORK_NAME: servicestateful + FC_TASKROLE_NAME: serverstateful ports: - port: 80 type: NodePort diff --git a/example/framework/extension/frameworkbarrier.yaml b/example/framework/extension/frameworkbarrier.yaml index a4980e88..b1cb6eeb 100644 --- a/example/framework/extension/frameworkbarrier.yaml +++ b/example/framework/extension/frameworkbarrier.yaml @@ -29,15 +29,15 @@ spec: containers: - name: ubuntu image: ubuntu:trusty - # Using /mnt/frameworkbarrier/injector.sh to inject environment - # variables, such as: - # {TaskRoleName}_ips= + # Using /mnt/frameworkbarrier/injector.sh to inject environment variables, + # such as: + # FB_{UpperCase({TaskRoleName})}_IPS= # {Task[0].PodIP},..., # {Task[TaskRole.TaskNumber-1].PodIP} - # {TaskRoleName}_addresses= - # {Task[0].PodIP}:${{TaskRoleName}_port},..., - # {Task[TaskRole.TaskNumber-1].PodIP}:${{TaskRoleName}_port} - # Note, the environment variable {TaskRoleName}_port should be + # FB_{UpperCase({TaskRoleName})}_ADDRESSES= + # {Task[0].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT},..., + # {Task[TaskRole.TaskNumber-1].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT} + # Note, the environment variable FB_{UpperCase({TaskRoleName})}_PORT should be # provided by the caller in advance. # # User may need to tweak these environment variables to its own @@ -48,8 +48,8 @@ spec: # /mnt/frameworkbarrier/framework.json. command: [ "sh", "-c", - "server_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && printenv && - server_port=4002 worker_port=5002 . /mnt/frameworkbarrier/injector.sh && printenv && + "FB_SERVER_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && printenv && + FB_SERVER_PORT=4002 FB_WORKER_PORT=5002 . /mnt/frameworkbarrier/injector.sh && printenv && sleep 60"] ports: - containerPort: 4001 @@ -104,8 +104,8 @@ spec: image: ubuntu:trusty command: [ "sh", "-c", - "server_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && printenv && - server_port=4002 worker_port=5002 . /mnt/frameworkbarrier/injector.sh && printenv && + "FB_SERVER_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && printenv && + FB_SERVER_PORT=4002 FB_WORKER_PORT=5002 . /mnt/frameworkbarrier/injector.sh && printenv && sleep 60"] ports: - containerPort: 5001 diff --git a/example/framework/scenario/tensorflow/cpu/tensorflowdistributedtrainingwithcpu.yaml b/example/framework/scenario/tensorflow/cpu/tensorflowdistributedtrainingwithcpu.yaml index 9ec33811..2aff55ef 100644 --- a/example/framework/scenario/tensorflow/cpu/tensorflowdistributedtrainingwithcpu.yaml +++ b/example/framework/scenario/tensorflow/cpu/tensorflowdistributedtrainingwithcpu.yaml @@ -43,22 +43,22 @@ spec: # For the tf_cnn_benchmarks usage, see # https://github.com/tensorflow/benchmarks/tree/master/scripts/tf_cnn_benchmarks workingDir: /tensorflow/benchmarks/scripts/tf_cnn_benchmarks - # Using /mnt/frameworkbarrier/injector.sh to inject environment - # variables without the need for image invasion and k8s DNS: - # {TaskRoleName}_addresses= - # {Task[0].PodIP}:${{TaskRoleName}_port},..., - # {Task[TaskRole.TaskNumber-1].PodIP}:${{TaskRoleName}_port} + # Using /mnt/frameworkbarrier/injector.sh to inject environment variables + # without the need for image invasion and k8s DNS: + # FB_{UpperCase({TaskRoleName})}_ADDRESSES= + # {Task[0].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT},..., + # {Task[TaskRole.TaskNumber-1].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT} # See more in ./example/framework/extension/frameworkbarrier.yaml command: [ "sh", "-c", - "ps_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && - python tf_cnn_benchmarks.py --job_name=ps --task_index=${TASK_INDEX} - --ps_hosts=${ps_addresses} --worker_hosts=${worker_addresses} + "FB_PS_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && + python tf_cnn_benchmarks.py --job_name=ps --task_index=${FC_TASK_INDEX} + --ps_hosts=${FB_PS_ADDRESSES} --worker_hosts=${FB_WORKER_ADDRESSES} --variable_update=parameter_server --cross_replica_sync=false --model=alexnet --batch_size=8 --num_batches=10 --device=cpu --local_parameter_device=cpu --data_format=NHWC --data_name=cifar10 --data_dir=/mnt/data/cifar-10-batches-py - --train_dir=/mnt/data/${FRAMEWORK_NAME}/output"] + --train_dir=/mnt/data/${FC_FRAMEWORK_NAME}/output"] ports: - containerPort: 4001 volumeMounts: @@ -129,14 +129,14 @@ spec: workingDir: /tensorflow/benchmarks/scripts/tf_cnn_benchmarks command: [ "sh", "-c", - "ps_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && - python tf_cnn_benchmarks.py --job_name=worker --task_index=${TASK_INDEX} - --ps_hosts=${ps_addresses} --worker_hosts=${worker_addresses} + "FB_PS_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && + python tf_cnn_benchmarks.py --job_name=worker --task_index=${FC_TASK_INDEX} + --ps_hosts=${FB_PS_ADDRESSES} --worker_hosts=${FB_WORKER_ADDRESSES} --variable_update=parameter_server --cross_replica_sync=false --model=alexnet --batch_size=8 --num_batches=10 --device=cpu --local_parameter_device=cpu --data_format=NHWC --data_name=cifar10 --data_dir=/mnt/data/cifar-10-batches-py - --train_dir=/mnt/data/${FRAMEWORK_NAME}/output"] + --train_dir=/mnt/data/${FC_FRAMEWORK_NAME}/output"] ports: - containerPort: 5001 volumeMounts: diff --git a/example/framework/scenario/tensorflow/gpu/tensorflowdistributedtrainingwithgpu.yaml b/example/framework/scenario/tensorflow/gpu/tensorflowdistributedtrainingwithgpu.yaml index 1d6bdde2..ef4ccc12 100644 --- a/example/framework/scenario/tensorflow/gpu/tensorflowdistributedtrainingwithgpu.yaml +++ b/example/framework/scenario/tensorflow/gpu/tensorflowdistributedtrainingwithgpu.yaml @@ -43,22 +43,22 @@ spec: # For the tf_cnn_benchmarks usage, see # https://github.com/tensorflow/benchmarks/tree/master/scripts/tf_cnn_benchmarks workingDir: /tensorflow/benchmarks/scripts/tf_cnn_benchmarks - # Using /mnt/frameworkbarrier/injector.sh to inject environment - # variables without the need for image invasion and k8s DNS: - # {TaskRoleName}_addresses= - # {Task[0].PodIP}:${{TaskRoleName}_port},..., - # {Task[TaskRole.TaskNumber-1].PodIP}:${{TaskRoleName}_port} + # Using /mnt/frameworkbarrier/injector.sh to inject environment variables + # without the need for image invasion and k8s DNS: + # FB_{UpperCase({TaskRoleName})}_ADDRESSES= + # {Task[0].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT},..., + # {Task[TaskRole.TaskNumber-1].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT} # See more in ./example/framework/extension/frameworkbarrier.yaml command: [ "sh", "-c", - "ps_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && - python tf_cnn_benchmarks.py --job_name=ps --task_index=${TASK_INDEX} - --ps_hosts=${ps_addresses} --worker_hosts=${worker_addresses} + "FB_PS_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && + python tf_cnn_benchmarks.py --job_name=ps --task_index=${FC_TASK_INDEX} + --ps_hosts=${FB_PS_ADDRESSES} --worker_hosts=${FB_WORKER_ADDRESSES} --variable_update=parameter_server --cross_replica_sync=false --model=alexnet --batch_size=8 --num_batches=10 --device=gpu --local_parameter_device=gpu --num_gpus=1 --data_format=NCHW --data_name=cifar10 --data_dir=/mnt/data/cifar-10-batches-py - --train_dir=/mnt/data/${FRAMEWORK_NAME}/output"] + --train_dir=/mnt/data/${FC_FRAMEWORK_NAME}/output"] ports: - containerPort: 4001 resources: @@ -135,14 +135,14 @@ spec: workingDir: /tensorflow/benchmarks/scripts/tf_cnn_benchmarks command: [ "sh", "-c", - "ps_port=4001 worker_port=5001 . /mnt/frameworkbarrier/injector.sh && - python tf_cnn_benchmarks.py --job_name=worker --task_index=${TASK_INDEX} - --ps_hosts=${ps_addresses} --worker_hosts=${worker_addresses} + "FB_PS_PORT=4001 FB_WORKER_PORT=5001 . /mnt/frameworkbarrier/injector.sh && + python tf_cnn_benchmarks.py --job_name=worker --task_index=${FC_TASK_INDEX} + --ps_hosts=${FB_PS_ADDRESSES} --worker_hosts=${FB_WORKER_ADDRESSES} --variable_update=parameter_server --cross_replica_sync=false --model=alexnet --batch_size=8 --num_batches=10 --device=gpu --local_parameter_device=gpu --num_gpus=1 --data_format=NCHW --data_name=cifar10 --data_dir=/mnt/data/cifar-10-batches-py - --train_dir=/mnt/data/${FRAMEWORK_NAME}/output"] + --train_dir=/mnt/data/${FC_FRAMEWORK_NAME}/output"] ports: - containerPort: 5001 resources: diff --git a/pkg/apis/frameworkcontroller/v1/constants.go b/pkg/apis/frameworkcontroller/v1/constants.go index e6fd1946..a033907c 100644 --- a/pkg/apis/frameworkcontroller/v1/constants.go +++ b/pkg/apis/frameworkcontroller/v1/constants.go @@ -46,35 +46,40 @@ const ( ExtendedUnlimitedValue = -2 // For all managed objects - AnnotationKeyFrameworkName = "FRAMEWORK_NAME" - AnnotationKeyTaskRoleName = "TASKROLE_NAME" - AnnotationKeyTaskIndex = "TASK_INDEX" - AnnotationKeyConfigMapName = "CONFIGMAP_NAME" - AnnotationKeyPodName = "POD_NAME" - AnnotationKeyPodNamespace = "POD_NAMESPACE" - - AnnotationKeyFrameworkAttemptID = "FRAMEWORK_ATTEMPT_ID" - AnnotationKeyFrameworkAttemptInstanceUID = "FRAMEWORK_ATTEMPT_INSTANCE_UID" - AnnotationKeyConfigMapUID = "CONFIGMAP_UID" - AnnotationKeyTaskAttemptID = "TASK_ATTEMPT_ID" - + // Predefined Annotations + AnnotationKeyFrameworkNamespace = "FC_FRAMEWORK_NAMESPACE" + AnnotationKeyFrameworkName = "FC_FRAMEWORK_NAME" + AnnotationKeyTaskRoleName = "FC_TASKROLE_NAME" + AnnotationKeyTaskIndex = "FC_TASK_INDEX" + AnnotationKeyConfigMapName = "FC_CONFIGMAP_NAME" + AnnotationKeyPodName = "FC_POD_NAME" + + AnnotationKeyFrameworkAttemptID = "FC_FRAMEWORK_ATTEMPT_ID" + AnnotationKeyFrameworkAttemptInstanceUID = "FC_FRAMEWORK_ATTEMPT_INSTANCE_UID" + AnnotationKeyConfigMapUID = "FC_CONFIGMAP_UID" + AnnotationKeyTaskAttemptID = "FC_TASK_ATTEMPT_ID" + + // Predefined Labels LabelKeyFrameworkName = AnnotationKeyFrameworkName LabelKeyTaskRoleName = AnnotationKeyTaskRoleName // For all managed containers - EnvNameFrameworkName = AnnotationKeyFrameworkName - EnvNameTaskRoleName = AnnotationKeyTaskRoleName - EnvNameTaskIndex = AnnotationKeyTaskIndex - EnvNameConfigMapName = AnnotationKeyConfigMapName - EnvNamePodName = AnnotationKeyPodName - EnvNamePodNamespace = AnnotationKeyPodNamespace + // Predefined Environment Variables + // It can be referred by the environment variable specified in the spec, i.e. + // specify the environment variable value to include "$(AnyPredefinedEnvName)". + EnvNameFrameworkNamespace = AnnotationKeyFrameworkNamespace + EnvNameFrameworkName = AnnotationKeyFrameworkName + EnvNameTaskRoleName = AnnotationKeyTaskRoleName + EnvNameTaskIndex = AnnotationKeyTaskIndex + EnvNameConfigMapName = AnnotationKeyConfigMapName + EnvNamePodName = AnnotationKeyPodName EnvNameFrameworkAttemptID = AnnotationKeyFrameworkAttemptID EnvNameFrameworkAttemptInstanceUID = AnnotationKeyFrameworkAttemptInstanceUID EnvNameConfigMapUID = AnnotationKeyConfigMapUID EnvNameTaskAttemptID = AnnotationKeyTaskAttemptID - EnvNameTaskAttemptInstanceUID = "TASK_ATTEMPT_INSTANCE_UID" - EnvNamePodUID = "POD_UID" + EnvNameTaskAttemptInstanceUID = "FC_TASK_ATTEMPT_INSTANCE_UID" + EnvNamePodUID = "FC_POD_UID" ) var FrameworkGroupVersionKind = SchemeGroupVersion.WithKind(FrameworkKind) diff --git a/pkg/apis/frameworkcontroller/v1/funcs.go b/pkg/apis/frameworkcontroller/v1/funcs.go index 36948641..be21a45e 100644 --- a/pkg/apis/frameworkcontroller/v1/funcs.go +++ b/pkg/apis/frameworkcontroller/v1/funcs.go @@ -261,6 +261,7 @@ func (f *Framework) NewConfigMap() *core.ConfigMap { cm.Finalizers = []string{meta.FinalizerDeleteDependents} cm.Annotations = map[string]string{} + cm.Annotations[AnnotationKeyFrameworkNamespace] = f.Namespace cm.Annotations[AnnotationKeyFrameworkName] = f.Name cm.Annotations[AnnotationKeyConfigMapName] = cm.Name cm.Annotations[AnnotationKeyFrameworkAttemptID] = frameworkAttemptIDStr @@ -305,12 +306,12 @@ func (f *Framework) NewPod(cm *core.ConfigMap, taskRoleName string, taskIndex in if pod.Annotations == nil { pod.Annotations = map[string]string{} } + pod.Annotations[AnnotationKeyFrameworkNamespace] = f.Namespace pod.Annotations[AnnotationKeyFrameworkName] = f.Name pod.Annotations[AnnotationKeyTaskRoleName] = taskRoleName pod.Annotations[AnnotationKeyTaskIndex] = taskIndexStr pod.Annotations[AnnotationKeyConfigMapName] = f.ConfigMapName() pod.Annotations[AnnotationKeyPodName] = pod.Name - pod.Annotations[AnnotationKeyPodNamespace] = pod.Namespace pod.Annotations[AnnotationKeyFrameworkAttemptID] = frameworkAttemptIDStr pod.Annotations[AnnotationKeyFrameworkAttemptInstanceUID] = frameworkAttemptInstanceUIDStr pod.Annotations[AnnotationKeyConfigMapUID] = configMapUIDStr @@ -322,13 +323,13 @@ func (f *Framework) NewPod(cm *core.ConfigMap, taskRoleName string, taskIndex in pod.Labels[LabelKeyFrameworkName] = f.Name pod.Labels[LabelKeyTaskRoleName] = taskRoleName - exEnvs := []core.EnvVar{ + predefinedEnvs := []core.EnvVar{ + {Name: EnvNameFrameworkNamespace, Value: f.Namespace}, {Name: EnvNameFrameworkName, Value: f.Name}, {Name: EnvNameTaskRoleName, Value: taskRoleName}, {Name: EnvNameTaskIndex, Value: taskIndexStr}, {Name: EnvNameConfigMapName, Value: f.ConfigMapName()}, {Name: EnvNamePodName, Value: pod.Name}, - {Name: EnvNamePodNamespace, Value: pod.Namespace}, {Name: EnvNameFrameworkAttemptID, Value: frameworkAttemptIDStr}, {Name: EnvNameFrameworkAttemptInstanceUID, Value: frameworkAttemptInstanceUIDStr}, {Name: EnvNameConfigMapUID, Value: configMapUIDStr}, @@ -337,6 +338,8 @@ func (f *Framework) NewPod(cm *core.ConfigMap, taskRoleName string, taskIndex in {Name: EnvNameTaskAttemptInstanceUID, Value: taskAttemptInstanceUIDReferStr}, } + // Prepend predefinedEnvs so that they can be referred by the environment variable + // specified in the spec. // Change the default TerminationMessagePolicy to TerminationMessageFallbackToLogsOnError // in case the cluster-level logging has not been setup for the cluster. // See https://kubernetes.io/docs/concepts/cluster-administration/logging @@ -344,17 +347,13 @@ func (f *Framework) NewPod(cm *core.ConfigMap, taskRoleName string, taskIndex in // is failed and the termination message file specified by the terminationMessagePath // is not found or empty. for i := range pod.Spec.Containers { - for _, exEnv := range exEnvs { - pod.Spec.Containers[i].Env = append(pod.Spec.Containers[i].Env, exEnv) - } + pod.Spec.Containers[i].Env = append(predefinedEnvs, pod.Spec.Containers[i].Env...) if len(pod.Spec.Containers[i].TerminationMessagePolicy) == 0 { pod.Spec.Containers[i].TerminationMessagePolicy = core.TerminationMessageFallbackToLogsOnError } } for i := range pod.Spec.InitContainers { - for _, exEnv := range exEnvs { - pod.Spec.InitContainers[i].Env = append(pod.Spec.InitContainers[i].Env, exEnv) - } + pod.Spec.InitContainers[i].Env = append(predefinedEnvs, pod.Spec.InitContainers[i].Env...) if len(pod.Spec.InitContainers[i].TerminationMessagePolicy) == 0 { pod.Spec.InitContainers[i].TerminationMessagePolicy = core.TerminationMessageFallbackToLogsOnError } diff --git a/pkg/barrier/barrier.go b/pkg/barrier/barrier.go index b9591c55..f214b314 100644 --- a/pkg/barrier/barrier.go +++ b/pkg/barrier/barrier.go @@ -66,14 +66,14 @@ import ( // // ./injector.sh exports below environment variables: // For each {TaskRoleName} in the Framework: -// {TaskRoleName}_ips= +// FB_{UpperCase({TaskRoleName})}_IPS= // {Task[0].PodIP},..., // {Task[TaskRole.TaskNumber-1].PodIP} -// {TaskRoleName}_addresses= -// {Task[0].PodIP}:${{TaskRoleName}_port},..., -// {Task[TaskRole.TaskNumber-1].PodIP}:${{TaskRoleName}_port} -// Note, the environment variable {TaskRoleName}_port should be provided by -// the caller in advance. +// FB_{UpperCase({TaskRoleName})}_ADDRESSES= +// {Task[0].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT},..., +// {Task[TaskRole.TaskNumber-1].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT} +// Note, the environment variable FB_{UpperCase({TaskRoleName})}_PORT should be +// provided by the caller in advance. // // Caller can also write its own injector script to inject other Framework // information from the ./framework.json. @@ -103,7 +103,7 @@ const ( type Config struct { // See the same fields in pkg/apis/frameworkcontroller/v1/config.go KubeApiServerAddress string `yaml:"kubeApiServerAddress"` - KubeConfigFilePath string `yaml:"kubeConfigFilePath"` + KubeConfigFilePath string `yaml:"kubeConfigFilePath"` // The Framework for which the barrier waits. FrameworkNamespace string `yaml:"frameworkNamespace"` @@ -125,7 +125,7 @@ func newConfig() *Config { } else { c.KubeConfigFilePath = ci.EnvValueKubeConfigFilePath } - c.FrameworkNamespace = os.Getenv(ci.EnvNamePodNamespace) + c.FrameworkNamespace = os.Getenv(ci.EnvNameFrameworkNamespace) c.FrameworkName = os.Getenv(ci.EnvNameFrameworkName) barrierCheckIntervalSecStr := os.Getenv(EnvNameBarrierCheckIntervalSec) @@ -327,6 +327,10 @@ func dumpFramework(f *ci.Framework) { FrameworkObjectFilePath) } +func getTaskRoleEnvName(taskRoleName string, suffix string) string { + return strings.Join([]string{"FB", strings.ToUpper(taskRoleName), suffix}, "_") +} + func generateInjector(f *ci.Framework) { var injector strings.Builder injector.WriteString("#!/bin/bash") @@ -338,14 +342,14 @@ func generateInjector(f *ci.Framework) { "echo " + InjectorFilePath + ": Start to inject environment variables") injector.WriteString("\n") - // {TaskRoleName}_ips= + // FB_{UpperCase({TaskRoleName})}_IPS= // {Task[0].PodIP},..., // {Task[TaskRole.TaskNumber-1].PodIP} injector.WriteString("\n") for _, taskRoleStatus := range f.TaskRoleStatuses() { - taskRoleName := taskRoleStatus.Name - injector.WriteString("export " + taskRoleName + "_ips=") + ipsEnvName := getTaskRoleEnvName(taskRoleStatus.Name, "IPS") + injector.WriteString("export " + ipsEnvName + "=") for _, taskStatus := range taskRoleStatus.TaskStatuses { taskIndex := taskStatus.Index if taskIndex > 0 { @@ -354,34 +358,30 @@ func generateInjector(f *ci.Framework) { taskIP := *taskStatus.AttemptStatus.PodIP injector.WriteString(taskIP) } - injector.WriteString("\n") - injector.WriteString( - "echo " + taskRoleName + "_ips=${" + taskRoleName + "_ips}") + injector.WriteString("echo " + ipsEnvName + "=${" + ipsEnvName + "}") injector.WriteString("\n") } - // {TaskRoleName}_addresses= - // {Task[0].PodIP}:${{TaskRoleName}_port},..., - // {Task[TaskRole.TaskNumber-1].PodIP}:${{TaskRoleName}_port} + // FB_{UpperCase({TaskRoleName})}_ADDRESSES= + // {Task[0].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT},..., + // {Task[TaskRole.TaskNumber-1].PodIP}:${FB_{UpperCase({TaskRoleName})}_PORT} injector.WriteString("\n") for _, taskRoleStatus := range f.TaskRoleStatuses() { - taskRoleName := taskRoleStatus.Name - injector.WriteString("export " + taskRoleName + "_addresses=") + addrsEnvName := getTaskRoleEnvName(taskRoleStatus.Name, "ADDRESSES") + portEnvName := getTaskRoleEnvName(taskRoleStatus.Name, "PORT") + injector.WriteString("export " + addrsEnvName + "=") for _, taskStatus := range taskRoleStatus.TaskStatuses { taskIndex := taskStatus.Index if taskIndex > 0 { injector.WriteString(",") } - taskAddr := *taskStatus.AttemptStatus.PodIP + - ":" + "${" + taskRoleName + "_port}" + taskAddr := *taskStatus.AttemptStatus.PodIP + ":" + "${" + portEnvName + "}" injector.WriteString(taskAddr) } - injector.WriteString("\n") - injector.WriteString( - "echo " + taskRoleName + "_addresses=${" + taskRoleName + "_addresses}") + injector.WriteString("echo " + addrsEnvName + "=${" + addrsEnvName + "}") injector.WriteString("\n") }