Dockerfile for scheduler

This commit is contained in:
pb 2024-07-03 10:21:17 +02:00
parent eab5162389
commit dd6f112954
10 changed files with 177 additions and 15 deletions

2
.gitignore vendored
View File

@ -23,5 +23,5 @@ go.work
__debug_bin __debug_bin
workflows_argo/ argo_workflows/*
*.xml *.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"]

59
conf/conf.go Normal file
View File

@ -0,0 +1,59 @@
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 = "/app/conf/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/"
}

View File

@ -0,0 +1,86 @@
@startuml
namespace main {
class ArgoBuilder << (S,Aquamarine) >> {
- graph Graph
- branches [][]string
+ Workflow Workflow
- createTemplates()
- createDAGstep()
- createVolumes()
- getDependency(current_computing_id string) []string
+ CreateDAG() bool
}
class Container << (S,Aquamarine) >> {
+ Image string
+ Command []string
+ Args []string
+ VolumeMounts []VolumeMount
}
class Dag << (S,Aquamarine) >> {
+ Tasks []Task
}
class Link << (S,Aquamarine) >> {
+ Src string
+ Dst string
}
class Parameter << (S,Aquamarine) >> {
+ Name string
+ Value string
}
class Spec << (S,Aquamarine) >> {
+ Entrypoint string
+ Arguments []Parameter
+ Volumes []VolumeClaimTemplate
+ Templates []Template
}
class Task << (S,Aquamarine) >> {
+ Name string
+ Template string
+ Dependencies []string
+ Arguments <font color=blue>struct</font>{[]Parameter}
}
class Template << (S,Aquamarine) >> {
+ Name string
+ Inputs <font color=blue>struct</font>{[]Parameter}
+ Container Container
+ Dag Dag
}
class VolumeClaimTemplate << (S,Aquamarine) >> {
+ Metadata <font color=blue>struct</font>{string}
+ Spec VolumeSpec
}
class VolumeMount << (S,Aquamarine) >> {
+ Name string
+ MountPath string
}
class VolumeSpec << (S,Aquamarine) >> {
+ AccessModes []string
+ Resources <font color=blue>struct</font>{<font color=blue>struct</font>{string}}
}
class Workflow << (S,Aquamarine) >> {
+ ApiVersion string
+ Kind string
+ Metadata <font color=blue>struct</font>{string}
+ Spec Spec
}
}
@enduml

1
go.mod
View File

@ -16,6 +16,7 @@ require (
github.com/Klathmon/StructToMap v0.0.0-20140724123129-3d0229e2dce7 // indirect github.com/Klathmon/StructToMap v0.0.0-20140724123129-3d0229e2dce7 // indirect
github.com/antihax/optional v1.0.0 // indirect github.com/antihax/optional v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.36.29 // 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/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-stack/stack v1.8.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 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 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/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 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.0.1/go.mod h1:8zyHi1FnWO1mZLwTn62aKRIZF/aIKvkCBB2JYs+eqQI=
github.com/beego/beego/v2 v2.2.0 h1:x2yCNL9x74vqAXRdFBw5HCzB8AwownALpBWEOitivow= github.com/beego/beego/v2 v2.2.0 h1:x2yCNL9x74vqAXRdFBw5HCzB8AwownALpBWEOitivow=

17
main.go
View File

@ -5,7 +5,8 @@ import (
"os" "os"
"time" "time"
"github.com/goraz/onion" conf "oc-scheduler/conf"
"github.com/rs/zerolog" "github.com/rs/zerolog"
) )
@ -15,18 +16,8 @@ func main() {
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339} output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
log = zerolog.New(output).With().Timestamp().Logger() log = zerolog.New(output).With().Timestamp().Logger()
var o *onion.Onion app_conf := conf.GetConfig()
l2 := onion.NewEnvLayerPrefix("_", "OC-SCHED") apiurl := app_conf.OcCatalogUrl
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
var g Graph var g Graph

BIN
oc-scheduler Executable file

Binary file not shown.