Monitord Acces Change
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"oc-monitord/conf"
|
||||
. "oc-monitord/models"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"os"
|
||||
@@ -80,23 +81,23 @@ func (b *Workflow) getDag() *Dag {
|
||||
|
||||
// PodSecurityContext mirrors the subset of k8s PodSecurityContext used by Argo.
|
||||
type PodSecurityContext struct {
|
||||
RunAsUser *int64 `yaml:"runAsUser,omitempty"`
|
||||
RunAsUser *int64 `yaml:"runAsUser,omitempty"`
|
||||
RunAsGroup *int64 `yaml:"runAsGroup,omitempty"`
|
||||
FSGroup *int64 `yaml:"fsGroup,omitempty"`
|
||||
FSGroup *int64 `yaml:"fsGroup,omitempty"`
|
||||
}
|
||||
|
||||
// Spec contient la spécification complète du workflow Argo :
|
||||
// compte de service, point d'entrée, volumes, templates et timeout.
|
||||
type Spec struct {
|
||||
ArtifactRepositoryRef
|
||||
ServiceAccountName string `yaml:"serviceAccountName,omitempty"`
|
||||
Entrypoint string `yaml:"entrypoint"`
|
||||
Arguments []Parameter `yaml:"arguments,omitempty"`
|
||||
Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"`
|
||||
ExistingVolumes []ExistingVolume `yaml:"volumes,omitempty"`
|
||||
Templates []Template `yaml:"templates"`
|
||||
Timeout int `yaml:"activeDeadlineSeconds,omitempty"`
|
||||
SecurityContext *PodSecurityContext `yaml:"securityContext,omitempty"`
|
||||
ArtifactRepositoryRef *ArtifactRepositoryRef `yaml:"artifactRepositoryRef,omitempty"`
|
||||
ServiceAccountName string `yaml:"serviceAccountName,omitempty"`
|
||||
Entrypoint string `yaml:"entrypoint"`
|
||||
Arguments []Parameter `yaml:"arguments,omitempty"`
|
||||
Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"`
|
||||
ExistingVolumes []ExistingVolume `yaml:"volumes,omitempty"`
|
||||
Templates []Template `yaml:"templates"`
|
||||
Timeout int `yaml:"activeDeadlineSeconds,omitempty"`
|
||||
SecurityContext *PodSecurityContext `yaml:"securityContext,omitempty"`
|
||||
}
|
||||
|
||||
// CreateDAG est le point d'entrée de la construction du DAG Argo.
|
||||
@@ -151,10 +152,11 @@ func (b *ArgoBuilder) createTemplates(exec *workflow_execution.WorkflowExecution
|
||||
if d, ok := exec.SelectedInstances[res.GetID()]; ok {
|
||||
index = d
|
||||
}
|
||||
instance := item.Processing.GetSelectedInstance(&index)
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for", item.Processing.GetName(), instance))
|
||||
if instance == nil || instance.(*resources.ProcessingInstance).Access == nil && instance.(*resources.ProcessingInstance).Access.Container != nil {
|
||||
logger.Error().Msg("Not enough configuration setup, template can't be created : " + item.Processing.GetName())
|
||||
instance := item.ItemResource.Processing.GetSelectedInstance(&index)
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for", item.ItemResource.Processing.GetName(), instance))
|
||||
procInst, _ := instance.(*resources.ProcessingInstance)
|
||||
if instance == nil || procInst == nil || procInst.Access == nil || (procInst.Access.Container == nil && !procInst.Access.HasSource()) {
|
||||
logger.Error().Msg("Not enough configuration setup, template can't be created : " + item.ItemResource.Processing.GetName())
|
||||
return firstItems, lastItems, volumes, nil
|
||||
}
|
||||
// Un même processing peut être bookié sur plusieurs peers : on crée
|
||||
@@ -162,16 +164,55 @@ func (b *ArgoBuilder) createTemplates(exec *workflow_execution.WorkflowExecution
|
||||
for _, pb := range getAllPeersForItem(exec, item.ID) {
|
||||
var err error
|
||||
volumes, firstItems, lastItems, err = b.createArgoTemplates(exec,
|
||||
namespace, item.ID, pb.PeerID, pb.BookingID, item.Processing, volumes, firstItems, lastItems)
|
||||
namespace, item.ID, pb.PeerID, pb.BookingID, item.ItemResource.Processing, volumes, firstItems, lastItems)
|
||||
if err != nil {
|
||||
return firstItems, lastItems, volumes, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Service Resources ---
|
||||
// HOSTED : le creator_id identifie le peer propriétaire du compute à contacter ;
|
||||
// pas de lien avec un compute unit nécessaire.
|
||||
// DEPLOYMENT : le service doit être déployé sur un compute booké (comme un processing).
|
||||
for _, item := range b.OriginWorkflow.GetGraphItems(b.OriginWorkflow.Graph.IsService) {
|
||||
index := 0
|
||||
_, res := item.GetResource()
|
||||
if d, ok := exec.SelectedInstances[res.GetID()]; ok {
|
||||
index = d
|
||||
}
|
||||
instance := item.ItemResource.Service.GetSelectedInstance(&index)
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for service", item.ItemResource.Service.GetName(), instance))
|
||||
if instance == nil {
|
||||
logger.Error().Msg("Not enough configuration setup, service template can't be created : " + item.ItemResource.Service.GetName())
|
||||
continue
|
||||
}
|
||||
svcInst := instance.(*resources.ServiceInstance)
|
||||
if svcInst.Mode == resources.HOSTED {
|
||||
// HOSTED : le creator_id suffit à identifier le peer cible.
|
||||
peerID := item.ItemResource.Service.GetCreatorID()
|
||||
var err error
|
||||
volumes, firstItems, lastItems, err = b.createArgoTemplates(exec,
|
||||
namespace, item.ID, peerID, item.ID, item.ItemResource.Service, volumes, firstItems, lastItems)
|
||||
if err != nil {
|
||||
return firstItems, lastItems, volumes, err
|
||||
}
|
||||
} else {
|
||||
// DEPLOYMENT : un template par peer booké, comme les processings.
|
||||
for _, pb := range getAllPeersForItem(exec, item.ID) {
|
||||
var err error
|
||||
volumes, firstItems, lastItems, err = b.createArgoTemplates(exec,
|
||||
namespace, item.ID, pb.PeerID, pb.BookingID, item.ItemResource.Service, volumes, firstItems, lastItems)
|
||||
if err != nil {
|
||||
return firstItems, lastItems, volumes, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Native Tools de type WORKFLOW_EVENT uniquement ---
|
||||
for _, item := range b.OriginWorkflow.GetGraphItems(b.OriginWorkflow.Graph.IsNativeTool) {
|
||||
if item.NativeTool.Kind != int(native_tools.WORKFLOW_EVENT) {
|
||||
if item.ItemResource.NativeTool.Kind != int(native_tools.WORKFLOW_EVENT) {
|
||||
continue
|
||||
}
|
||||
index := 0
|
||||
@@ -179,11 +220,14 @@ func (b *ArgoBuilder) createTemplates(exec *workflow_execution.WorkflowExecution
|
||||
if d, ok := exec.SelectedInstances[res.GetID()]; ok {
|
||||
index = d
|
||||
}
|
||||
instance := item.NativeTool.GetSelectedInstance(&index)
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for", item.NativeTool.GetName(), instance))
|
||||
instance := item.ItemResource.NativeTool.GetSelectedInstance(&index)
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for", item.ItemResource.NativeTool.GetName(), instance))
|
||||
// Résolution du peer cible : distant si un compute directement connecté
|
||||
// est distant, local sinon (aucun compute ou compute local).
|
||||
peerID := b.getNativeToolPeer(item.ID)
|
||||
var err error
|
||||
volumes, firstItems, lastItems, err = b.createArgoTemplates(exec,
|
||||
namespace, item.ID, "", item.ID, item.NativeTool, volumes, firstItems, lastItems)
|
||||
namespace, item.ID, peerID, item.ID, item.ItemResource.NativeTool, volumes, firstItems, lastItems)
|
||||
if err != nil {
|
||||
return firstItems, lastItems, volumes, err
|
||||
}
|
||||
@@ -193,7 +237,7 @@ func (b *ArgoBuilder) createTemplates(exec *workflow_execution.WorkflowExecution
|
||||
firstWfTasks := map[string][]string{}
|
||||
latestWfTasks := map[string][]string{}
|
||||
relatedWfTasks := map[string][]string{}
|
||||
for _, wf := range b.OriginWorkflow.Workflows {
|
||||
for _, wf := range b.OriginWorkflow.ResourceSet.Workflows {
|
||||
realWorkflow, code, err := w.NewAccessor(nil).LoadOne(wf)
|
||||
if code != 200 {
|
||||
logger.Error().Msg("Error loading the workflow : " + err.Error())
|
||||
@@ -257,6 +301,12 @@ func (b *ArgoBuilder) createTemplates(exec *workflow_execution.WorkflowExecution
|
||||
}
|
||||
}
|
||||
|
||||
// --- Sources Data (isReachable = true ET false) ---
|
||||
// Injecte les steps curl/wrapper pour les Data avec source, APRÈS que toutes les
|
||||
// steps processing ont été ajoutées au DAG (dépendances câblées).
|
||||
// Phase 3 (public) et Phase 4 (privé) sont gérées dans HandleDataSources.
|
||||
b.HandleDataSources(exec, namespace)
|
||||
|
||||
// Si des services Kubernetes sont nécessaires, on ajoute le pod dédié.
|
||||
if b.Services != nil {
|
||||
dag := b.Workflow.getDag()
|
||||
@@ -289,17 +339,61 @@ func (b *ArgoBuilder) createArgoTemplates(
|
||||
template := &Template{Name: getArgoName(obj.GetName(), bookingID)}
|
||||
logger.Info().Msg(fmt.Sprint("Creating template for", template.Name))
|
||||
|
||||
// Résoudre le peer en amont pour que le NativeTool puisse choisir l'URL NATS cible.
|
||||
isReparted, remotePeer := b.isPeerReparted(peerID)
|
||||
|
||||
if obj.GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||
template.CreateContainer(exec, obj.(*resources.ProcessingResource), b.Workflow.getDag())
|
||||
proc := obj.(*resources.ProcessingResource)
|
||||
index := 0
|
||||
if d, ok := exec.SelectedInstances[proc.GetID()]; ok {
|
||||
index = d
|
||||
}
|
||||
if procInst, ok := proc.GetSelectedInstance(&index).(*resources.ProcessingInstance); ok && procInst.Access.HasSource() {
|
||||
argoStepName := getArgoName(proc.GetName(), bookingID)
|
||||
if procInst.Access.Source.IsReachable {
|
||||
// Phase 3 — source publique : injecter une step curl directe.
|
||||
if err := b.handleProcessingSource(exec, graphID, proc, procInst, argoStepName, template); err != nil {
|
||||
logger.Error().Msg("[source-fetch] " + err.Error())
|
||||
return volumes, firstItems, lastItems, err
|
||||
}
|
||||
} else {
|
||||
// Phase 4 — source privée : NATS + URL pré-signée + Secret K8s.
|
||||
if err := b.handlePrivateProcessingSource(exec, graphID, proc, procInst, argoStepName, namespace); err != nil {
|
||||
logger.Error().Msg("[source-private] " + err.Error())
|
||||
return volumes, firstItems, lastItems, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
template.CreateContainer(exec, b.OriginWorkflow, graphID, proc, b.Workflow.getDag())
|
||||
}
|
||||
} else if obj.GetType() == tools.NATIVE_TOOL.String() {
|
||||
template.CreateEventContainer(exec, obj.(*resources.NativeTool), b.Workflow.getDag())
|
||||
// Pour le cas local, on utilise le FQDN cross-namespace car le pod tourne
|
||||
// dans le namespace executions_id, pas dans OCNamespace (opencloud).
|
||||
natsURL := conf.GetConfig().NATSPodURL()
|
||||
if isReparted && remotePeer != nil && remotePeer.NATSAddress != "" {
|
||||
natsURL = remotePeer.NATSAddress
|
||||
}
|
||||
template.CreateEventContainer(exec, graphID, b.OriginWorkflow, obj.(*resources.NativeTool), b.Workflow.getDag(), natsURL)
|
||||
} else if obj.GetType() == tools.SERVICE_RESOURCE.String() {
|
||||
svc := obj.(*resources.ServiceResource)
|
||||
template.CreateServiceContainer(exec, b.OriginWorkflow, graphID, svc, b.Workflow.getDag())
|
||||
// Le k8s Service (NodePort/LoadBalancer) et le label "app" ne sont nécessaires
|
||||
// que pour DEPLOYMENT : le service est déployé et doit être exposé.
|
||||
// Pour HOSTED, le service tourne déjà chez son créateur, aucune exposition locale.
|
||||
svcIndex := 0
|
||||
if d, ok := exec.SelectedInstances[svc.GetID()]; ok {
|
||||
svcIndex = d
|
||||
}
|
||||
if inst, ok := svc.GetSelectedInstance(&svcIndex).(*resources.ServiceInstance); ok && inst.Mode == resources.DEPLOYMENT {
|
||||
b.CreateService(exec, graphID, obj)
|
||||
template.Metadata.Labels = make(map[string]string)
|
||||
template.Metadata.Labels["app"] = "oc-service-" + obj.GetName()
|
||||
}
|
||||
}
|
||||
// Enregistre l'image pour le pre-pull sur le peer cible.
|
||||
// peerID == "" désigne le peer local (clé "" dans PeerImages).
|
||||
b.addPeerImage(peerID, template.Container.Image)
|
||||
|
||||
// Vérifie si le peer est distant (Admiralty).
|
||||
isReparted, remotePeer := b.isPeerReparted(peerID)
|
||||
if isReparted {
|
||||
logger.Debug().Msg("Reparted processing, on " + remotePeer.GetID())
|
||||
b.RemotePeers = append(b.RemotePeers, remotePeer.GetID())
|
||||
@@ -309,14 +403,6 @@ func (b *ArgoBuilder) createArgoTemplates(
|
||||
b.HasLocalCompute = true
|
||||
}
|
||||
|
||||
// Si le processing expose un service Kubernetes, on l'enregistre et on
|
||||
// applique le label "app" pour que le Service puisse le sélectionner.
|
||||
if obj.GetType() == tools.PROCESSING_RESOURCE.String() && obj.(*resources.ProcessingResource).IsService {
|
||||
b.CreateService(exec, graphID, obj)
|
||||
template.Metadata.Labels = make(map[string]string)
|
||||
template.Metadata.Labels["app"] = "oc-service-" + obj.GetName()
|
||||
}
|
||||
|
||||
var err error
|
||||
volumes, err = b.addStorageAnnotations(exec, graphID, template, namespace, volumes, isReparted)
|
||||
if err != nil {
|
||||
@@ -340,19 +426,25 @@ func (b *ArgoBuilder) addStorageAnnotations(exec *workflow_execution.WorkflowExe
|
||||
related := b.OriginWorkflow.GetByRelatedProcessing(id, b.OriginWorkflow.Graph.IsStorage)
|
||||
|
||||
for _, r := range related {
|
||||
storage := r.Node.(*resources.StorageResource)
|
||||
for _, linkToStorage := range r.Links {
|
||||
n := r.Node
|
||||
storage := n.(*resources.StorageResource)
|
||||
for _, linkToStorage := range r.Links { //nolint:govet
|
||||
for _, rw := range linkToStorage.StorageLinkInfos {
|
||||
var art Artifact
|
||||
// Le nom de l'artefact doit être alphanumérique + '-' ou '_'.
|
||||
artifactBaseName := strings.Join(strings.Split(storage.GetName(), " "), "-") + "-" + strings.Replace(rw.FileName, ".", "-", -1)
|
||||
envs := []Parameter{}
|
||||
for _, p := range linkToStorage.Env {
|
||||
envs = append(envs, Parameter{Name: p.Name})
|
||||
}
|
||||
if rw.Write {
|
||||
// Écriture vers S3 : Path = chemin du fichier dans le pod.
|
||||
art = Artifact{Path: template.ReplacePerEnv(rw.Source, linkToStorage.Env)}
|
||||
art = Artifact{Path: template.ReplacePerEnv(rw.Source, envs)}
|
||||
art.Name = artifactBaseName + "-input-write"
|
||||
} else {
|
||||
|
||||
// Lecture depuis S3 : Path = destination dans le pod.
|
||||
art = Artifact{Path: template.ReplacePerEnv(rw.Destination+"/"+rw.FileName, linkToStorage.Env)}
|
||||
art = Artifact{Path: template.ReplacePerEnv(rw.Destination+"/"+rw.FileName, envs)}
|
||||
art.Name = artifactBaseName + "-input-read"
|
||||
}
|
||||
|
||||
@@ -430,6 +522,97 @@ func (b *ArgoBuilder) addStorageAnnotations(exec *workflow_execution.WorkflowExe
|
||||
}, volumes)
|
||||
}
|
||||
}
|
||||
// Embedded storages: scan links for compute nodes connected to this processing.
|
||||
// Key in SelectedEmbeddedStorages is the graph item ID (not resource ID), so we
|
||||
// iterate links directly to preserve the graph position identity.
|
||||
for _, link := range b.OriginWorkflow.Graph.Links {
|
||||
var computeGraphID string
|
||||
if link.Source.ID == id && b.OriginWorkflow.Graph.IsCompute(b.OriginWorkflow.Graph.Items[link.Destination.ID]) {
|
||||
computeGraphID = link.Destination.ID
|
||||
} else if link.Destination.ID == id && b.OriginWorkflow.Graph.IsCompute(b.OriginWorkflow.Graph.Items[link.Source.ID]) {
|
||||
computeGraphID = link.Source.ID
|
||||
}
|
||||
if computeGraphID == "" {
|
||||
continue
|
||||
}
|
||||
sel, ok := exec.SelectedEmbeddedStorages[computeGraphID]
|
||||
if !ok || sel == nil {
|
||||
continue
|
||||
}
|
||||
c := b.OriginWorkflow.Graph.Items[computeGraphID]
|
||||
_, computeRes := (&c).GetResource()
|
||||
computeResource := computeRes.(*resources.ComputeResource)
|
||||
computeIdx := 0
|
||||
if d, ok := exec.SelectedInstances[computeResource.GetID()]; ok {
|
||||
computeIdx = d
|
||||
}
|
||||
if computeIdx >= len(computeResource.Instances) {
|
||||
continue
|
||||
}
|
||||
computeInst := computeResource.Instances[computeIdx]
|
||||
if sel.StorageIndex >= len(computeInst.AvailableStorages) {
|
||||
continue
|
||||
}
|
||||
storage := computeInst.AvailableStorages[sel.StorageIndex]
|
||||
|
||||
if storage.StorageType == enum.S3 {
|
||||
relatedProcessing := b.getStorageRelatedProcessing(storage.GetID())
|
||||
var wg sync.WaitGroup
|
||||
errCh := make(chan error, len(relatedProcessing))
|
||||
for _, rp := range relatedProcessing {
|
||||
wg.Add(1)
|
||||
go waitForConsiders(exec.ExecutionsID, tools.STORAGE_RESOURCE, ArgoKubeEvent{
|
||||
ExecutionsID: exec.ExecutionsID,
|
||||
DestPeerID: rp.GetID(),
|
||||
Type: tools.STORAGE_RESOURCE,
|
||||
SourcePeerID: storage.GetCreatorID(),
|
||||
OriginID: conf.GetConfig().PeerID,
|
||||
}, &wg, errCh)
|
||||
}
|
||||
wg.Wait()
|
||||
close(errCh)
|
||||
for err := range errCh {
|
||||
if err != nil {
|
||||
return volumes, err
|
||||
}
|
||||
}
|
||||
b.addS3annotations(storage, namespace)
|
||||
} else {
|
||||
// Local volume / Minio: provision PVC via oc-datacenter then mount it.
|
||||
var pvcWg sync.WaitGroup
|
||||
pvcErrCh := make(chan error, 1)
|
||||
pvcWg.Add(1)
|
||||
go waitForConsiders(exec.ExecutionsID, tools.STORAGE_RESOURCE, ArgoKubeEvent{
|
||||
ExecutionsID: exec.ExecutionsID,
|
||||
Type: tools.STORAGE_RESOURCE,
|
||||
SourcePeerID: conf.GetConfig().PeerID,
|
||||
DestPeerID: conf.GetConfig().PeerID,
|
||||
OriginID: conf.GetConfig().PeerID,
|
||||
MinioID: storage.GetID(),
|
||||
Local: true,
|
||||
StorageName: storage.GetName(),
|
||||
}, &pvcWg, pvcErrCh)
|
||||
pvcWg.Wait()
|
||||
close(pvcErrCh)
|
||||
for err := range pvcErrCh {
|
||||
if err != nil {
|
||||
return volumes, err
|
||||
}
|
||||
}
|
||||
// Use the first instance's source as mount path if available.
|
||||
mountPath := ""
|
||||
if len(storage.Instances) > 0 {
|
||||
mountPath = storage.Instances[0].Source
|
||||
}
|
||||
volumes = template.Container.AddVolumeMount(VolumeMount{
|
||||
Name: strings.ReplaceAll(strings.ToLower(storage.GetName()), " ", "-"),
|
||||
MountPath: mountPath,
|
||||
Storage: storage,
|
||||
IsReparted: isReparted,
|
||||
}, volumes)
|
||||
}
|
||||
}
|
||||
|
||||
return volumes, nil
|
||||
}
|
||||
|
||||
@@ -478,12 +661,26 @@ func (b *ArgoBuilder) getComputeProcessing(processingId string) (res []resources
|
||||
// du workflow Argo. La ConfigMap et la clé sont dérivées de l'ID du stockage.
|
||||
// Le namespace est conservé en signature pour une évolution future.
|
||||
func (b *ArgoBuilder) addS3annotations(storage *resources.StorageResource, namespace string) {
|
||||
b.Workflow.Spec.ArtifactRepositoryRef = ArtifactRepositoryRef{
|
||||
b.Workflow.Spec.ArtifactRepositoryRef = &ArtifactRepositoryRef{
|
||||
ConfigMap: storage.GetID() + "-artifact-repository",
|
||||
Key: storage.GetID() + "-s3-local",
|
||||
}
|
||||
}
|
||||
|
||||
func (b *ArgoBuilder) getRealVar(exec *workflow_execution.WorkflowExecution, val string, processing resources.ResourceInterface) string {
|
||||
if strings.Contains(val, "[resource]instance.") {
|
||||
attr := strings.ReplaceAll(val, "[resource]instance.", "")
|
||||
index := 0
|
||||
if d, ok := exec.SelectedInstances[processing.GetID()]; ok {
|
||||
index = d
|
||||
}
|
||||
instance := processing.GetSelectedInstance(&index)
|
||||
ser := instance.Serialize(instance)
|
||||
return fmt.Sprintf("%v", ser[attr])
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
// addTaskToArgo ajoute une tâche au DAG Argo pour le nœud graphItemID.
|
||||
// Elle résout les dépendances DAG, propage les paramètres d'environnement,
|
||||
// d'entrée et de sortie de l'instance sélectionnée, et met à jour les listes
|
||||
@@ -494,32 +691,77 @@ func (b *ArgoBuilder) addTaskToArgo(exec *workflow_execution.WorkflowExecution,
|
||||
|
||||
unique_name := getArgoName(processing.GetName(), bookingID)
|
||||
step := Task{Name: unique_name, Template: unique_name}
|
||||
|
||||
index := 0
|
||||
if d, ok := exec.SelectedInstances[processing.GetID()]; ok {
|
||||
index = d
|
||||
// Propagation des variables d'environnement, entrées et sorties
|
||||
// de l'instance vers les paramètres de la tâche Argo.
|
||||
// AppendParamIfAbsent évite les doublons quand une variable est définie
|
||||
// à la fois sur le ProcessingResource et sur le Workflow (override).
|
||||
for _, value := range processing.GetEnv() {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
instance := processing.GetSelectedInstance(&index)
|
||||
if instance != nil {
|
||||
// Propagation des variables d'environnement, entrées et sorties
|
||||
// de l'instance vers les paramètres de la tâche Argo.
|
||||
for _, value := range instance.(*resources.ProcessingInstance).Env {
|
||||
step.Arguments.Parameters = append(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: value.Value,
|
||||
})
|
||||
for _, value := range b.OriginWorkflow.Env[graphItemID] {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
for _, value := range processing.GetInputs() {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
for _, value := range b.OriginWorkflow.Inputs[graphItemID] {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
for _, value := range processing.GetOutputs() {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
for _, value := range b.OriginWorkflow.Outputs[graphItemID] {
|
||||
step.Arguments.Parameters = AppendParamIfAbsent(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: b.getRealVar(exec, value.Value, processing),
|
||||
})
|
||||
}
|
||||
|
||||
// Résolution récursive des références $VAR_NAME entre paramètres.
|
||||
// Les needles sont triées par longueur décroissante pour éviter que $FOO
|
||||
// matche à l'intérieur de $FOOBAR (le plus long est substitué en premier).
|
||||
// On itère jusqu'au point fixe pour gérer les dépendances transitives
|
||||
// (A=$B, B=$C → après deux passes A=valeur de C).
|
||||
sortedParams := make([]Parameter, len(step.Arguments.Parameters))
|
||||
copy(sortedParams, step.Arguments.Parameters)
|
||||
sort.Slice(sortedParams, func(i, j int) bool {
|
||||
return len(sortedParams[i].Name) > len(sortedParams[j].Name)
|
||||
})
|
||||
for {
|
||||
changed := false
|
||||
for i := range step.Arguments.Parameters {
|
||||
for _, needle_param := range sortedParams {
|
||||
if step.Arguments.Parameters[i].Name == needle_param.Name {
|
||||
continue
|
||||
}
|
||||
needle := "$" + needle_param.Name
|
||||
if strings.Contains(step.Arguments.Parameters[i].Value, needle) {
|
||||
step.Arguments.Parameters[i].Value = strings.ReplaceAll(
|
||||
step.Arguments.Parameters[i].Value,
|
||||
needle,
|
||||
needle_param.Value,
|
||||
)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, value := range instance.(*resources.ProcessingInstance).Inputs {
|
||||
step.Arguments.Parameters = append(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: value.Value,
|
||||
})
|
||||
}
|
||||
for _, value := range instance.(*resources.ProcessingInstance).Outputs {
|
||||
step.Arguments.Parameters = append(step.Arguments.Parameters, Parameter{
|
||||
Name: value.Name,
|
||||
Value: value.Value,
|
||||
})
|
||||
if !changed {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,11 +769,14 @@ func (b *ArgoBuilder) addTaskToArgo(exec *workflow_execution.WorkflowExecution,
|
||||
|
||||
// Détermine si ce nœud est une première ou une dernière tâche du DAG.
|
||||
name := ""
|
||||
if b.OriginWorkflow.Graph.Items[graphItemID].Processing != nil {
|
||||
name = b.OriginWorkflow.Graph.Items[graphItemID].Processing.GetName()
|
||||
if b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Processing != nil {
|
||||
name = b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Processing.GetName()
|
||||
}
|
||||
if b.OriginWorkflow.Graph.Items[graphItemID].Workflow != nil {
|
||||
name = b.OriginWorkflow.Graph.Items[graphItemID].Workflow.GetName()
|
||||
if b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Workflow != nil {
|
||||
name = b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Workflow.GetName()
|
||||
}
|
||||
if b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Service != nil {
|
||||
name = b.OriginWorkflow.Graph.Items[graphItemID].ItemResource.Service.GetName()
|
||||
}
|
||||
if len(step.Dependencies) == 0 && name != "" {
|
||||
firstItems = append(firstItems, getArgoName(name, bookingID))
|
||||
@@ -557,9 +802,10 @@ func (b *ArgoBuilder) createVolumes(exec *workflow_execution.WorkflowExecution,
|
||||
}
|
||||
seen[name] = struct{}{}
|
||||
claimName := name + "-" + exec.ExecutionsID
|
||||
ev := ExistingVolume{}
|
||||
ev.Name = name
|
||||
ev.PersistentVolumeClaim.ClaimName = claimName
|
||||
ev := ExistingVolume{
|
||||
Name: name,
|
||||
PersistentVolumeClaim: &PVCRef{ClaimName: claimName},
|
||||
}
|
||||
b.Workflow.Spec.ExistingVolumes = append(b.Workflow.Spec.ExistingVolumes, ev)
|
||||
}
|
||||
// hostPath PVs are created as root:root 0755. Ensure pods can read/write
|
||||
@@ -586,20 +832,27 @@ func (b *ArgoBuilder) isArgoDependancy(exec *workflow_execution.WorkflowExecutio
|
||||
logger.Info().Msg(fmt.Sprint("Could not find the source of the link", link.Destination.ID))
|
||||
continue
|
||||
}
|
||||
source := b.OriginWorkflow.Graph.Items[link.Destination.ID].Processing
|
||||
source := b.OriginWorkflow.Graph.Items[link.Destination.ID].ItemResource.Processing
|
||||
if id == link.Source.ID && source != nil {
|
||||
isDeps = true
|
||||
for _, pb := range getAllPeersForItem(exec, link.Destination.ID) {
|
||||
dependancyOfIDs = append(dependancyOfIDs, getArgoName(source.GetName(), pb.BookingID))
|
||||
}
|
||||
}
|
||||
wourceWF := b.OriginWorkflow.Graph.Items[link.Destination.ID].Workflow
|
||||
wourceWF := b.OriginWorkflow.Graph.Items[link.Destination.ID].ItemResource.Workflow
|
||||
if id == link.Source.ID && wourceWF != nil {
|
||||
isDeps = true
|
||||
for _, pb := range getAllPeersForItem(exec, link.Destination.ID) {
|
||||
dependancyOfIDs = append(dependancyOfIDs, getArgoName(wourceWF.GetName(), pb.BookingID))
|
||||
}
|
||||
}
|
||||
sourceSvc := b.OriginWorkflow.Graph.Items[link.Destination.ID].ItemResource.Service
|
||||
if id == link.Source.ID && sourceSvc != nil {
|
||||
isDeps = true
|
||||
for _, pb := range getAllPeersForItem(exec, link.Destination.ID) {
|
||||
dependancyOfIDs = append(dependancyOfIDs, getArgoName(sourceSvc.GetName(), pb.BookingID))
|
||||
}
|
||||
}
|
||||
}
|
||||
return isDeps, dependancyOfIDs
|
||||
}
|
||||
@@ -614,12 +867,18 @@ func (b *ArgoBuilder) getArgoDependencies(exec *workflow_execution.WorkflowExecu
|
||||
logger.Info().Msg(fmt.Sprint("Could not find the source of the link", link.Source.ID))
|
||||
continue
|
||||
}
|
||||
source := b.OriginWorkflow.Graph.Items[link.Source.ID].Processing
|
||||
source := b.OriginWorkflow.Graph.Items[link.Source.ID].ItemResource.Processing
|
||||
if id == link.Destination.ID && source != nil {
|
||||
for _, pb := range getAllPeersForItem(exec, link.Source.ID) {
|
||||
dependencies = append(dependencies, getArgoName(source.GetName(), pb.BookingID))
|
||||
}
|
||||
}
|
||||
sourceSvc := b.OriginWorkflow.Graph.Items[link.Source.ID].ItemResource.Service
|
||||
if id == link.Destination.ID && sourceSvc != nil {
|
||||
for _, pb := range getAllPeersForItem(exec, link.Source.ID) {
|
||||
dependencies = append(dependencies, getArgoName(sourceSvc.GetName(), pb.BookingID))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -657,6 +916,24 @@ func getAllPeersForItem(exec *workflow_execution.WorkflowExecution, graphItemID
|
||||
return result
|
||||
}
|
||||
|
||||
// getNativeToolPeer résout le peer cible d'un NativeTool WORKFLOW_EVENT.
|
||||
// Règle : si un compute est directement connecté au NativeTool dans le graphe
|
||||
// et que ce compute appartient à un peer distant, on retourne ce peerID.
|
||||
// Dans tous les autres cas (aucun compute connecté, ou compute local), on retourne "".
|
||||
func (b *ArgoBuilder) getNativeToolPeer(graphItemID string) string {
|
||||
computeRel := b.OriginWorkflow.GetByRelatedProcessing(graphItemID, b.OriginWorkflow.Graph.IsCompute)
|
||||
for _, rel := range computeRel {
|
||||
peerID := rel.Node.GetCreatorID()
|
||||
if peerID == "" {
|
||||
continue
|
||||
}
|
||||
if isReparted, _ := b.isPeerReparted(peerID); isReparted {
|
||||
return peerID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// isPeerReparted vérifie si le peerID désigne un peer distant (Relation != 1).
|
||||
// Un peerID vide signifie exécution locale : retourne false sans appel réseau.
|
||||
func (b *ArgoBuilder) isPeerReparted(peerID string) (bool, *peer.Peer) {
|
||||
@@ -725,7 +1002,7 @@ func waitForConsiders(executionsId string, dataType tools.DataType, event ArgoKu
|
||||
}
|
||||
|
||||
// ArgoKubeEvent est la structure publiée sur NATS lors de la demande de
|
||||
// provisionnement d'une ressource distante (Admiralty ou stockage S3).
|
||||
// provisionnement d'une ressource distante (Admiralty, stockage S3, ou source privée).
|
||||
// Le champ OriginID identifie le peer initiateur : c'est vers lui que la
|
||||
// réponse PB_CONSIDERS sera routée par le système de propagation.
|
||||
type ArgoKubeEvent struct {
|
||||
@@ -733,7 +1010,8 @@ type ArgoKubeEvent struct {
|
||||
ExecutionsID string `json:"executions_id"`
|
||||
// DestPeerID est le peer de destination (compute ou peer S3 cible).
|
||||
DestPeerID string `json:"dest_peer_id"`
|
||||
// Type indique la nature de la ressource : COMPUTE_RESOURCE ou STORAGE_RESOURCE.
|
||||
// Type indique la nature de la ressource : COMPUTE_RESOURCE, STORAGE_RESOURCE
|
||||
// ou PROCESSING_RESOURCE (source privée Phase 4).
|
||||
Type tools.DataType `json:"data_type"`
|
||||
// SourcePeerID est le peer source de la ressource demandée.
|
||||
SourcePeerID string `json:"source_peer_id"`
|
||||
@@ -747,8 +1025,11 @@ type ArgoKubeEvent struct {
|
||||
// StorageName est le nom normalisé du storage, utilisé pour calculer le claimName.
|
||||
StorageName string `json:"storage_name,omitempty"`
|
||||
// Images est la liste des images de conteneurs à pre-pull sur le peer cible
|
||||
// avant le démarrage du workflow. Vide pour les events STORAGE_RESOURCE.
|
||||
// avant le démarrage du workflow. Vide pour les events STORAGE_RESOURCE / PROCESSING_RESOURCE.
|
||||
Images []string `json:"images,omitempty"`
|
||||
// SourceResourceID est l'ID de la ressource Processing/Data dont on demande
|
||||
// une URL pré-signée (Phase 4, isReachable=false uniquement).
|
||||
SourceResourceID string `json:"source_resource_id,omitempty"`
|
||||
}
|
||||
|
||||
// addPeerImage enregistre une image à pre-pull pour un peer donné.
|
||||
@@ -768,7 +1049,6 @@ func (b *ArgoBuilder) addPeerImage(peerID, image string) {
|
||||
b.PeerImages[peerID] = append(b.PeerImages[peerID], image)
|
||||
}
|
||||
|
||||
|
||||
// CompleteBuild finalise la construction du workflow Argo après la génération
|
||||
// du DAG. Elle effectue dans l'ordre :
|
||||
// 1. Pour chaque peer distant (Admiralty) : publie un ArgoKubeEvent de type
|
||||
|
||||
Reference in New Issue
Block a user