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
workload-update: cancel a workload update migration #11641
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7cbd05c
api: add WorkloadUpdateMigrationAbortionAnnotation
alicefr 4c1ee82
migrations: add ListWorkloadUpdateMigrations
alicefr e77f709
workload-updater: ignore changes with the abortion annotation
alicefr be31f56
workload-updater: cancel a workload update migration
alicefr a60b726
workload-updater: unit test for update abortion
alicefr 4dfde6f
tests: test migration abortion with CPU hotplug
alicefr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |||||
|
||||||
migrationutils "kubevirt.io/kubevirt/pkg/util/migrations" | ||||||
|
||||||
v1 "kubevirt.io/api/core/v1" | ||||||
virtv1 "kubevirt.io/api/core/v1" | ||||||
"kubevirt.io/client-go/kubecli" | ||||||
"kubevirt.io/client-go/log" | ||||||
|
@@ -43,6 +44,12 @@ const ( | |||||
FailedEvictVirtualMachineInstanceReason = "FailedEvict" | ||||||
// SuccessfulEvictVirtualMachineInstanceReason is added in an event if a deletion of a VMI Succeeds | ||||||
SuccessfulEvictVirtualMachineInstanceReason = "SuccessfulEvict" | ||||||
// SuccessfulChangeAbortionReason is added in an event if a deletion of a | ||||||
// migration succeeds | ||||||
SuccessfulChangeAbortionReason = "SuccessfulChangeAbortion" | ||||||
// FailedChangeAbortionReason is added in an event if a deletion of a | ||||||
// migration succeeds | ||||||
FailedChangeAbortionReason = "FailedChangeAbortion" | ||||||
) | ||||||
|
||||||
// time to wait before re-enqueing when outdated VMIs are still detected | ||||||
|
@@ -74,6 +81,7 @@ type updateData struct { | |||||
allOutdatedVMIs []*virtv1.VirtualMachineInstance | ||||||
migratableOutdatedVMIs []*virtv1.VirtualMachineInstance | ||||||
evictOutdatedVMIs []*virtv1.VirtualMachineInstance | ||||||
abortChangeVMIs []*virtv1.VirtualMachineInstance | ||||||
|
||||||
numActiveMigrations int | ||||||
} | ||||||
|
@@ -313,14 +321,27 @@ func (c *WorkloadUpdateController) doesRequireMigration(vmi *virtv1.VirtualMachi | |||||
if vmi.IsFinal() || migrationutils.IsMigrating(vmi) { | ||||||
return false | ||||||
} | ||||||
|
||||||
if metav1.HasAnnotation(vmi.ObjectMeta, v1.WorkloadUpdateMigrationAbortionAnnotation) { | ||||||
return false | ||||||
} | ||||||
if isHotplugInProgress(vmi) { | ||||||
return true | ||||||
} | ||||||
|
||||||
return false | ||||||
} | ||||||
|
||||||
func (c *WorkloadUpdateController) shouldAbortMigration(vmi *virtv1.VirtualMachineInstance) bool { | ||||||
numMig := len(migrationutils.ListWorkloadUpdateMigrations(c.migrationInformer.GetStore(), vmi.Name, vmi.Namespace)) | ||||||
alicefr marked this conversation as resolved.
Show resolved
Hide resolved
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. nit
Suggested change
Then return it below |
||||||
if metav1.HasAnnotation(vmi.ObjectMeta, virtv1.WorkloadUpdateMigrationAbortionAnnotation) { | ||||||
return numMig > 0 | ||||||
} | ||||||
if isHotplugInProgress(vmi) { | ||||||
return false | ||||||
} | ||||||
return numMig > 0 | ||||||
} | ||||||
|
||||||
func (c *WorkloadUpdateController) getUpdateData(kv *virtv1.KubeVirt) *updateData { | ||||||
data := &updateData{} | ||||||
|
||||||
|
@@ -349,10 +370,14 @@ func (c *WorkloadUpdateController) getUpdateData(kv *virtv1.KubeVirt) *updateDat | |||||
objs := c.vmiInformer.GetStore().List() | ||||||
for _, obj := range objs { | ||||||
vmi := obj.(*virtv1.VirtualMachineInstance) | ||||||
if !vmi.IsRunning() || vmi.IsFinal() || vmi.DeletionTimestamp != nil { | ||||||
switch { | ||||||
case !vmi.IsRunning() || vmi.IsFinal() || vmi.DeletionTimestamp != nil: | ||||||
// only consider running VMIs that aren't being shutdown | ||||||
continue | ||||||
} else if !c.isOutdated(vmi) && !c.doesRequireMigration(vmi) { | ||||||
case c.shouldAbortMigration(vmi) && !c.isOutdated(vmi): | ||||||
data.abortChangeVMIs = append(data.abortChangeVMIs, vmi) | ||||||
continue | ||||||
case !c.isOutdated(vmi) && !c.doesRequireMigration(vmi): | ||||||
continue | ||||||
} | ||||||
|
||||||
|
@@ -453,7 +478,7 @@ func (c *WorkloadUpdateController) sync(kv *virtv1.KubeVirt) error { | |||||
// Rather than enqueing based on VMI activity, we keep periodically poping the loop | ||||||
// until all VMIs are updated. Watching all VMI activity is chatty for this controller | ||||||
// when we don't need to be that efficent in how quickly the updates are being processed. | ||||||
if len(data.evictOutdatedVMIs) != 0 || len(data.migratableOutdatedVMIs) != 0 { | ||||||
if len(data.evictOutdatedVMIs) != 0 || len(data.migratableOutdatedVMIs) != 0 || len(data.abortChangeVMIs) != 0 { | ||||||
c.queue.AddAfter(key, periodicReEnqueueIntervalSeconds) | ||||||
} | ||||||
|
||||||
|
@@ -507,7 +532,7 @@ func (c *WorkloadUpdateController) sync(kv *virtv1.KubeVirt) error { | |||||
evictionCandidates = data.evictOutdatedVMIs[0:batchDeletionCount] | ||||||
} | ||||||
|
||||||
wgLen := len(migrationCandidates) + len(evictionCandidates) | ||||||
wgLen := len(migrationCandidates) + len(evictionCandidates) + len(data.abortChangeVMIs) | ||||||
wg := &sync.WaitGroup{} | ||||||
wg.Add(wgLen) | ||||||
errChan := make(chan error, wgLen) | ||||||
|
@@ -572,6 +597,25 @@ func (c *WorkloadUpdateController) sync(kv *virtv1.KubeVirt) error { | |||||
}(vmi) | ||||||
} | ||||||
|
||||||
for _, vmi := range data.abortChangeVMIs { | ||||||
go func(vmi *virtv1.VirtualMachineInstance) { | ||||||
defer wg.Done() | ||||||
migList := migrationutils.ListWorkloadUpdateMigrations(c.migrationInformer.GetStore(), vmi.Name, vmi.Namespace) | ||||||
for _, mig := range migList { | ||||||
err = c.clientset.VirtualMachineInstanceMigration(vmi.Namespace).Delete(context.Background(), mig.Name, metav1.DeleteOptions{}) | ||||||
if err != nil && !errors.IsNotFound(err) { | ||||||
log.Log.Object(vmi).Reason(err).Errorf("Failed to delete the migration due to a migration abortion") | ||||||
c.recorder.Eventf(vmi, k8sv1.EventTypeNormal, FailedChangeAbortionReason, "Failed to abort change for vmi: %s: %v", vmi.Name, err) | ||||||
errChan <- err | ||||||
} else if err == nil { | ||||||
log.Log.Infof("Delete migration %s due to an update change abortion", mig.Name) | ||||||
c.recorder.Eventf(vmi, k8sv1.EventTypeNormal, SuccessfulChangeAbortionReason, "Aborted change for vmi: %s", vmi.Name) | ||||||
|
||||||
} | ||||||
} | ||||||
|
||||||
}(vmi) | ||||||
} | ||||||
wg.Wait() | ||||||
|
||||||
select { | ||||||
|
This file contains 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 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 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 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
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.
can't/shouldn't this ionformer have a "namespace" index?
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.
Could also add your own "vmi" index that indexes on namespace/name
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.
@mhenriks I'm not sure I understand the feedback, could you please expand?
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.
The disruption budget's controller's migration informer is initially created here:
kubevirt/pkg/controller/virtinformers.go
Lines 495 to 500 in 3763f9f
the
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
part is providing a namespace indexer. This is how it's being used:kubevirt/pkg/controller/controller.go
Lines 254 to 255 in 3763f9f
The idea is that you can provide an indexer name and a key (e.g. the namespace indexer with the
my-namespace
key).what you can do is pass the indexer as an argument instead of a store, but that's not a blocker IMO
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.
If you want to go further with this approach you can even add a new indexer that would get the aborted migrations and use it here 😃
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.
do you mind if I address this in a followup PR? I'd like to get this merge in order to continue with volume migration
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.
Not at all, as I said it's not a blocker from my side :)