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
4 changes: 4 additions & 0 deletions common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func ExtractTaskClassName(taskName string) (string, error) {
// JitK8sPrefix is the name prefix of JIT workflows and task classes generated to run on Kubernetes.
const JitK8sPrefix = "jit-k8s-"

// K8sTaskClassSuffix is the name suffix of task classes dedicated to run on Kubernetes,
// e.g. "readout-k8s" is the Kubernetes variant of "readout".
const K8sTaskClassSuffix = "-k8s"

// TrimJitPrefix removes the JIT prefix from task class names.
// For example, "jit-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long" becomes "qc-pp-TPC-CalibQC_long",
// as does "jit-k8s-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long".
Expand Down
4 changes: 2 additions & 2 deletions configuration/template/dplutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, wo
envId, _ := varStack["environment_id"]

// When enabled, the JIT workflow gets a separate name (and files), whose tasks are deployed via the K8s path
jitK8sEnabled := varStack["jit_k8s_enabled"] == "true"
jitK8sEnabled := varStack["k8s_enabled"] == "true"
if jitK8sEnabled && !viper.GetBool("enableKubernetes") {
return "", fmt.Errorf("jit_k8s_enabled is set, but Kubernetes support is not enabled in core (enableKubernetes)")
return "", fmt.Errorf("k8s_enabled is set, but Kubernetes support is not enabled in core (enableKubernetes)")
}

var payloads []string
Expand Down
4 changes: 4 additions & 0 deletions core/task/managerk8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/apimachinery/pkg/watch"

"github.com/AliceO2Group/Control/common/gera"
"github.com/AliceO2Group/Control/common/utils"
"github.com/AliceO2Group/Control/common/utils/uid"
"github.com/AliceO2Group/Control/control-operator/api/v1alpha1"
k8sclient "github.com/AliceO2Group/Control/control-operator/pkg/client"
Expand Down Expand Up @@ -262,6 +263,9 @@ func (m *Manager) buildK8sNodeTaskRefs(envId uid.ID, entries []k8sTaskEntry) (ma
isJit = true
refName = k8sJitTaskTemplateName
nameSuffix = match[1]
} else {
// Kubernetes variants of task classes ("readout-k8s") use the TaskTemplate of the original ("readout")
refName = strings.TrimSuffix(refName, utils.K8sTaskClassSuffix)
}

var argsCLI []string
Expand Down
30 changes: 28 additions & 2 deletions core/workflow/taskrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ package workflow

import (
"errors"
"fmt"
"os"
"path"
"strings"
texttemplate "text/template"
"time"
Expand All @@ -36,12 +39,14 @@ import (
"github.com/AliceO2Group/Control/common/event"
"github.com/AliceO2Group/Control/common/event/topic"
pb "github.com/AliceO2Group/Control/common/protos"
"github.com/AliceO2Group/Control/common/utils"
"github.com/AliceO2Group/Control/configuration/template"
"github.com/AliceO2Group/Control/core/repos"
"github.com/AliceO2Group/Control/core/task"
"github.com/AliceO2Group/Control/core/the"
"github.com/AliceO2Group/Control/core/workflow/callable"
"github.com/gobwas/glob"
"github.com/spf13/viper"
)

type taskRole struct {
Expand Down Expand Up @@ -198,13 +203,34 @@ func (t *taskRole) ProcessTemplates(workflowRepo repos.IRepo, _ LoadSubworkflowF
return
}

t.resolveTaskClassIdentifier(workflowRepo)
err = t.resolveTaskClassIdentifier(workflowRepo)

return
}

func (t *taskRole) resolveTaskClassIdentifier(repo repos.IRepo) {
func (t *taskRole) resolveTaskClassIdentifier(repo repos.IRepo) error {
varStack, err := t.ConsolidatedVarStack()
if err != nil {
return err
}

// When enabled, tasks are deployed via the K8s path using dedicated "<name>-k8s" task classes.
// JIT task classes are generated for K8s already (see configuration/template/dplutil.go).
if varStack["k8s_enabled"] == "true" && !strings.HasPrefix(path.Base(t.LoadTaskClass), utils.JitK8sPrefix) {
if !viper.GetBool("enableKubernetes") {
return fmt.Errorf("k8s_enabled is set, but Kubernetes support is not enabled in core (enableKubernetes)")
}
k8sTaskClass := repo.ResolveTaskClassIdentifier(t.LoadTaskClass + utils.K8sTaskClassSuffix)
k8sTaskClassFile := strings.Split(k8sTaskClass, "@")[0] + ".yaml"
if _, err = os.Stat(repo.GetTaskTemplatePath(k8sTaskClassFile)); err != nil {
return fmt.Errorf("k8s_enabled is set, but task class %s has no Kubernetes variant %s: %w", t.LoadTaskClass, t.LoadTaskClass+utils.K8sTaskClassSuffix, err)
}
t.LoadTaskClass = k8sTaskClass
return nil
}

t.LoadTaskClass = repo.ResolveTaskClassIdentifier(t.LoadTaskClass)
return nil
}

func (t *taskRole) UpdateStatus(s task.Status) {
Expand Down
8 changes: 7 additions & 1 deletion docs/kubernetes_ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ The manager.go implements the split between Mesos and K8s tasks while managerk8s

To deploy a Kubernetes task you can in principle reuse existing control-workflow task YAML manifests by changing the control mode to `kubernetes_direct` or `kubernetes_fairmq`. But in practice there can be issues reusing existing manifests, for example issues with argument quotation: Mesos runs tasks via shell, which interpreted and stripped quotation from commands. But K8s uses arguments as they are passed. For this reason you can find ready-to-use manifests with all necessary changes inside `control-operator/ecs-manifests/control-workflows/*kube-direct*` and you can just copy these files to be used instead of Workflow yaml templates.

### Switching between Mesos and Kubernetes

Whether tasks run via Mesos or Kubernetes is controlled by a single environment variable `k8s_enabled` ("Run on Kubernetes" checkbox in the GUI, requires `enableKubernetes` in core). Workflow templates don't need to change: when `k8s_enabled` is `true`, a role with `load: readout` loads the task class `readout-k8s` (file `tasks/readout-k8s.yaml` in the same repository) instead of `readout`. If the `-k8s` variant doesn't exist, the environment fails to be created. JIT tasks don't need a `-k8s` variant, as they are generated for Kubernetes (see [DPL and JIT](#dpl-and-jit)).

The `-k8s` task classes are the ones from `control-operator/ecs-manifests/control-workflows/*kube-direct*` with the matching name, i.e. they use `kubernetes_direct`/`kubernetes_fairmq` control modes and have argument quotation fixed. Core looks up the TaskTemplate by the task class name without the `-k8s` suffix, so e.g. `readout-k8s` is deployed with the `readout` TaskTemplate.

### Core configuration

The Kubernetes client in ECS core is configured with the following parameters, passed as CLI arguments or in placed in `o2/components/aliecs/ANY/any/settings` consul file:
Expand All @@ -67,7 +73,7 @@ Since some tasks are deployed with known values ahead of time (image, env vars,

### DPL and JIT

DPL tasks work similarly to those mentioned before: they use `kubernetes_fairmq` in their workflow YAML manifests. JIT tasks are different, as their manifests are generated by DPL the moment the workflow is run, always with control mode `fairmq`. To run them on Kubernetes, set the environment variable `jit_k8s_enabled` to `true` (requires `enableKubernetes` in core). The JIT workflow is then generated under the name `jit-k8s-<hash>` instead of `jit-<hash>`, and core switches the control mode of its tasks to `kubernetes_fairmq` when loading them. All JIT tasks are deployed using the shared `dpl` TaskTemplate.
DPL tasks work similarly to those mentioned before: they use `kubernetes_fairmq` in their workflow YAML manifests. JIT tasks are different, as their manifests are generated by DPL the moment the workflow is run, always with control mode `fairmq`. To run them on Kubernetes, set the environment variable `k8s_enabled` to `true` (requires `enableKubernetes` in core). The JIT workflow is then generated under the name `jit-k8s-<hash>` instead of `jit-<hash>`, and core switches the control mode of its tasks to `kubernetes_fairmq` when loading them. All JIT tasks are deployed using the shared `dpl` TaskTemplate.

## Running tasks (`KubectlTask`)

Expand Down
Loading