feat: support multiple operator in single namespace
This commit is contained in:
@@ -3,6 +3,7 @@ package managed_job
|
||||
import (
|
||||
"flink-kube-operator/internal/crd"
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"flink-kube-operator/pkg"
|
||||
@@ -73,6 +74,8 @@ func (mgr *Manager) cycle(client *api.Client, crdInstance *crd.Crd) {
|
||||
}
|
||||
pkg.Logger.Debug("[manager] [cycle] overviews", zap.Any("overviews", jobManagerJobOverviews))
|
||||
|
||||
operatorId := os.Getenv("OPERATOR_ID")
|
||||
|
||||
// Loop over job definitions as Kubernetes CRD
|
||||
for _, uid := range crd.GetAllJobKeys() {
|
||||
if lo.Contains(mgr.processingJobsIds, uid) {
|
||||
@@ -82,6 +85,27 @@ func (mgr *Manager) cycle(client *api.Client, crdInstance *crd.Crd) {
|
||||
|
||||
// Get job definition from Kubernetes CRD
|
||||
def := crd.GetJob(uid)
|
||||
|
||||
// Auto-claim: if flinkCluster is empty, set it to this operator's ID
|
||||
if def.Spec.FlinkCluster == "" {
|
||||
pkg.Logger.Info("[manager] auto-claiming unowned job", zap.String("name", def.GetName()))
|
||||
crdInstance.Patch(def.GetUID(), map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"flinkCluster": operatorId,
|
||||
},
|
||||
})
|
||||
def.Spec.FlinkCluster = operatorId
|
||||
}
|
||||
|
||||
// Skip CRs that belong to another operator
|
||||
if def.Spec.FlinkCluster != operatorId {
|
||||
pkg.Logger.Debug("[manager] skipping job owned by another operator",
|
||||
zap.String("name", def.GetName()),
|
||||
zap.String("flinkCluster", def.Spec.FlinkCluster),
|
||||
zap.String("operatorId", operatorId),
|
||||
)
|
||||
continue
|
||||
}
|
||||
mgr.processingJobsIds = append(mgr.processingJobsIds, uid)
|
||||
|
||||
// Check if job exists in manager managed jobs
|
||||
|
||||
Reference in New Issue
Block a user