From 7a0f6462ba61b59cd1c88896d12785e36332dfd8 Mon Sep 17 00:00:00 2001 From: Matthias Linhuber Date: Fri, 24 May 2024 16:24:22 +0200 Subject: [PATCH] Add scaffolding for k8s scheduler --- .vscode/launch.json | 23 ++++++++++++++++++++--- HadesScheduler/k8s/k8s.go | 28 ++++++++++++++++++++++++++++ HadesScheduler/main.go | 8 ++++---- go.work.sum | 5 ++++- shared/utils/config.go | 4 ---- 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 HadesScheduler/k8s/k8s.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 7e8a664..0deb83a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ } }, { - "name": "HadesScheduler", + "name": "HadesScheduler (docker)", "type": "go", "request": "launch", "mode": "auto", @@ -22,13 +22,30 @@ "preLaunchTask": "Start Redis Container", // This will start the Redis container before launching the scheduler - defined in .vscode/tasks.json "env": { "DEBUG": "true", + "HADES_EXECUTOR": "docker" + } + } + { + "name": "HadesScheduler (k8s)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/HadesScheduler", + "preLaunchTask": "Start Redis Container", // This will start the Redis container before launching the scheduler - defined in .vscode/tasks.json + "env": { + "DEBUG": "true", + "HADES_EXECUTOR": "k8s" } } ], "compounds": [ { - "name": "HadesAPI and HadesScheduler", - "configurations": ["HadesAPI", "HadesScheduler"] + "name": "HadesAPI and HadesScheduler (docker)", + "configurations": ["HadesAPI", "HadesScheduler (docker)"] + } + { + "name": "HadesAPI and HadesScheduler (k8s)", + "configurations": ["HadesAPI", "HadesScheduler (k8s)"] } ] } \ No newline at end of file diff --git a/HadesScheduler/k8s/k8s.go b/HadesScheduler/k8s/k8s.go new file mode 100644 index 0000000..e1c91da --- /dev/null +++ b/HadesScheduler/k8s/k8s.go @@ -0,0 +1,28 @@ +package k8s + +import ( + "context" + + "github.com/ls1intum/hades/shared/payload" + "github.com/ls1intum/hades/shared/utils" + log "github.com/sirupsen/logrus" +) + +type Scheduler struct{} + +type K8sConfig struct{} + +func NewK8sScheduler() Scheduler { + log.Debug("Initializing Kubernetes scheduler") + + var k8sCfg K8sConfig + utils.LoadConfig(&k8sCfg) + log.Debugf("Kubernetes config: %+v", k8sCfg) + + return Scheduler{} +} + +func (k Scheduler) ScheduleJob(ctx context.Context, job payload.QueuePayload) error { + log.Debug("Scheduling job in Kubernetes") + return nil +} diff --git a/HadesScheduler/main.go b/HadesScheduler/main.go index c2d2915..eec90e3 100644 --- a/HadesScheduler/main.go +++ b/HadesScheduler/main.go @@ -7,6 +7,7 @@ import ( "github.com/hibiken/asynq" "github.com/ls1intum/hades/hadesScheduler/docker" + "github.com/ls1intum/hades/hadesScheduler/k8s" "github.com/ls1intum/hades/shared/payload" "github.com/ls1intum/hades/shared/utils" @@ -41,10 +42,9 @@ func main() { var scheduler JobScheduler switch executorCfg.Executor { - // case "k8s": - // log.Info("Started HadesScheduler in Kubernetes mode") - // kube.Init() - // scheduler = kube.Scheduler{} + case "k8s": + log.Info("Started HadesScheduler in Kubernetes mode") + scheduler = k8s.NewK8sScheduler() case "docker": log.Info("Started HadesScheduler in Docker mode") scheduler = docker.NewDockerScheduler() diff --git a/go.work.sum b/go.work.sum index 9d9d33e..ce8abdb 100644 --- a/go.work.sum +++ b/go.work.sum @@ -151,8 +151,10 @@ github.com/containerd/go-cni v1.1.9/go.mod h1:XYrZJ1d5W6E2VOvjffL3IZq0Dz6bsVlERH github.com/containerd/go-runc v1.0.0/go.mod h1:cNU0ZbCgCQVZK4lgG3P+9tn9/PaJNmoDXPpoJhDR+Ok= github.com/containerd/imgcrypt v1.1.7/go.mod h1:FD8gqIcX5aTotCtOmjeCsi3A1dHmTZpnMISGKSczt4k= github.com/containerd/nri v0.4.0/go.mod h1:Zw9q2lP16sdg0zYybemZ9yTDy8g7fPCIB3KXOGlggXI= +github.com/containerd/nri v0.6.0/go.mod h1:F7OZfO4QTPqw5r87aq+syZJwiVvRYLIlHZiZDBV1W3A= github.com/containerd/stargz-snapshotter/estargz v0.14.3/go.mod h1:KY//uOCIkSuNAHhJogcZtrNHdKrA99/FCCRjE3HD36o= github.com/containerd/ttrpc v1.2.2/go.mod h1:sIT6l32Ph/H9cvnJsfXM5drIVzTr5A2flTf1G5tYZak= +github.com/containerd/ttrpc v1.2.3/go.mod h1:ieWsXucbb8Mj9PH0rXCw1i8IunRbbAiDkpXkbfflWBM= github.com/containerd/typeurl v1.0.2/go.mod h1:9trJWW2sRlGub4wZJRTW83VtbOLS6hwcDZXTn6oPz9s= github.com/containerd/typeurl/v2 v2.1.1/go.mod h1:IDp2JFvbwZ31H8dQbEIY7sDl2L3o3HZj1hsSQlywkQ0= github.com/containerd/zfs v1.1.0/go.mod h1:oZF9wBnrnQjpWLaPKEinrx3TQ9a+W/RJO7Zb41d8YLE= @@ -247,7 +249,6 @@ github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tchap/go-patricia/v2 v2.3.1/go.mod h1:VZRHKAb53DLaG+nA9EaYYiaEx6YztwDlLElMsnSHD4k= github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8= @@ -320,3 +321,5 @@ k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5/go.mod h1:OLgZIPagt7ERELqWJFomSt sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +tags.cncf.io/container-device-interface v0.6.2/go.mod h1:Shusyhjs1A5Na/kqPVLL0KqnHQHuunol9LFeUNkuGVE= +tags.cncf.io/container-device-interface/specs-go v0.6.0/go.mod h1:hMAwAbMZyBLdmYqWgYcKH0F/yctNpV3P35f+/088A80= diff --git a/shared/utils/config.go b/shared/utils/config.go index b3a6b8e..ccc7ede 100644 --- a/shared/utils/config.go +++ b/shared/utils/config.go @@ -16,10 +16,6 @@ type RedisConfig struct { TLS_Enabled bool `env:"REDIS_TLS_ENABLED" envDefault:"false"` } -type K8sConfig struct { - HadesCInamespace string `env:"HADES_CI_NAMESPACE" envDefault:"hades-ci"` -} - type ExecutorConfig struct { Executor string `env:"HADES_EXECUTOR,notEmpty" envDefault:"docker"` }