Compare commits

..

12 Commits

Author SHA1 Message Date
mr
7a7364fb45 adjustment 2025-03-28 08:48:12 +01:00
mr
b4d57a8f2f oc-monitord 2025-03-24 09:23:03 +01:00
mr
907880bfd6 dev launch mode 2025-03-06 09:33:03 +01:00
mr
09b8046073 loki traefik + neo oclib 2025-02-21 11:24:56 +01:00
mr
90af391a0d oclib update 2025-02-19 12:06:56 +01:00
mr
88b2edee2f oclib update + casual debug 2025-02-18 15:00:17 +01:00
mr
88610c3dba Merge branch 'feature/order' into main 2025-02-18 08:31:54 +01:00
mr
b753523c35 Docker oc-schedulerd 2025-02-17 16:55:01 +01:00
mr
7246dea2b2 Mode in CMD 2025-02-14 11:59:32 +01:00
plm
8ddb119899 Use regular conf oclib library instead of custom implem to leverage env variable injection fonctionality; Dockerfile refactor 2025-01-14 18:33:51 +01:00
plm
7d78920304 Removing binary from conf 2025-01-13 12:15:44 +01:00
plm
b4cef41db2 Unique entry point + oclib dependency update 2025-01-13 12:15:08 +01:00
31 changed files with 196 additions and 1306 deletions

View File

@ -1,25 +1,41 @@
FROM golang:alpine AS builder FROM golang:alpine AS deps
LABEL maintainer="IRT PFN"
ENV DOCKER_ENVIRONMENT=true ARG MONITORD_IMAGE
WORKDIR /app WORKDIR /app
COPY go.mod go.sum ./
RUN sed -i '/replace/d' go.mod
RUN go mod download -x
#----------------------------------------------------------------------------------------------
FROM golang:alpine AS builder
WORKDIR /app
COPY --from=deps /go/pkg /go/pkg
COPY --from=deps /app/go.mod /app/go.sum ./
COPY . . COPY . .
RUN go build . RUN go build
FROM oc-monitord:latest AS monitord #----------------------------------------------------------------------------------------------
FROM ${MONITORD_IMAGE:-oc-monitord}:latest AS monitord
FROM argoproj/argocd:latest FROM scratch
ENV MONITORD_PATH = "./oc-monitord"
WORKDIR /app WORKDIR /app
COPY conf/docker_schedulerd.json /etc/oc/schedulerd.json COPY docker_schedulerd.json /etc/oc/schedulerd.json
COPY --from=monitord /app/oc-monitord . COPY --from=monitord /app/oc-monitord /usr/bin/oc-monitord
COPY --from=builder /app/oc-schedulerd . COPY --from=builder /app/oc-schedulerd /usr/bin/oc-schedulerd
COPY conf/docker_schedulerd.json /etc/oc/schedulerd.json
ENTRYPOINT ["/app/oc-schedulerd"] COPY docker_schedulerd.json /etc/oc/schedulerd.json
COPY argo_workflows .
EXPOSE 8080
ENTRYPOINT ["oc-schedulerd"]

29
Makefile Normal file
View File

@ -0,0 +1,29 @@
.DEFAULT_GOAL := all
build: clean
go build .
build-monitord:
go build -o ../oc-monitord ../oc-monitord
run:
./oc-schedulerd
clean:
rm -rf oc-schedulerd
docker:
DOCKER_BUILDKIT=1 docker build -t oc/oc-schedulerd:0.0.1 --build-arg MONITORD_IMAGE=oc/oc-monitord -f Dockerfile .
docker tag oc/oc-schedulerd:0.0.1 oc/oc-schedulerd:latest
publish-kind:
kind load docker-image oc/oc-schedulerd:0.0.1 --name opencloud
publish-registry:
@echo "TODO"
all: docker publish-kind publish-registry
dev: build-monitord build run
.PHONY: build run clean docker publish-kind publish-registry

View File

@ -2,6 +2,8 @@
OC-Scheduler retrieves the content of submitted workflows and prepare them to be executed. OC-Scheduler retrieves the content of submitted workflows and prepare them to be executed.
make dev
## Parsing ## Parsing
From a workflow's name we retrieve the xml graph associated and parse it in order to create the object representing each componant. From a workflow's name we retrieve the xml graph associated and parse it in order to create the object representing each componant.
@ -16,3 +18,6 @@ TODO :
- [ ] create an argo file from the graph/worfklow - [ ] create an argo file from the graph/worfklow
- [ ] Create a different entry for each component - [ ] Create a different entry for each component
- [ ] execute each element in the right order - [ ] execute each element in the right order
## CHANGE ENV FOR KUBE
Add your proper CA, Cert & Data + external IP for kube config.

View File

@ -14,6 +14,12 @@ type Config struct {
Logs string Logs string
LokiUrl string LokiUrl string
NatsUrl string NatsUrl string
Mode string
KubeHost string
KubePort string
KubeCA string
KubeCert string
KubeData string
} }
var instance *Config var instance *Config
@ -38,12 +44,6 @@ func init() {
o = onion.New(l2, l3) o = onion.New(l2, l3)
} }
GetConfig().MonitorPath = o.GetStringDefault("MONITORD_PATH", "../oc-monitord/oc-monitord") GetConfig().MonitorPath = o.GetStringDefault("MONITORD_PATH", "../oc-monitord/oc-monitord")
GetConfig().Logs = o.GetStringDefault("LOG_LEVEL", "info")
GetConfig().LokiUrl = o.GetStringDefault("LOKI_URL", "http://127.0.0.1:3100")
GetConfig().NatsUrl = o.GetStringDefault("NATS_URL", "http://127.0.0.1:4222")
GetConfig().MongoUrl = o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017")
GetConfig().DBName = o.GetStringDefault("MONGO_DATABASE", "DC_myDC")
} }
func GetConfig() *Config { func GetConfig() *Config {

View File

@ -1,6 +0,0 @@
{
"LOKI_URL" : "http://loki:3100",
"MONGO_URL":"mongodb://mongo:27017/",
"MONGO_DATABASE":"DC_myDC",
"NATS_URL": "nats://nats:4222"
}

View File

@ -1,67 +0,0 @@
package daemons
// type manifestValues struct{
// ARGO_FILE string
// LOKI_URL string
// CONTAINER_NAME string
// }
// manifest, err := em.CreateManifest(booking, argo_file_path)
// if err != nil {
// logger.Logger.Error().Msg("Could not create manifest " + err.Error())
// }
// // launch a pod that contains oc-monitor, give it the name of the workflow
// cmd := exec.Command("kubectl","apply","-f", "manifests/"+manifest)
// output , err := cmd.CombinedOutput()
// if err != nil {
// logger.Logger.Error().Msg("failed to create new pod for " + booking.Workflow + " :" + err.Error())
// return
// }
// func (*ExecutionManager) CreateManifest(booking models.Booking, argo_file string) (manifest_filepath string, err error) {
// var filled_template bytes.Buffer
// manifest_file, err := os.ReadFile("conf/monitor_pod_template.yml")
// if err != nil {
// logger.Logger.Error().Msg("Could not open the k8s template file for " + booking.Workflow)
// return "", err
// }
// container_name := getContainerName(argo_file)
// tmpl, err := template.New("manifest_template").Parse(string(manifest_file))
// if err != nil {
// logger.Logger.Error().Msg(err.Error())
// return "", err
// }
// manifest_data := manifestValues{
// ARGO_FILE: argo_file,
// LOKI_URL: conf.GetConfig().Logs,
// CONTAINER_NAME: container_name,
// }
// err = tmpl.Execute(&filled_template, manifest_data)
// if err != nil {
// logger.Logger.Error().Msg("Could not complete manifest template for " + booking.Workflow)
// return "", err }
// manifest_filepath = booking.Workflow + "_manifest.yaml"
// err = os.WriteFile("manifests/" + manifest_filepath, filled_template.Bytes(),0644)
// if err != nil {
// logger.Logger.Error().Msg("Could not write the YAML file for " + booking.Workflow + "'s manifest")
// return "", err
// }
// return manifest_filepath, nil
// }
// func getContainerName(argo_file string) string {
// regex := "([a-zA-Z]+-[a-zA-Z]+)"
// re := regexp.MustCompile(regex)
// container_name := re.FindString(argo_file)
// return container_name
// }

View File

@ -9,8 +9,6 @@ import (
) )
type LocalMonitor struct { type LocalMonitor struct {
LokiURL string
KubeURL string
ExecutionID string ExecutionID string
PeerID string PeerID string
Duration int Duration int
@ -18,20 +16,22 @@ type LocalMonitor struct {
} }
func (lm *LocalMonitor) LaunchLocalMonitor() { func (lm *LocalMonitor) LaunchLocalMonitor() {
if lm.LokiURL == "" || lm.KubeURL == "" || lm.ExecutionID == "" { if lm.ExecutionID == "" {
lm.Logger.Error().Msg("Missing parameter in LocalMonitor") lm.Logger.Error().Msg("Missing parameter in LocalMonitor")
} }
lm.execKube()
// For dev purposes, in prod KubeURL must be a kube API's URL
if lm.KubeURL != "localhost" {
lm.execRemoteKube()
} else {
lm.execLocalKube()
}
} }
func (lm *LocalMonitor) execLocalKube() { func (lm *LocalMonitor) execKube() {
args := []string{"-e", lm.ExecutionID, "-p", lm.PeerID, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName} args := []string{
"-e", lm.ExecutionID, "-p", lm.PeerID, "-u", conf.GetConfig().LokiUrl, "-m", conf.GetConfig().MongoUrl,
"-d", conf.GetConfig().DBName,
}
if conf.GetConfig().Mode == "kubernetes" {
args = append(args, []string{"-M", conf.GetConfig().Mode, "-H", conf.GetConfig().KubeHost, "-P", conf.GetConfig().KubePort,
"-C", conf.GetConfig().KubeCert, "-D", conf.GetConfig().KubeData, "-c", conf.GetConfig().KubeCA}...)
}
if lm.Duration > 0 { if lm.Duration > 0 {
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration)) args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
} }
@ -42,6 +42,3 @@ func (lm *LocalMonitor) execLocalKube() {
lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error()) lm.Logger.Error().Msg("Could not start oc-monitor for " + lm.ExecutionID + " : " + err.Error())
} }
} }
// TODO : implement this
func (lm *LocalMonitor) execRemoteKube() {}

View File

@ -2,7 +2,6 @@ package daemons
import ( import (
"fmt" "fmt"
"oc-schedulerd/conf"
"os" "os"
"time" "time"
@ -10,33 +9,33 @@ import (
workflow_execution "cloud.o-forge.io/core/oc-lib/models/workflow_execution" workflow_execution "cloud.o-forge.io/core/oc-lib/models/workflow_execution"
) )
var Bookings = ScheduledBooking{Bookings: []*workflow_execution.WorkflowExecutions{}} var Executions = ScheduledExecution{Execs: []*workflow_execution.WorkflowExecution{}}
type ExecutionManager struct{} type ExecutionManager struct{}
// Loop every second on the booking's list and move the booking that must start to a new list // Loop every second on the Execution's list and move the Execution that must start to a new list
// that will be looped over to start them // that will be looped over to start them
func (em *ExecutionManager) RetrieveNextExecutions() { func (em *ExecutionManager) RetrieveNextExecutions() {
logger := oclib.GetLogger() logger := oclib.GetLogger()
for { for {
fmt.Println("Checking for bookings", len(Bookings.Bookings)) fmt.Println("Checking for executions", len(Executions.Execs))
Bookings.Mu.Lock() Executions.Mu.Lock()
if len(Bookings.Bookings) > 0 { if len(Executions.Execs) > 0 {
bookings := Bookings.Bookings executions := Executions.Execs
for i := len(bookings) - 1; i >= 0; i-- { for i := len(executions) - 1; i >= 0; i-- {
if bookings[i].ExecDate.Before(time.Now().UTC()) { if executions[i].ExecDate.Before(time.Now().UTC()) {
logger.Info().Msg("Will execute " + bookings[i].UUID + " soon") logger.Info().Msg("Will execute " + executions[i].UUID + " soon")
go em.executeBooking(bookings[i]) go em.executeExecution(executions[i])
Bookings.Bookings = append(bookings[:i], bookings[i+1:]...) Executions.Execs = append(executions[:i], executions[i+1:]...)
} }
} }
} }
Bookings.Mu.Unlock() Executions.Mu.Unlock()
time.Sleep(time.Second) time.Sleep(time.Second)
} }
} }
func (em *ExecutionManager) executeBooking(booking *workflow_execution.WorkflowExecutions) { func (em *ExecutionManager) executeExecution(Execution *workflow_execution.WorkflowExecution) {
// start execution // start execution
// create the yaml that describes the pod : filename, path/url to Loki // create the yaml that describes the pod : filename, path/url to Loki
exec_method := os.Getenv("MONITOR_METHOD") exec_method := os.Getenv("MONITOR_METHOD")
@ -46,16 +45,14 @@ func (em *ExecutionManager) executeBooking(booking *workflow_execution.WorkflowE
} else { } else {
logger.Debug().Msg("Executing oc-monitor localy") logger.Debug().Msg("Executing oc-monitor localy")
duration := 0 duration := 0
if booking.EndDate != nil { if Execution.EndDate != nil {
duration = int(booking.EndDate.Sub(booking.ExecDate).Seconds()) duration = int(Execution.EndDate.Sub(Execution.ExecDate).Seconds())
} }
monitor := LocalMonitor{ monitor := LocalMonitor{
Logger: logger, Logger: logger,
Duration: duration, Duration: duration,
LokiURL: conf.GetConfig().LokiUrl, ExecutionID: Execution.UUID,
KubeURL: "localhost", PeerID: Execution.CreatorID,
ExecutionID: booking.UUID,
PeerID: booking.CreatorID,
} }
monitor.LaunchLocalMonitor() monitor.LaunchLocalMonitor()
} }

View File

@ -3,7 +3,6 @@ package daemons
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"oc-schedulerd/conf"
"sync" "sync"
"time" "time"
@ -17,36 +16,36 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
) )
type ScheduledBooking struct { type ScheduledExecution struct {
Bookings []*workflow_execution.WorkflowExecutions Execs []*workflow_execution.WorkflowExecution
Mu sync.Mutex Mu sync.Mutex
} }
func (sb *ScheduledBooking) DeleteSchedules(workflow_id string) { func (sb *ScheduledExecution) DeleteSchedules(workflow_id string) {
toNotDelete := []*workflow_execution.WorkflowExecutions{} toNotDelete := []*workflow_execution.WorkflowExecution{}
for _, b := range sb.Bookings { for _, b := range sb.Execs {
if b.WorkflowID != workflow_id { if b.WorkflowID != workflow_id {
toNotDelete = append(toNotDelete, b) toNotDelete = append(toNotDelete, b)
} }
} }
Bookings.Mu.Lock() Executions.Mu.Lock()
defer Bookings.Mu.Unlock() defer Executions.Mu.Unlock()
sb.Bookings = toNotDelete sb.Execs = toNotDelete
} }
func (sb *ScheduledBooking) AddSchedules(new_bookings []*workflow_execution.WorkflowExecutions, logger zerolog.Logger) { func (sb *ScheduledExecution) AddSchedules(new_executions []*workflow_execution.WorkflowExecution, logger zerolog.Logger) {
Bookings.Mu.Lock() Executions.Mu.Lock()
defer Bookings.Mu.Unlock() defer Executions.Mu.Unlock()
for _, exec := range new_bookings { for _, exec := range new_executions {
fmt.Println("Adding "+exec.UUID, !sb.execIsSet(exec)) fmt.Println("Adding "+exec.UUID, !sb.execIsSet(exec))
if !sb.execIsSet(exec) { if !sb.execIsSet(exec) {
sb.Bookings = append(sb.Bookings, exec) sb.Execs = append(sb.Execs, exec)
} }
} }
} }
func (sb *ScheduledBooking) execIsSet(exec *workflow_execution.WorkflowExecutions) bool { func (sb *ScheduledExecution) execIsSet(exec *workflow_execution.WorkflowExecution) bool {
for _, b := range sb.Bookings { for _, b := range sb.Execs {
if b.Equals(exec) { if b.Equals(exec) {
return true return true
} }
@ -66,7 +65,7 @@ type ScheduleManager struct {
// on workflows' scheduling. Messages must contain // on workflows' scheduling. Messages must contain
// workflow execution ID, to allow retrieval of execution infos // workflow execution ID, to allow retrieval of execution infos
func (s *ScheduleManager) ListenNATS() { func (s *ScheduleManager) ListenNATS() {
nc, err := nats.Connect(conf.GetConfig().NatsUrl) nc, err := nats.Connect(oclib.GetConfig().NATSUrl)
if err != nil { if err != nil {
s.Logger.Error().Msg("Could not connect to NATS") s.Logger.Error().Msg("Could not connect to NATS")
return return
@ -102,7 +101,7 @@ func (s *ScheduleManager) listenForChange(nc *nats.Conn, chanName string, delete
} }
fmt.Println("Catching " + str + " workflow... " + map_mess["id"]) fmt.Println("Catching " + str + " workflow... " + map_mess["id"])
if delete { if delete {
Bookings.DeleteSchedules(map_mess["id"]) Executions.DeleteSchedules(map_mess["id"])
} else { } else {
s.getNextScheduledWorkflows(1) s.getNextScheduledWorkflows(1)
} }
@ -115,11 +114,11 @@ func (s *ScheduleManager) SchedulePolling() {
var sleep_time float64 = 1 var sleep_time float64 = 1
for { for {
s.getNextScheduledWorkflows(1) s.getNextScheduledWorkflows(1)
s.Logger.Info().Msg("Current list of schedules -------> " + fmt.Sprintf("%v", len(Bookings.Bookings))) s.Logger.Info().Msg("Current list of schedules -------> " + fmt.Sprintf("%v", len(Executions.Execs)))
time.Sleep(time.Minute * time.Duration(sleep_time)) time.Sleep(time.Minute * time.Duration(sleep_time))
} }
} }
func (s *ScheduleManager) getExecution(from time.Time, to time.Time) (exec_list []*workflow_execution.WorkflowExecutions, err error) { func (s *ScheduleManager) getExecution(from time.Time, to time.Time) (exec_list []*workflow_execution.WorkflowExecution, err error) {
fmt.Printf("Getting workflows execution from %s to %s \n", from.String(), to.String()) fmt.Printf("Getting workflows execution from %s to %s \n", from.String(), to.String())
f := dbs.Filters{ f := dbs.Filters{
And: map[string][]dbs.Filter{ And: map[string][]dbs.Filter{
@ -133,7 +132,7 @@ func (s *ScheduleManager) getExecution(from time.Time, to time.Time) (exec_list
return return
} }
for _, exec := range res.Data { for _, exec := range res.Data {
exec_list = append(exec_list, exec.(*workflow_execution.WorkflowExecutions)) exec_list = append(exec_list, exec.(*workflow_execution.WorkflowExecution))
} }
fmt.Println("Found "+fmt.Sprintf("%v", len(exec_list))+" workflows", res) fmt.Println("Found "+fmt.Sprintf("%v", len(exec_list))+" workflows", res)
return return
@ -151,6 +150,6 @@ func (s *ScheduleManager) getNextScheduledWorkflows(minutes float64) {
); err != nil { ); err != nil {
s.Logger.Error().Msg("Could not retrieve next schedules") s.Logger.Error().Msg("Could not retrieve next schedules")
} else { } else {
Bookings.AddSchedules(next_wf_exec, s.Logger) Executions.AddSchedules(next_wf_exec, s.Logger)
} }
} }

View File

@ -1,36 +0,0 @@
version: '3.4'
services:
nats:
image: 'nats:latest'
container_name: nats
ports:
- 4222:4222
command:
- "--debug"
networks:
- catalog
loki:
image: 'grafana/loki'
container_name: loki
ports :
- "3100:3100"
networks:
- catalog
grafana:
image: 'grafana/grafana'
container_name: grafana
ports:
- '3000:3000'
networks:
- catalog
volumes:
- ./conf/grafana_data_source.yml:/etc/grafana/provisioning/datasources/datasource.yml
environment:
- GF_SECURITY_ADMIN_PASSWORD=pfnirt # Change this to anything but admin to not have a password change page at startup
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_DISABLE_INITIAL_ADMIN_PASSWORD_CHANGE=true
networks:
catalog:
external: true

View File

@ -4,13 +4,16 @@ services:
oc-schedulerd: oc-schedulerd:
environment: environment:
- MONGO_DATABASE=DC_myDC - MONGO_DATABASE=DC_myDC
- KUBERNETES_SERVICE_HOST=${KUBERNETES_SERVICE_HOST:-193.50.43.14}
- KUBE_CA=${KUBE_CA:-LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrVENDQVRlZ0F3SUJBZ0lJWUxWNkFPQkdrU1F3Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTnNhV1Z1ZEMxallVQXhOekl6TVRFeU1ETTJNQjRYRFRJME1EZ3dPREV3TVRNMU5sb1hEVEkxTURndwpPREV3TVRNMU5sb3dNREVYTUJVR0ExVUVDaE1PYzNsemRHVnRPbTFoYzNSbGNuTXhGVEFUQmdOVkJBTVRESE41CmMzUmxiVHBoWkcxcGJqQlpNQk1HQnlxR1NNNDlBZ0VHQ0NxR1NNNDlBd0VIQTBJQUJGQ2Q1MFdPeWdlQ2syQzcKV2FrOWY4MVAvSkJieVRIajRWOXBsTEo0ck5HeHFtSjJOb2xROFYxdUx5RjBtOTQ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EVGF1R2p3cFk9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K}
- KUBE_TOKEN=${KUBE_TOKEN:-LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSU5ZS1BFb1dhd1NKUzJlRW5oWmlYMk5VZlY1ZlhKV2krSVNnV09TNFE5VTlvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFVUozblJZN0tCNEtUWUx0WnFUMS96VS84a0Z2Sk1lUGhYMm1Vc25pczBiR3FZblkyaVZEeApYVzR2SVhTYjNqcm9iZ1YwSUtDT0twUWs2OHJEbE03ckRBPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=}
image: 'oc-schedulerd:latest' image: 'oc-schedulerd:latest'
ports: ports:
- 9001:8080 - 9001:8080
container_name: oc-schedulerd container_name: oc-schedulerd
networks: networks:
- catalog - oc
networks: networks:
catalog: oc:
external: true external: true

13
docker_schedulerd.json Normal file
View File

@ -0,0 +1,13 @@
{
"LOKI_URL" : "http://loki:3100",
"MONGO_URL":"mongodb://mongo:27017/",
"NATS_URL":"nats://nats:4222",
"MONGO_DATABASE":"DC_myDC",
"MONITORD_PATH": "oc-monitord",
"KUBERNETES_SERVICE_HOST" : "192.168.47.41",
"MODE": "kubernetes",
"KUBE_CA" : "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUzTWpNeE1USXdNell3SGhjTk1qUXdPREE0TVRBeE16VTJXaGNOTXpRd09EQTJNVEF4TXpVMgpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUzTWpNeE1USXdNell3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTVlk3ZHZhNEdYTVdkMy9jMlhLN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DkKQXdFSG9VUURRZ0FFVUozblJZN0tCNEtUWUx0WnFUMS96VS84a0Z2Sk1lUGhYMm1Vc25pczBiR3FZblkyaVZEeApYVzR2SVhTYjNqcm9iZ1YwSUtDT0twUWs2OHJEbE03ckRBPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo="
}

59
go.mod
View File

@ -5,99 +5,50 @@ go 1.22.0
toolchain go1.22.5 toolchain go1.22.5
require ( require (
cloud.o-forge.io/core/oc-lib v0.0.0-20250219142942-5111c9c8bec7
github.com/beego/beego v1.12.12 github.com/beego/beego v1.12.12
github.com/beego/beego/v2 v2.3.1
github.com/goraz/onion v0.1.3 github.com/goraz/onion v0.1.3
github.com/nats-io/nats.go v1.37.0 github.com/nats-io/nats.go v1.37.0
github.com/nwtgck/go-fakelish v0.1.3
github.com/rs/zerolog v1.33.0 github.com/rs/zerolog v1.33.0
github.com/tidwall/gjson v1.17.1 go.mongodb.org/mongo-driver v1.17.1
gopkg.in/yaml.v3 v3.0.1
k8s.io/client-go v0.30.3
) )
require ( require (
cloud.o-forge.io/core/oc-lib v0.0.0-20250205160221-88b7cfe2fd0f // indirect github.com/beego/beego/v2 v2.3.1 // indirect
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/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/biter777/countries v1.7.5 // indirect github.com/biter777/countries v1.7.5 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect github.com/klauspost/compress v1.17.11 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/marcinwyszynski/geopoint v0.0.0-20140302213024-cf2a6f750c5b // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect github.com/montanaflynn/stats v0.7.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nats-io/jwt v0.3.2 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect github.com/nats-io/nuid v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect
github.com/robfig/cron v1.2.0 // indirect github.com/robfig/cron v1.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/vk496/cron v1.2.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
golang.org/x/crypto v0.28.0 // indirect golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.8.0 // indirect golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.35.1 // indirect google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.30.3 // indirect
k8s.io/apimachinery v0.30.3 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
) )

868
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,59 +0,0 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Note: the example only works with the code within the same release/branch.
package k8s
import (
"flag"
"path/filepath"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
//
// Uncomment to load all auth plugins
// _ "k8s.io/client-go/plugin/pkg/client/auth"
//
// Or uncomment to load specific auth plugins
// _ "k8s.io/client-go/plugin/pkg/client/auth/azure"
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
// _ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
)
func NewK8SClient() *kubernetes.Clientset {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
// create the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
return clientset
}

28
main.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
"fmt" "fmt"
"oc-schedulerd/conf" "oc-schedulerd/conf"
"oc-schedulerd/daemons" "oc-schedulerd/daemons"
@ -10,14 +9,29 @@ import (
) )
func main() { func main() {
oclib.InitDaemon("oc-schedulerd") oclib.InitDaemon("oc-schedulerd")
oclib.SetConfig( o := oclib.GetConfLoader()
conf.GetConfig().MongoUrl,
conf.GetConfig().DBName, c := oclib.SetConfig(
conf.GetConfig().NatsUrl, o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
conf.GetConfig().LokiUrl, o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
conf.GetConfig().Logs, o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
o.GetStringDefault("LOKI_URL", ""),
o.GetStringDefault("LOG_LEVEL", "info"),
) )
conf.GetConfig().DBName = c.MongoDatabase
conf.GetConfig().MongoUrl = c.MongoUrl
conf.GetConfig().NatsUrl = c.NATSUrl
conf.GetConfig().LokiUrl = c.LokiUrl
conf.GetConfig().Mode = o.GetStringDefault("MODE", "")
conf.GetConfig().KubeHost = o.GetStringDefault("KUBERNETES_SERVICE_HOST", "")
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
conf.GetConfig().KubeCA = o.GetStringDefault("KUBE_CA", "")
conf.GetConfig().KubeCert = o.GetStringDefault("KUBE_CERT", "")
conf.GetConfig().KubeData = o.GetStringDefault("KUBE_DATA", "")
sch_mngr := daemons.ScheduleManager{Logger: oclib.GetLogger()} sch_mngr := daemons.ScheduleManager{Logger: oclib.GetLogger()}
exe_mngr := daemons.ExecutionManager{} exe_mngr := daemons.ExecutionManager{}

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

View File

@ -1,60 +0,0 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body
{
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
// End Swagger UI call region
window.ui = ui;
};
</script>
</body>
</html>

View File

@ -1,79 +0,0 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1);
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long