Skip to content

Commit 737cfc9

Browse files
authored
[OCTRL-1091] OCC_CONTROL_PORT removal from TaskTemplate CRDs (#841)
[control-operator] Remove OCC_CONTROL_PORT as requirement from TaskTemplate The reason for the removal is that ECS can assign OCC_CONTROL_PORT only for mesos tasks, thus the removal here. The variable is now set inside the TaskTemplates. Ability to overwrite EnvVars from TaskReference CRDs was also added
1 parent 4ada65d commit 737cfc9

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

control-operator/ecs-manifests/task-templates/readout-tasktemplate.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
- name: readout
2121
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/readout:1
2222
command: ["/opt/o2/bin/o2-readout-exe"]
23+
env:
24+
- name: OCC_CONTROL_PORT
25+
value: "47101"
2326
securityContext:
2427
privileged: true
2528
runAsUser: 1100

control-operator/ecs-manifests/task-templates/stfbuilder-senderoutput-tasktemplate.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ spec:
2222
- name: stfbuilder
2323
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/dd:1
2424
command: [/opt/o2/bin/StfBuilder]
25+
env:
26+
- name: OCC_CONTROL_PORT
27+
value: "47102"
2528
securityContext:
2629
privileged: true
2730
runAsUser: 1100

control-operator/ecs-manifests/task-templates/stfsender-tasktemplate.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
- name: stfsender
3030
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/dd:1
3131
command: ["numactl"]
32+
env:
33+
- name: OCC_CONTROL_PORT
34+
value: "47103"
3235
securityContext:
3336
privileged: true
3437
runAsUser: 1100

control-operator/internal/controller/environment_controller.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,11 @@ func (r *EnvironmentReconciler) runTasksFromReferenceOnNode(ctx context.Context,
8383
task.Spec.Pod = *template.Spec.Pod.DeepCopy()
8484
task.Spec.Control = *template.Spec.Control.DeepCopy()
8585

86-
// TODO: regarding error handling. Is it correct to stop while handling one task? this will fail the whole deployment,
87-
// which might not be desirable outcome especially for non-critical tasks
88-
if foundIdx := slices.IndexFunc(taskReference.Env, func(envVar v1.EnvVar) bool { return envVar.Name == "OCC_CONTROL_PORT" }); foundIdx == -1 {
89-
log.Error(fmt.Errorf("didn't find OCC_CONTROL_PORT in env"), "failed to fill in env vars from template")
90-
return &reconcile.Result{}, nil
91-
} else {
92-
port, err := strconv.Atoi(taskReference.Env[foundIdx].Value)
93-
if err != nil {
94-
log.Error(fmt.Errorf("found OCC_CONTROL_PORT isn't convertible to number "), "failed to fill in env vars from template")
95-
return &reconcile.Result{}, nil
96-
}
97-
task.Spec.Control.Port = port
98-
}
99-
10086
if task.Spec.Arguments == nil {
10187
task.Spec.Arguments = make(map[string]string)
10288
}
10389

104-
// TODO: check for containers!
105-
task.Spec.Pod.Containers[0].Env = append(task.Spec.Pod.Containers[0].Env, taskReference.Env...)
106-
task.Spec.Pod.Containers[0].Args = append(task.Spec.Pod.Containers[0].Args, taskReference.ArgsCLI...)
90+
handleEnvVars(task, taskReference)
10791
maps.Copy(task.Spec.Arguments, taskReference.ArgsTransition)
10892

10993
task.Spec.Pod.NodeName = resolvedNodename
@@ -131,6 +115,34 @@ func (r *EnvironmentReconciler) runTasksFromReferenceOnNode(ctx context.Context,
131115
return nil, nil
132116
}
133117

118+
func handleEnvVars(task *aliecsv1alpha1.Task, taskReference aliecsv1alpha1.TaskReference) {
119+
// TODO: check for existence of containers
120+
// TODO: adapt for Pods with multiple containers
121+
// reference to existing Env Vars to overwrite them if found in taskReference
122+
existing := make(map[string]int, len(task.Spec.Pod.Containers[0].Env))
123+
for i, e := range task.Spec.Pod.Containers[0].Env {
124+
existing[e.Name] = i
125+
}
126+
for _, e := range taskReference.Env {
127+
if i, ok := existing[e.Name]; ok {
128+
task.Spec.Pod.Containers[0].Env[i] = e
129+
} else {
130+
task.Spec.Pod.Containers[0].Env = append(task.Spec.Pod.Containers[0].Env, e)
131+
}
132+
}
133+
task.Spec.Pod.Containers[0].Args = append(task.Spec.Pod.Containers[0].Args, taskReference.ArgsCLI...)
134+
135+
// TODO: should the OCC_CONTROL_PORT handled in task_controller.go and set only Ports and types in this controller?
136+
for _, envVar := range task.Spec.Pod.Containers[0].Env {
137+
if envVar.Name == "OCC_CONTROL_PORT" {
138+
if port, err := strconv.Atoi(envVar.Value); err == nil {
139+
task.Spec.Control.Port = port
140+
}
141+
break
142+
}
143+
}
144+
}
145+
134146
func (r *EnvironmentReconciler) runTaskFromDefinitionOnNode(ctx context.Context, taskDefs []aliecsv1alpha1.TaskDefinition,
135147
nodename string, resolvedNodename string, req ctrl.Request, environment *aliecsv1alpha1.Environment, log logr.Logger,
136148
) (*ctrl.Result, error) {

0 commit comments

Comments
 (0)