Scheduling is decharged of API Call Datacentering + charged of booking

This commit is contained in:
mr
2026-02-25 09:04:48 +01:00
parent c8b8955c4b
commit 29623244c4
10 changed files with 512 additions and 277 deletions

View File

@@ -1,8 +1,10 @@
package infrastructure
import (
"context"
"encoding/json"
"fmt"
"oc-scheduler/conf"
"slices"
"sync"
"time"
@@ -471,6 +473,7 @@ func confirmResource(id string, dt tools.DataType) {
fmt.Printf("confirmResource: could not confirm booking %s: %v\n", id, err)
return
}
createNamespace(bk.ExecutionsID) // create Namespace locally
self, err := oclib.GetMySelf()
if err == nil && self != nil {
go refreshSelfPlanner(self.PeerID, adminReq)
@@ -641,3 +644,55 @@ func broadcastPlanner(wf *workflow.Workflow) {
}
}
}
func createNamespace(ns string) error {
/*
* This function is used to create a namespace.
* It takes the following parameters:
* - ns: the namespace you want to create
*/
logger := oclib.GetLogger()
serv, err := tools.NewKubernetesService(
conf.GetConfig().KubeHost+":"+conf.GetConfig().KubePort, conf.GetConfig().KubeCA,
conf.GetConfig().KubeCert, conf.GetConfig().KubeData)
if err != nil {
return nil
}
c := context.Background()
ok, err := serv.GetNamespace(c, ns)
if ok != nil && err == nil {
logger.Debug().Msg("A namespace with name " + ns + " already exists")
return nil
}
if err != nil {
return err
}
err = serv.CreateNamespace(c, ns)
if err != nil {
return err
}
err = serv.CreateServiceAccount(c, ns)
if err != nil {
return err
}
role := "argo-role"
err = serv.CreateRole(c, ns, role,
[][]string{
{"coordination.k8s.io"},
{""},
{""}},
[][]string{
{"leases"},
{"secrets"},
{"pods"}},
[][]string{
{"get", "create", "update"},
{"get"},
{"patch"}})
if err != nil {
return err
}
return serv.CreateRoleBinding(c, ns, "argo-role-binding", role)
}