package manager import ( "flink-kube-operator/internal/crd" "flink-kube-operator/internal/managed_job" "time" api "github.com/logi-camp/go-flink-client" "github.com/tidwall/buntdb" "k8s.io/apimachinery/pkg/types" ) var managedJobs = map[types.UID]managed_job.ManagedJob{} func Setup(client *api.Client, db *buntdb.DB) { ticker := time.NewTicker(5 * time.Second) quit := make(chan struct{}) go func() { for { select { case <-ticker.C: cycle(client, db) case <-quit: ticker.Stop() return } } }() } func cycle(client *api.Client, db *buntdb.DB) { 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) managedJobs[uid] = *managedJob } } }