[Provisioning] Fix duplicate sync jobs triggered in controller (#100870)
* Improve logging on reasons why the controller triggered * Fix messaging for sync job
This commit is contained in:
1 parent
77a11efe0c
commit
7d27e916cc
2 files changed
+21
-4
No files matched your search
@@ -247,11 +247,18 @@ func (rc *RepositoryController) process(item *queueItem) error {
|
||||
shouldResync := syncAge >= (syncInterval-tolerance) && !isSyncJobPendingOrRunning
|
||||
hasSpecChanged := obj.Generation != obj.Status.ObservedGeneration
|
||||
|
||||
if !hasSpecChanged && obj.DeletionTimestamp == nil && (healthAge < time.Hour*4) && !shouldResync {
|
||||
switch {
|
||||
case hasSpecChanged:
|
||||
logger.Info("spec changed", "Generation", obj.Generation, "ObservedGeneration", obj.Status.ObservedGeneration)
|
||||
case obj.DeletionTimestamp != nil:
|
||||
logger.Info("deletion timestamp set")
|
||||
case shouldResync:
|
||||
logger.Info("sync interval triggered", "sync_age", syncAge, "sync_interval", syncInterval, "sync_status", obj.Status.Sync.State)
|
||||
case healthAge > time.Hour*4:
|
||||
logger.Info("health is too old", "health_age", healthAge)
|
||||
default:
|
||||
logger.Info("skipping as conditions are not met", "status", obj.Status, "generation", obj.Generation, "deletion_timestamp", obj.DeletionTimestamp, "sync_spec", obj.Spec.Sync)
|
||||
return nil
|
||||
} else {
|
||||
logger.Info("conditions met", "status", obj.Status, "generation", obj.Generation, "deletion_timestamp", obj.DeletionTimestamp, "sync_spec", obj.Spec.Sync)
|
||||
}
|
||||
|
||||
repo, err := rc.repoGetter.AsRepository(ctx, obj)
|
||||
@@ -371,6 +378,12 @@ func (rc *RepositoryController) process(item *queueItem) error {
|
||||
} else {
|
||||
logger.Info("sync job triggered", "job", job.Name)
|
||||
}
|
||||
|
||||
statusPatch.Sync = provisioning.SyncStatus{
|
||||
State: provisioning.JobStatePending,
|
||||
JobID: job.Name,
|
||||
Incremental: sync.Incremental,
|
||||
}
|
||||
}
|
||||
|
||||
// The one place we update status (triggers another controller loop!)
|
||||
|
||||
@@ -124,7 +124,7 @@ func (r *SyncWorker) Process(ctx context.Context, repo repository.Repository, jo
|
||||
stats = &provisioning.ResourceStats{}
|
||||
}
|
||||
|
||||
progress.SetMessage("update sync amd stats status at end")
|
||||
progress.SetMessage("update status and stats")
|
||||
data = map[string]any{
|
||||
"status": map[string]any{
|
||||
"sync": syncStatus,
|
||||
@@ -136,6 +136,10 @@ func (r *SyncWorker) Process(ctx context.Context, repo repository.Repository, jo
|
||||
return fmt.Errorf("update repo with job final status: %w", err)
|
||||
}
|
||||
|
||||
if syncError == nil {
|
||||
progress.SetMessage("job completed successfully")
|
||||
}
|
||||
|
||||
return syncError
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user