From e2ceb6e58d5521aa9aee533c4dc941bf0351dd8e Mon Sep 17 00:00:00 2001 From: pb Date: Mon, 14 Apr 2025 18:20:49 +0200 Subject: [PATCH] Adapted some of the steps of the executeInside()'s method to work with the updated Admiralty environment, using execution id as namespace, serviceAccount naming convention and adding the serviceAccount in the workflow's YAML. Logging not working yet. --- README.md | 12 +++++++++--- conf/conf.go | 1 + main.go | 13 +++++++++---- tools/kubernetes.go | 3 ++- workflow_builder/argo_builder.go | 12 +++++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 23a80f7..f71c870 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,17 @@ In rules add a new entry : This command **must return "yes"** +# Notes features/admiralty-docker + +- When executing monitord as a container we need to change any url with "localhost" to the container's host IP. + + We can : + - declare a new parameter 'HOST_IP' + - decide that no peer can have "http://localhost" as its url and use an attribute from the peer object or isMyself() from oc-lib if a peer is the current host. + + ## TODO -- [ ] Logs the output of each pods : - - logsPods() function already exists - - need to implement the logic to create each pod's logger and start the monitoring routing - [ ] Allow the front to known on which IP the service are reachable - currently doing it by using `kubectl get nodes -o wide` diff --git a/conf/conf.go b/conf/conf.go index 860605b..0893916 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -18,6 +18,7 @@ type Config struct { KubeCA string KubeCert string KubeData string + ArgoHost string // when executed in a container will replace addresses with "localhost" in their url } var instance *Config diff --git a/main.go b/main.go index b2ae16b..f7ad03e 100644 --- a/main.go +++ b/main.go @@ -96,12 +96,12 @@ func main() { logger.Error().Msg(err.Error()) } - argo_file_path, err := builder.CompleteBuild(exec.ExecutionsID) + argoFilePath, err := builder.CompleteBuild(exec.ExecutionsID) if err != nil { logger.Error().Msg(err.Error()) } - workflowName = getContainerName(argo_file_path) + workflowName = getContainerName(argoFilePath) wf_logger = logger.With().Str("argo_name", workflowName).Str("workflow_id", conf.GetConfig().WorkflowID).Str("workflow_execution_id", conf.GetConfig().ExecutionID).Logger() wf_logger.Debug().Msg("Testing argo name") @@ -110,11 +110,12 @@ func main() { if conf.GetConfig().KubeHost == "" { // Not in a k8s environment, get conf from parameters fmt.Println("Executes outside of k8s") - executeOutside(argo_file_path, stepMax, builder.Workflow) + executeOutside(argoFilePath, stepMax, builder.Workflow) } else { // Executed in a k8s environment fmt.Println("Executes inside a k8s") - executeInside(exec.GetID(), "argo", argo_file_path, stepMax) + // executeInside(exec.GetID(), "argo", argo_file_path, stepMax) // commenting to use conf.ExecutionID instead of exec.GetID() + executeInside(conf.GetConfig().ExecutionID, conf.GetConfig().ExecutionID, argoFilePath, stepMax) } } @@ -294,6 +295,8 @@ func setConf(is_k8s bool, o *onion.Onion, parser *argparse.Parser) { host := parser.String("H", "host", &argparse.Options{Required: false, Default: "", Help: "Host for the Kubernetes cluster"}) port := parser.String("P", "port", &argparse.Options{Required: false, Default: "6443", Help: "Port for the Kubernetes cluster"}) + // argoHost := parser.String("h", "argoHost", &argparse.Options{Required: false, Default: "", Help: "Host where Argo is running from"}) // can't use -h because its reserved to help + err := parser.Parse(os.Args) if err != nil { fmt.Println(parser.Usage(err)) @@ -311,6 +314,8 @@ func setConf(is_k8s bool, o *onion.Onion, parser *argparse.Parser) { conf.GetConfig().KubeHost = *host conf.GetConfig().KubePort = *port + // conf.GetConfig().ArgoHost = *argoHost + decoded, err := base64.StdEncoding.DecodeString(*ca) if err == nil { conf.GetConfig().KubeCA = string(decoded) diff --git a/tools/kubernetes.go b/tools/kubernetes.go index d92171b..2b096be 100644 --- a/tools/kubernetes.go +++ b/tools/kubernetes.go @@ -52,6 +52,7 @@ func NewKubernetesTool() (Tool, error) { if err != nil { return nil, errors.New("Error creating Kubernetes versionned client: " + err.Error()) } + return &KubernetesTools{ Set: clientset, VersionedSet: clientset2, @@ -149,7 +150,7 @@ func (k *KubernetesTools) CreateArgoWorkflow(path string, ns string) (string, er if err != nil { return "", errors.New("failed to create workflow: " + err.Error()) } - fmt.Printf("workflow %s created in namespace %s\n", createdWf.Name, "argo") + fmt.Printf("workflow %s created in namespace %s\n", createdWf.Name, ns) return createdWf.Name, nil } diff --git a/workflow_builder/argo_builder.go b/workflow_builder/argo_builder.go index 5631c26..731a22c 100644 --- a/workflow_builder/argo_builder.go +++ b/workflow_builder/argo_builder.go @@ -53,11 +53,12 @@ func (b *Workflow) getDag() *Dag { } type Spec struct { - Entrypoint string `yaml:"entrypoint"` - Arguments []Parameter `yaml:"arguments,omitempty"` - Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"` - Templates []Template `yaml:"templates"` - Timeout int `yaml:"activeDeadlineSeconds,omitempty"` + ServiceAccountName string `yaml:"serviceAccountName"` + Entrypoint string `yaml:"entrypoint"` + Arguments []Parameter `yaml:"arguments,omitempty"` + Volumes []VolumeClaimTemplate `yaml:"volumeClaimTemplates,omitempty"` + Templates []Template `yaml:"templates"` + Timeout int `yaml:"activeDeadlineSeconds,omitempty"` } // TODO: found on a processing instance linked to storage @@ -72,6 +73,7 @@ func (b *ArgoBuilder) CreateDAG(namespace string, write bool) ( int, []string, [ if b.Timeout > 0 { b.Workflow.Spec.Timeout = b.Timeout } + b.Workflow.Spec.ServiceAccountName = "sa-"+namespace b.Workflow.Spec.Entrypoint = "dag" b.Workflow.ApiVersion = "argoproj.io/v1alpha1" b.Workflow.Kind = "Workflow"