Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ spec:
- name: readout
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/readout:1
command: ["/opt/o2/bin/o2-readout-exe"]
env:
- name: OCC_CONTROL_PORT
value: "47101"
securityContext:
privileged: true
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ spec:
- name: stfbuilder
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/dd:1
command: [/opt/o2/bin/StfBuilder]
env:
- name: OCC_CONTROL_PORT
value: "47102"
securityContext:
privileged: true
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
- name: stfsender
image: gitlab-registry.cern.ch/aliceo2group/dockerfiles/alma9-flp-node/dd:1
command: ["numactl"]
env:
- name: OCC_CONTROL_PORT
value: "47103"
securityContext:
privileged: true
volumeMounts:
Expand Down
46 changes: 29 additions & 17 deletions control-operator/internal/controller/environment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,11 @@ func (r *EnvironmentReconciler) runTasksFromReferenceOnNode(ctx context.Context,
task.Spec.Pod = *template.Spec.Pod.DeepCopy()
task.Spec.Control = *template.Spec.Control.DeepCopy()

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

if task.Spec.Arguments == nil {
task.Spec.Arguments = make(map[string]string)
}

// TODO: check for containers!
task.Spec.Pod.Containers[0].Env = append(task.Spec.Pod.Containers[0].Env, taskReference.Env...)
task.Spec.Pod.Containers[0].Args = append(task.Spec.Pod.Containers[0].Args, taskReference.ArgsCLI...)
handleEnvVars(task, taskReference)
maps.Copy(task.Spec.Arguments, taskReference.ArgsTransition)

task.Spec.Pod.NodeName = nodename
Expand All @@ -127,6 +111,34 @@ func (r *EnvironmentReconciler) runTasksFromReferenceOnNode(ctx context.Context,
return nil, nil
}

func handleEnvVars(task *aliecsv1alpha1.Task, taskReference aliecsv1alpha1.TaskReference) {
// TODO: check for existence of containers
// TODO: adapt for Pods with multiple containers
// reference to existing Env Vars to overwrite them if found in taskReference
existing := make(map[string]int, len(task.Spec.Pod.Containers[0].Env))
for i, e := range task.Spec.Pod.Containers[0].Env {
existing[e.Name] = i
}
for _, e := range taskReference.Env {
if i, ok := existing[e.Name]; ok {
task.Spec.Pod.Containers[0].Env[i] = e
} else {
task.Spec.Pod.Containers[0].Env = append(task.Spec.Pod.Containers[0].Env, e)
}
}
task.Spec.Pod.Containers[0].Args = append(task.Spec.Pod.Containers[0].Args, taskReference.ArgsCLI...)

// TODO: should the OCC_CONTROL_PORT handled in task_controller.go and set only Ports and types in this controller?
for _, envVar := range task.Spec.Pod.Containers[0].Env {
if envVar.Name == "OCC_CONTROL_PORT" {
if port, err := strconv.Atoi(envVar.Value); err == nil {
task.Spec.Control.Port = port
}
break
}
}
}

func (r *EnvironmentReconciler) runTaskFromDefinitionOnNode(ctx context.Context, taskDefs []aliecsv1alpha1.TaskDefinition,
nodename string, req ctrl.Request, environment *aliecsv1alpha1.Environment, log logr.Logger,
) (*ctrl.Result, error) {
Expand Down
Loading