-
Notifications
You must be signed in to change notification settings - Fork 289
feat: Add sync-dependencies #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -480,7 +480,7 @@ func (sc *syncContext) Sync() { | |||
|
||||
sc.log.WithValues("tasks", tasks).V(1).Info("Filtering out non-pending tasks") | ||||
// remove tasks that are completed, we can assume that there are no running tasks | ||||
tasks = tasks.Filter(func(t *syncTask) bool { return t.pending() }) | ||||
completedTasks, tasks := tasks.Split(func(t *syncTask) bool { return t.completed() }) | ||||
|
||||
if sc.applyOutOfSyncOnly { | ||||
tasks = sc.filterOutOfSyncTasks(tasks) | ||||
|
@@ -500,15 +500,22 @@ func (sc *syncContext) Sync() { | |||
wave := tasks.wave() | ||||
finalWave := phase == tasks.lastPhase() && wave == tasks.lastWave() | ||||
|
||||
// if it is the last phase/wave and the only remaining tasks are non-hooks, the we are successful | ||||
// EVEN if those objects subsequently degraded | ||||
// This handles the common case where neither hooks or waves are used and a sync equates to simply an (asynchronous) kubectl apply of manifests, which succeeds immediately. | ||||
remainingTasks := tasks.Filter(func(t *syncTask) bool { return t.phase != phase || wave != t.wave() || t.isHook() }) | ||||
hasIncompleteDependency := func(t *syncTask) bool { | ||||
for _, dep := range t.dependencies() { | ||||
if !completedTasks.Any(func(t *syncTask) bool { return dep.match(t.obj()) }) { | ||||
return true | ||||
} | ||||
} | ||||
return false | ||||
} | ||||
|
||||
tasks, waitingTasks := tasks.Split(func(t *syncTask) bool { | ||||
return t.phase == phase && t.wave() == wave && !hasIncompleteDependency(t) | ||||
}) | ||||
|
||||
sc.log.WithValues("phase", phase, "wave", wave, "tasks", tasks, "syncFailTasks", syncFailTasks).V(1).Info("Filtering tasks in correct phase and wave") | ||||
tasks = tasks.Filter(func(t *syncTask) bool { return t.phase == phase && t.wave() == wave }) | ||||
sc.log.WithValues("phase", phase, "wave", wave, "tasks", tasks, "waitingTasks", waitingTasks, "syncFailTasks", syncFailTasks).V(1).Info("Filtering tasks in correct phase and wave") | ||||
|
||||
sc.setOperationPhase(common.OperationRunning, "one or more tasks are running") | ||||
sc.setOperationPhase(common.OperationRunning, fmt.Sprintf("%d task(s) are running", len(tasks))) | ||||
|
||||
sc.log.WithValues("tasks", tasks).V(1).Info("Wet-run") | ||||
runState := sc.runTasks(tasks, false) | ||||
|
@@ -529,12 +536,19 @@ func (sc *syncContext) Sync() { | |||
sc.deleteHooks(hooksPendingDeletionFailed) | ||||
sc.setOperationFailed(syncFailTasks, syncFailedTasks, "one or more objects failed to apply") | ||||
case successful: | ||||
if remainingTasks.Len() == 0 { | ||||
|
||||
// if it is the last phase/wave and the only remaining tasks are non-hooks, then the sync is complete | ||||
// EVEN if those objects subsequently degraded | ||||
// This handles the case where neither hooks or waves are used and a sync equates to an | ||||
// (asynchronous) kubectl apply of manifests, which succeeds immediately. | ||||
anyHooks := tasks.Any(func(task *syncTask) bool { return task.isHook() }) | ||||
|
||||
if len(waitingTasks) == 0 && !anyHooks { | ||||
// delete all completed hooks which have appropriate delete policy | ||||
sc.deleteHooks(hooksPendingDeletionSuccessful) | ||||
sc.setOperationPhase(common.OperationSucceeded, "successfully synced (all tasks run)") | ||||
} else { | ||||
sc.setRunningPhase(remainingTasks, false) | ||||
sc.setRunningPhase(tasks, false) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a 2+ year old bug. |
||||
} | ||||
default: | ||||
sc.setRunningPhase(tasks.Filter(func(task *syncTask) bool { | ||||
|
@@ -772,6 +786,8 @@ func (sc *syncContext) getSyncTasks() (_ syncTasks, successful bool) { | |||
|
||||
tasks.Sort() | ||||
|
||||
sc.log.WithValues("tasks", tasks).V(1).Info("tasks after sorting") | ||||
|
||||
Comment on lines
+789
to
+790
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
// finally enrich tasks with the result | ||||
for _, task := range tasks { | ||||
result, ok := sc.syncRes[task.resultKey()] | ||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
syncTasks
we need to check for cyclic-dependencies.