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
16 changes: 12 additions & 4 deletions common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,22 @@ func ExtractTaskClassName(taskName string) (string, error) {
return matches[1], nil
}

// JitK8sPrefix is the name prefix of JIT workflows and task classes generated to run on Kubernetes.
const JitK8sPrefix = "jit-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".
// 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".
// If input does not contain a JIT prefix, it is returned as it is.
func TrimJitPrefix(taskClassName string) string {
nParts := 3
if strings.HasPrefix(taskClassName, JitK8sPrefix) {
nParts = 4
}
if strings.HasPrefix(taskClassName, "jit-") {
parts := strings.SplitN(taskClassName, "-", 3)
if len(parts) > 2 {
return parts[2]
parts := strings.SplitN(taskClassName, "-", nParts)
if len(parts) == nParts {
return parts[nParts-1]
}
}
return taskClassName
Expand Down
5 changes: 5 additions & 0 deletions common/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ var _ = Describe("Utils", func() {
Expect(result).To(Equal("qc-pp-TPC-CalibQC_long"))
})

It("should remove the Kubernetes JIT prefix correctly", func() {
result := TrimJitPrefix("jit-k8s-ad6f2b64b7502198430d7d7f93f15bf94c088cab-qc-pp-TPC-CalibQC_long")
Expect(result).To(Equal("qc-pp-TPC-CalibQC_long"))
})

It("should return the original string if no JIT prefix is present", func() {
result := TrimJitPrefix("qc-pp-TPC-CalibQC_long")
Expect(result).To(Equal("qc-pp-TPC-CalibQC_long"))
Expand Down
14 changes: 13 additions & 1 deletion configuration/template/dplutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"encoding/hex"
"fmt"
"github.com/AliceO2Group/Control/common/logger/infologger"
"github.com/AliceO2Group/Control/common/utils"
"os"
"os/exec"
"path/filepath"
Expand All @@ -38,6 +39,7 @@ import (

"github.com/AliceO2Group/Control/configuration/componentcfg"
"github.com/AliceO2Group/Control/core/repos"
"github.com/spf13/viper"
)

// extractConfigURIs looks for configuration URIs in the provided DPL commands and extracts them
Expand Down Expand Up @@ -74,6 +76,12 @@ func extractConfigURIs(dplCommand string) (uris []string) {
func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, workflowRepo repos.IRepo, dplCommand string, userWfName string) (jitWorkflowName string, err error) {
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"
if jitK8sEnabled && !viper.GetBool("enableKubernetes") {
return "", fmt.Errorf("jit_k8s_enabled is set, but Kubernetes support is not enabled in core (enableKubernetes)")
}

var payloads []string

configURIs := extractConfigURIs(dplCommand)
Expand Down Expand Up @@ -140,7 +148,11 @@ func jitDplGenerate(confSvc ConfigurationService, varStack map[string]string, wo
for _, payload := range payloads {
hash.Write([]byte(payload))
}
jitWorkflowName = "jit-" + hex.EncodeToString(hash.Sum(nil))
if jitK8sEnabled {
jitWorkflowName = utils.JitK8sPrefix + hex.EncodeToString(hash.Sum(nil))
} else {
jitWorkflowName = "jit-" + hex.EncodeToString(hash.Sum(nil))
}

// We now have a workflow name made out of a hash that should be unique with respect to
// 1) DPL command and
Expand Down
7 changes: 7 additions & 0 deletions core/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ func getTaskClassList(taskClassesRequired []string) (taskClassList []*taskclass.
return
}

// DPL generates JIT tasks with control mode fairmq, those generated to run on Kubernetes
// are told apart by their name and switched to kubernetes_fairmq.
if strings.HasPrefix(taskClassStruct.Identifier.Name, utils.JitK8sPrefix) &&
taskClassStruct.Control.Mode == controlmode.FAIRMQ {
taskClassStruct.Control.Mode = controlmode.KUBERNETES_FAIRMQ
}

taskClassStruct.Identifier.RepoIdentifier = repo.GetIdentifier()
taskClassStruct.Identifier.Hash = repo.GetHash()
taskClassList = append(taskClassList, &taskClassStruct)
Expand Down
6 changes: 3 additions & 3 deletions core/task/managerk8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const (
)

// jitClassNameRe matches JIT-generated task class identifiers of the form
// "jit-<40-hex-char-sha1>-<devicename>" (see configuration/template/dplutil.go)
// and captures the devicename, e.g. "readout-proxy" or "Dispatcher".
var jitClassNameRe = regexp.MustCompile(`^jit-[0-9a-f]{40}-(.+)$`)
// "jit-<40-hex-char-sha1>-<devicename>" or "jit-k8s-<40-hex-char-sha1>-<devicename>"
// (see configuration/template/dplutil.go) and captures the devicename, e.g. "readout-proxy" or "Dispatcher".
var jitClassNameRe = regexp.MustCompile(`^jit-(?:k8s-)?[0-9a-f]{40}-(.+)$`)

// k8sEnvRegistry maps ECS environment IDs to K8s custom Environment names.
type k8sEnvRegistry struct {
Expand Down
2 changes: 1 addition & 1 deletion docs/kubernetes_ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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. However, there is a problem: JIT tasks' manifests are created the moment they are run. So for now you need to first run the workflow to generate those tasks, then change the control mode after they've been generated. This will be changed in the future.
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.

## Running tasks (`KubectlTask`)

Expand Down
Loading