Skip to content

Commit 1f8e4df

Browse files
committed
fix bug
1 parent 78559fc commit 1f8e4df

File tree

2 files changed

+6
-60
lines changed

2 files changed

+6
-60
lines changed

hiclaw-controller/internal/controller/manager_controller.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ func (r *ManagerReconciler) failManagerUpdate(ctx context.Context, m *v1beta1.Ma
345345
// --- Desired state reconciliation ---
346346

347347
func (r *ManagerReconciler) reconcileDesiredState(ctx context.Context, m *v1beta1.Manager, desired string) (reconcile.Result, error) {
348-
// If current phase already matches desired state, verify the pod still exists.
349-
if m.Status.Phase == desired && desired == "Running" {
350-
return r.ensureManagerPodExists(ctx, m)
351-
}
348+
// If current phase already matches desired state, nothing to do.
349+
// This also avoids calling backend Status/Stop/Delete for Managers
350+
// in Docker mode, where the container name ("hiclaw-manager") doesn't
351+
// include the backend's worker prefix ("hiclaw-worker-").
352352
if m.Status.Phase == desired {
353353
return reconcile.Result{}, nil
354354
}
@@ -547,28 +547,6 @@ func (r *ManagerReconciler) failManagerLifecycle(ctx context.Context, m *v1beta1
547547
return reconcile.Result{RequeueAfter: time.Minute}, fmt.Errorf("%s", msg)
548548
}
549549

550-
// ensureManagerPodExists checks if the manager's pod/container still exists.
551-
func (r *ManagerReconciler) ensureManagerPodExists(ctx context.Context, m *v1beta1.Manager) (reconcile.Result, error) {
552-
wb := r.managerBackend(ctx)
553-
if wb == nil {
554-
return reconcile.Result{}, nil
555-
}
556-
557-
containerName := managerContainerName(m.Name)
558-
result, err := wb.Status(ctx, containerName)
559-
if err != nil {
560-
return reconcile.Result{RequeueAfter: reconcileRetryDelay}, nil
561-
}
562-
563-
if result.Status == backend.StatusRunning || result.Status == backend.StatusStarting {
564-
return reconcile.Result{}, nil
565-
}
566-
567-
logger := log.FromContext(ctx)
568-
logger.Info("pod missing for Running manager, recreating", "name", m.Name, "backendStatus", result.Status)
569-
return r.ensureManagerRunning(ctx, m)
570-
}
571-
572550
func (r *ManagerReconciler) SetupWithManager(mgr ctrl.Manager) error {
573551
builder := ctrl.NewControllerManagedBy(mgr).
574552
For(&v1beta1.Manager{})

hiclaw-controller/internal/controller/worker_controller.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,8 @@ func (r *WorkerReconciler) failUpdate(ctx context.Context, w *v1beta1.Worker, ms
400400
// reconcileDesiredState compares the desired lifecycle state (spec.state) with
401401
// the actual backend state and takes corrective action when drift is detected.
402402
func (r *WorkerReconciler) reconcileDesiredState(ctx context.Context, w *v1beta1.Worker, desired string) (reconcile.Result, error) {
403-
// If current phase already matches desired state, verify the pod still exists.
404-
// The pod may have been deleted externally (e.g. kubectl delete pod) while
405-
// the CR status still shows Running.
406-
if w.Status.Phase == desired && desired == "Running" {
407-
return r.ensurePodExists(ctx, w)
408-
}
403+
// If current phase already matches desired state, nothing to do.
404+
// This also avoids unnecessary backend Status calls on every reconcile.
409405
if w.Status.Phase == desired {
410406
return reconcile.Result{}, nil
411407
}
@@ -575,34 +571,6 @@ func (r *WorkerReconciler) failLifecycle(ctx context.Context, w *v1beta1.Worker,
575571
return reconcile.Result{RequeueAfter: time.Minute}, fmt.Errorf("%s", msg)
576572
}
577573

578-
// ensurePodExists checks if the worker's pod/container still exists.
579-
// If the pod was deleted externally while the CR status is Running,
580-
// this triggers recreation via ensureWorkerRunning.
581-
func (r *WorkerReconciler) ensurePodExists(ctx context.Context, w *v1beta1.Worker) (reconcile.Result, error) {
582-
if r.Backend == nil {
583-
return reconcile.Result{}, nil
584-
}
585-
wb := r.Backend.DetectWorkerBackend(ctx)
586-
if wb == nil {
587-
return reconcile.Result{}, nil
588-
}
589-
590-
result, err := wb.Status(ctx, w.Name)
591-
if err != nil {
592-
// Backend error — don't panic, just requeue
593-
return reconcile.Result{RequeueAfter: reconcileRetryDelay}, nil
594-
}
595-
596-
if result.Status == backend.StatusRunning || result.Status == backend.StatusStarting {
597-
return reconcile.Result{}, nil // pod exists, all good
598-
}
599-
600-
// Pod is gone — trigger recreation
601-
logger := log.FromContext(ctx)
602-
logger.Info("pod missing for Running worker, recreating", "name", w.Name, "backendStatus", result.Status)
603-
return r.ensureWorkerRunning(ctx, w)
604-
}
605-
606574
func (r *WorkerReconciler) SetupWithManager(mgr ctrl.Manager) error {
607575
builder := ctrl.NewControllerManagedBy(mgr).
608576
For(&v1beta1.Worker{})

0 commit comments

Comments
 (0)