feat(crd): add update custom resource status

This commit is contained in:
2024-12-01 23:55:58 +03:30
parent fb646086b0
commit 3e77ac121a
8 changed files with 100 additions and 13 deletions

View File

@@ -12,7 +12,7 @@ import (
var managedJobs = map[types.UID]managed_job.ManagedJob{}
func Setup(client *api.Client, db *buntdb.DB) {
func Setup(client *api.Client, db *buntdb.DB, crdInstance *crd.Crd) {
ticker := time.NewTicker(5 * time.Second)
quit := make(chan struct{})
@@ -20,7 +20,7 @@ func Setup(client *api.Client, db *buntdb.DB) {
for {
select {
case <-ticker.C:
cycle(client, db)
cycle(client, db, crdInstance)
case <-quit:
ticker.Stop()
return
@@ -29,14 +29,14 @@ func Setup(client *api.Client, db *buntdb.DB) {
}()
}
func cycle(client *api.Client, db *buntdb.DB) {
func cycle(client *api.Client, db *buntdb.DB, crdInstance *crd.Crd) {
for _, uid := range crd.GetAllJobKeys() {
def := crd.GetJob(uid)
managedJob, ok := managedJobs[uid]
if ok {
managedJob.Update(def)
} else {
managedJob := managed_job.NewManagedJob(client, db, def)
managedJob := managed_job.NewManagedJob(client, db, def, crdInstance)
managedJobs[uid] = *managedJob
}
}