Use regular conf oclib library instead of custom implem to leverage env variable injection fonctionality; Dockerfile refactor

This commit is contained in:
plm 2025-01-14 18:33:51 +01:00
parent 7d78920304
commit 8ddb119899
9 changed files with 31 additions and 27 deletions

View File

@ -1,22 +1,32 @@
FROM golang:alpine AS deps
WORKDIR /app
COPY go.mod go.sum ./
RUN sed -i '/replace/d' go.mod
RUN go mod download -x
#----------------------------------------------------------------------------------------------
FROM golang:alpine AS builder
LABEL maintainer="IRT PFN"
ENV DOCKER_ENVIRONMENT=true
WORKDIR /app
COPY --from=deps /go/pkg /go/pkg
COPY --from=deps /app/go.mod /app/go.sum ./
COPY . .
RUN go build .
#----------------------------------------------------------------------------------------------
FROM oc-monitord:latest AS monitord
FROM argoproj/argocd:latest
ENV MONITORD_PATH = "./oc-monitord"
WORKDIR /app
COPY conf/docker_schedulerd.json /etc/oc/schedulerd.json
COPY --from=monitord /app/oc-monitord .
COPY --from=builder /app/oc-schedulerd .
COPY conf/docker_schedulerd.json /etc/oc/schedulerd.json

View File

@ -38,12 +38,6 @@ func init() {
o = onion.New(l2, l3)
}
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 {

View File

@ -5,6 +5,7 @@ import (
"oc-schedulerd/conf"
"os/exec"
oclib "cloud.o-forge.io/core/oc-lib"
"github.com/rs/zerolog"
)
@ -30,7 +31,7 @@ func (lm *LocalMonitor) LaunchLocalMonitor() {
}
func (lm *LocalMonitor) execLocalKube() {
args := []string{"-e", lm.ExecutionID, "-u", lm.LokiURL, "-m", conf.GetConfig().MongoUrl, "-d", conf.GetConfig().DBName}
args := []string{"-e", lm.ExecutionID, "-u", lm.LokiURL, "-m", oclib.GetConfig().MongoUrl, "-d", oclib.GetConfig().MongoDatabase}
if lm.Duration > 0 {
args = append(args, "-t", fmt.Sprintf("%d", lm.Duration))
}

View File

@ -1,7 +1,6 @@
package daemons
import (
"oc-schedulerd/conf"
"os"
"time"
@ -49,10 +48,10 @@ func (em *ExecutionManager) executeBooking(booking *workflow_execution.WorkflowE
duration = int(booking.EndDate.Sub(*booking.ExecDate).Seconds())
}
monitor := LocalMonitor{
Logger: logger,
Duration: duration,
LokiURL: conf.GetConfig().LokiUrl,
KubeURL: "localhost",
Logger: logger,
Duration: duration,
LokiURL: oclib.GetConfig().LokiUrl,
KubeURL: "localhost",
ExecutionID: booking.UUID,
}
monitor.LaunchLocalMonitor()

View File

@ -3,7 +3,6 @@ package daemons
import (
"encoding/json"
"fmt"
"oc-schedulerd/conf"
"sync"
"time"
@ -64,7 +63,7 @@ type ScheduleManager struct {
// on workflows' scheduling. Messages must contain
// workflow execution ID, to allow retrieval of execution infos
func (s *ScheduleManager) ListenNATS() {
nc, err := nats.Connect(conf.GetConfig().NatsUrl)
nc, err := nats.Connect(oclib.GetConfig().NATSUrl)
if err != nil {
s.Logger.Error().Msg("Could not connect to NATS")
return

4
go.mod
View File

@ -6,11 +6,10 @@ toolchain go1.22.5
require (
cloud.o-forge.io/core/oc-lib v0.0.0-20250110163958-fd1c579ec418
github.com/beego/beego v1.12.12
github.com/beego/beego v1.12.14
github.com/goraz/onion v0.1.3
github.com/nats-io/nats.go v1.37.0
github.com/rs/zerolog v1.33.0
go.mongodb.org/mongo-driver v1.17.1
k8s.io/client-go v0.30.3
)
@ -61,6 +60,7 @@ require (
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // 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/net v0.30.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect

4
go.sum
View File

@ -8,8 +8,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
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.14 h1:j+3z3d9NfLRcvjqM7l8LFUbwwDOv5NgOuQxImZKyZg0=
github.com/beego/beego v1.12.14/go.mod h1:QURFL1HldOcCZAxnc1cZ7wrplsYR5dKPHFjmk6WkLAs=
github.com/beego/beego/v2 v2.3.1 h1:7MUKMpJYzOXtCUsTEoXOxsDV/UcHw6CPbaWMlthVNsc=
github.com/beego/beego/v2 v2.3.1/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=

13
main.go
View File

@ -3,20 +3,21 @@ package main
import (
"fmt"
"oc-schedulerd/conf"
"oc-schedulerd/daemons"
oclib "cloud.o-forge.io/core/oc-lib"
)
func main() {
oclib.InitDaemon("oc-schedulerd")
conf := oclib.GetConfLoader()
oclib.SetConfig(
conf.GetConfig().MongoUrl,
conf.GetConfig().DBName,
conf.GetConfig().NatsUrl,
conf.GetConfig().LokiUrl,
conf.GetConfig().Logs,
conf.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
conf.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
conf.GetStringDefault("NATS_URL", "nats://localhost:4222"),
conf.GetStringDefault("LOKI_URL", ""),
conf.GetStringDefault("LOG_LEVEL", "info"),
)
sch_mngr := daemons.ScheduleManager{Logger: oclib.GetLogger()}
exe_mngr := daemons.ExecutionManager{}

BIN
oc-schedulerd Executable file

Binary file not shown.