2 Commits

Author SHA1 Message Date
pb
f9e5c591bd added conf/ and configuration logic 2024-07-03 10:22:22 +02:00
pb
dd6f112954 Dockerfile for scheduler 2024-07-03 10:21:17 +02:00
12 changed files with 104 additions and 19 deletions

2
.gitignore vendored
View File

@@ -23,5 +23,5 @@ go.work
__debug_bin
workflows_argo/
argo_workflows/*
*.xml

18
Dockerfile Normal file
View File

@@ -0,0 +1,18 @@
FROM golang:alpine AS builder
LABEL maintainer="IRT PFN"
ENV DOCKER_ENVIRONMENT=true
WORKDIR /app
COPY . .
COPY conf/docker_scheduler.json /etc/oc/scheduler.json
RUN go build .
FROM golang:alpine
WORKDIR /app
COPY --from=builder /app/oc-scheduler .
COPY conf/docker_scheduler.json /etc/oc/scheduler.json
ENTRYPOINT ["/app/oc-scheduler"]

View File

@@ -61,7 +61,7 @@ func (b *ArgoBuilder) CreateDAG() bool {
// Give a unique name to each argo file with its timestamp DD:MM:YYYY_hhmmss
current_timestamp := time.Now().Format("02_01_2006_150405")
file_name := random_name + "_" + current_timestamp + ".yml"
workflows_dir := "workflows_argo/"
workflows_dir := "argo_workflows/"
err = os.WriteFile(workflows_dir + file_name , []byte(yamlified), 0660)
if err != nil {
logs.Error("Could not write the yaml file")

58
conf/conf.go Normal file
View File

@@ -0,0 +1,58 @@
package conf
import (
"sync"
"github.com/beego/beego/logs"
"github.com/goraz/onion"
)
type Config struct {
OcCatalogUrl string
Logs string
}
var instance *Config
var once sync.Once
const defaultConfigFile = "/etc/oc/scheduler.json"
const localConfigFile = "./conf/local_scheduler.json"
func init(){
configFile := ""
var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULER_")
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
if err == nil {
logs.Info("Config file found : " + defaultConfigFile)
configFile = defaultConfigFile
}
l1, err := onion.NewFileLayer(localConfigFile, nil)
if err == nil {
logs.Info("Local config file found " + localConfigFile + ", overriding default file")
configFile = localConfigFile
}
if configFile == "" {
logs.Info("No config file found, using env")
o = onion.New(l3)
} else if l1 == nil && l2 == nil {
o = onion.New(l1, l2, l3)
} else if l1 == nil {
o = onion.New(l2, l3)
} else if l2 == nil {
o = onion.New(l1, l3)
}
GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "https://localhost:49618")
GetConfig().Logs = o.GetStringDefault("loglevel", "info")
}
func GetConfig() *Config {
once.Do(func() {
instance = &Config{}
})
return instance
}

View File

@@ -0,0 +1,3 @@
{
"oc-catalog" : "http://oc-catalog:49618/"
}

View File

@@ -0,0 +1,3 @@
{
"oc-catalog" : "http://localhost:49618/"
}

1
go.mod
View File

@@ -16,6 +16,7 @@ require (
github.com/Klathmon/StructToMap v0.0.0-20140724123129-3d0229e2dce7 // indirect
github.com/antihax/optional v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.36.29 // indirect
github.com/beego/beego v1.12.12 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect

1
go.sum
View File

@@ -33,6 +33,7 @@ github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/
github.com/aws/aws-sdk-go v1.36.29 h1:lM1G3AF1+7vzFm0n7hfH8r2+750BTo+6Lo6FtPB7kzk=
github.com/aws/aws-sdk-go v1.36.29/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/beego/beego v1.12.12 h1:ARY1sNVSS23N0mEQIhSqRDTyyDlx95JY0V3GogBbZbQ=
github.com/beego/beego v1.12.12/go.mod h1:QURFL1HldOcCZAxnc1cZ7wrplsYR5dKPHFjmk6WkLAs=
github.com/beego/beego/v2 v2.0.1/go.mod h1:8zyHi1FnWO1mZLwTn62aKRIZF/aIKvkCBB2JYs+eqQI=
github.com/beego/beego/v2 v2.2.0 h1:x2yCNL9x74vqAXRdFBw5HCzB8AwownALpBWEOitivow=

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"maps"
"net/url"
"os"
"cloud.o-forge.io/core/oc-catalog/models"
@@ -24,7 +23,7 @@ type Graph struct {
ws HttpQuery
}
// Create a dictionnaries with each each existing workflow from a workspace, associated to the JSON representation of its content
// Create a dictionnaries with each existing workflow from a workspace, associated to the JSON representation of its content
func (g *Graph) GetGraphList(apiurl string) (map[string]string, error) {
g.ws.Init(apiurl)
body, err := g.ws.Get("v1/workspace/list")
@@ -48,8 +47,9 @@ func (g *Graph) LoadFrom(workspace string) error {
if err != nil {
return err
}
_ = decodedValue
os.WriteFile("graph.xml", []byte(decodedValue), 0660)
// os.WriteFile("graph.xml", []byte(decodedValue), 0660)
g.GetWorkflowComponents(workspace)
g.GetLinks(workspace)

29
main.go
View File

@@ -5,7 +5,8 @@ import (
"os"
"time"
"github.com/goraz/onion"
conf "oc-scheduler/conf"
"github.com/rs/zerolog"
)
@@ -15,32 +16,32 @@ func main() {
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
log = zerolog.New(output).With().Timestamp().Logger()
var o *onion.Onion
l2 := onion.NewEnvLayerPrefix("_", "OC-SCHED")
l1, err := onion.NewFileLayer("config.json", nil)
if err != nil {
log.Info().Msg("no config file found, using env")
o = onion.New(l2)
} else {
o = onion.New(l1, l2)
}
loglevel := o.GetStringDefault("loglevel", "info")
apiurl := o.GetStringDefault("apiurl", "http://localhost:49618/")
_ = loglevel
app_conf := conf.GetConfig()
apiurl := app_conf.OcCatalogUrl
var g Graph
list, err := g.GetGraphList(apiurl)
if err != nil {
log.Fatal().Msg("Failed to get the workspaces list, check api url and that api server is up : " + apiurl)
}
println("Available workspaces :")
for workspace, _ := range list {
println(workspace)
}
if _, err := os.Stat("./argo_workflows/"); os.IsNotExist(err) {
os.Mkdir("./argo_workflows/",0755)
log.Info().Msg("Created argo_workflows/")
}
g.LoadFrom(list["test-alpr"])
g.ExportToArgo("test-alpr")
for(1 == 1){
fmt.Print("")
}
fmt.Print("stop")
}

BIN
oc-scheduler Executable file

Binary file not shown.