forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
workload-updater.go
628 lines (522 loc) · 20.5 KB
/
workload-updater.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
package workloadupdater
import (
"context"
"fmt"
"math"
"math/rand"
"sync"
"time"
"golang.org/x/time/rate"
k8sv1 "k8s.io/api/core/v1"
policy "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
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"
"kubevirt.io/kubevirt/pkg/controller"
metrics "kubevirt.io/kubevirt/pkg/monitoring/metrics/virt-controller"
"kubevirt.io/kubevirt/pkg/util/status"
)
const (
// FailedCreateVirtualMachineInstanceMigrationReason is added in an event if creating a VirtualMachineInstanceMigration failed.
FailedCreateVirtualMachineInstanceMigrationReason = "FailedCreate"
// SuccessfulCreateVirtualMachineInstanceMigrationReason is added in an event if creating a VirtualMachineInstanceMigration succeeded.
SuccessfulCreateVirtualMachineInstanceMigrationReason = "SuccessfulCreate"
// FailedEvictVirtualMachineInstanceReason is added in an event if a deletion of a VMI fails
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
const periodicReEnqueueIntervalSeconds = 30
// ensures we don't execute more than once every 5 seconds
const defaultThrottleInterval = 5 * time.Second
const defaultBatchDeletionIntervalSeconds = 60
const defaultBatchDeletionCount = 10
type WorkloadUpdateController struct {
clientset kubecli.KubevirtClient
queue workqueue.RateLimitingInterface
vmiInformer cache.SharedIndexInformer
podInformer cache.SharedIndexInformer
migrationInformer cache.SharedIndexInformer
recorder record.EventRecorder
migrationExpectations *controller.UIDTrackingControllerExpectations
kubeVirtInformer cache.SharedIndexInformer
clusterConfig *virtconfig.ClusterConfig
statusUpdater *status.KVStatusUpdater
launcherImage string
lastDeletionBatch time.Time
}
type updateData struct {
allOutdatedVMIs []*virtv1.VirtualMachineInstance
migratableOutdatedVMIs []*virtv1.VirtualMachineInstance
evictOutdatedVMIs []*virtv1.VirtualMachineInstance
abortChangeVMIs []*virtv1.VirtualMachineInstance
numActiveMigrations int
}
func NewWorkloadUpdateController(
launcherImage string,
vmiInformer cache.SharedIndexInformer,
podInformer cache.SharedIndexInformer,
migrationInformer cache.SharedIndexInformer,
kubeVirtInformer cache.SharedIndexInformer,
recorder record.EventRecorder,
clientset kubecli.KubevirtClient,
clusterConfig *virtconfig.ClusterConfig,
) (*WorkloadUpdateController, error) {
rl := workqueue.NewMaxOfRateLimiter(
workqueue.NewItemExponentialFailureRateLimiter(defaultThrottleInterval, 300*time.Second),
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Every(defaultThrottleInterval), 1)},
)
c := &WorkloadUpdateController{
queue: workqueue.NewNamedRateLimitingQueue(rl, "virt-controller-workload-update"),
vmiInformer: vmiInformer,
podInformer: podInformer,
migrationInformer: migrationInformer,
kubeVirtInformer: kubeVirtInformer,
recorder: recorder,
clientset: clientset,
statusUpdater: status.NewKubeVirtStatusUpdater(clientset),
launcherImage: launcherImage,
migrationExpectations: controller.NewUIDTrackingControllerExpectations(controller.NewControllerExpectations()),
clusterConfig: clusterConfig,
}
_, err := c.vmiInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
UpdateFunc: c.updateVmi,
})
if err != nil {
return nil, err
}
_, err = c.kubeVirtInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.addKubeVirt,
DeleteFunc: c.deleteKubeVirt,
UpdateFunc: c.updateKubeVirt,
})
if err != nil {
return nil, err
}
_, err = c.migrationInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.addMigration,
DeleteFunc: c.deleteMigration,
UpdateFunc: c.updateMigration,
})
if err != nil {
return nil, err
}
return c, nil
}
func (c *WorkloadUpdateController) getKubeVirtKey() (string, error) {
kvs := c.kubeVirtInformer.GetStore().List()
if len(kvs) > 1 {
log.Log.Errorf("More than one KubeVirt custom resource detected: %v", len(kvs))
return "", fmt.Errorf("more than one KubeVirt custom resource detected: %v", len(kvs))
}
if len(kvs) == 1 {
kv := kvs[0].(*virtv1.KubeVirt)
return controller.KeyFunc(kv)
}
return "", nil
}
func (c *WorkloadUpdateController) addMigration(obj interface{}) {
migration, ok := obj.(*virtv1.VirtualMachineInstanceMigration)
if !ok {
return
}
key, err := c.getKubeVirtKey()
if key == "" || err != nil {
return
}
if migration.Annotations != nil {
// only observe the migration expectation if our controller created it
_, ok = migration.Annotations[virtv1.WorkloadUpdateMigrationAnnotation]
if ok {
c.migrationExpectations.CreationObserved(key)
}
}
c.queue.AddAfter(key, defaultThrottleInterval)
}
func (c *WorkloadUpdateController) deleteMigration(_ interface{}) {
key, err := c.getKubeVirtKey()
if key == "" || err != nil {
return
}
c.queue.AddAfter(key, defaultThrottleInterval)
}
func (c *WorkloadUpdateController) updateMigration(_, _ interface{}) {
key, err := c.getKubeVirtKey()
if key == "" || err != nil {
return
}
c.queue.AddAfter(key, defaultThrottleInterval)
}
func (c *WorkloadUpdateController) updateVmi(_, obj interface{}) {
vmi, ok := obj.(*virtv1.VirtualMachineInstance)
if !ok {
return
}
key, err := c.getKubeVirtKey()
if key == "" || err != nil {
return
}
if vmi.IsFinal() {
return
}
if !isHotplugInProgress(vmi) || migrationutils.IsMigrating(vmi) {
return
}
c.queue.AddAfter(key, defaultThrottleInterval)
}
func (c *WorkloadUpdateController) addKubeVirt(obj interface{}) {
c.enqueueKubeVirt(obj)
}
func (c *WorkloadUpdateController) deleteKubeVirt(obj interface{}) {
c.enqueueKubeVirt(obj)
}
func (c *WorkloadUpdateController) updateKubeVirt(_, curr interface{}) {
c.enqueueKubeVirt(curr)
}
func (c *WorkloadUpdateController) enqueueKubeVirt(obj interface{}) {
logger := log.Log
kv, ok := obj.(*virtv1.KubeVirt)
if !ok {
return
}
key, err := controller.KeyFunc(kv)
if err != nil {
logger.Object(kv).Reason(err).Error("Failed to extract key from KubeVirt.")
return
}
c.queue.AddAfter(key, defaultThrottleInterval)
}
// Run runs the passed in NodeController.
func (c *WorkloadUpdateController) Run(stopCh <-chan struct{}) {
defer controller.HandlePanic()
defer c.queue.ShutDown()
log.Log.Info("Starting workload update controller.")
// This is hardcoded because there's no reason to make thread count
// configurable. The queue keys off the KubeVirt install object, and
// there can only be a single one of these in a cluster at a time.
threadiness := 1
// Wait for cache sync before we start the controller
cache.WaitForCacheSync(stopCh, c.migrationInformer.HasSynced, c.vmiInformer.HasSynced, c.podInformer.HasSynced, c.kubeVirtInformer.HasSynced)
// Start the actual work
for i := 0; i < threadiness; i++ {
go wait.Until(c.runWorker, time.Second, stopCh)
}
<-stopCh
log.Log.Info("Stopping workload update controller.")
}
func (c *WorkloadUpdateController) runWorker() {
for c.Execute() {
}
}
func (c *WorkloadUpdateController) Execute() bool {
key, quit := c.queue.Get()
if quit {
return false
}
defer c.queue.Done(key)
err := c.execute(key.(string))
if err != nil {
log.Log.Reason(err).Infof("reenqueuing workload updates for KubeVirt %v", key)
c.queue.AddRateLimited(key)
} else {
log.Log.V(4).Infof("processed workload updates for KubeVirt %v", key)
c.queue.Forget(key)
}
return true
}
func (c *WorkloadUpdateController) isOutdated(vmi *virtv1.VirtualMachineInstance) bool {
if vmi.IsFinal() {
return false
}
// if the launcher image isn't detected yet, that means
// we don't know what the launcher image is yet.
// This could be due to a migration, or the VMI is still
// initializing. virt-controller will set it for us once
// either the VMI is either running or done migrating.
if vmi.Status.LauncherContainerImageVersion == "" {
return false
} else if vmi.Status.LauncherContainerImageVersion != c.launcherImage {
return true
}
return false
}
func isHotplugInProgress(vmi *virtv1.VirtualMachineInstance) bool {
condManager := controller.NewVirtualMachineInstanceConditionManager()
return condManager.HasCondition(vmi, virtv1.VirtualMachineInstanceVCPUChange) ||
condManager.HasCondition(vmi, virtv1.VirtualMachineInstanceMemoryChange)
}
func (c *WorkloadUpdateController) doesRequireMigration(vmi *virtv1.VirtualMachineInstance) bool {
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))
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{}
lookup := make(map[string]bool)
migrations := migrationutils.ListUnfinishedMigrations(c.migrationInformer)
for _, migration := range migrations {
lookup[migration.Namespace+"/"+migration.Spec.VMIName] = true
}
automatedMigrationAllowed := false
automatedShutdownAllowed := false
for _, method := range kv.Spec.WorkloadUpdateStrategy.WorkloadUpdateMethods {
if method == virtv1.WorkloadUpdateMethodLiveMigrate {
automatedMigrationAllowed = true
} else if method == virtv1.WorkloadUpdateMethodEvict {
automatedShutdownAllowed = true
}
}
runningMigrations := migrationutils.FilterRunningMigrations(migrations)
data.numActiveMigrations = len(runningMigrations)
objs := c.vmiInformer.GetStore().List()
for _, obj := range objs {
vmi := obj.(*virtv1.VirtualMachineInstance)
switch {
case !vmi.IsRunning() || vmi.IsFinal() || vmi.DeletionTimestamp != nil:
// only consider running VMIs that aren't being shutdown
continue
case c.shouldAbortMigration(vmi) && !c.isOutdated(vmi):
data.abortChangeVMIs = append(data.abortChangeVMIs, vmi)
continue
case !c.isOutdated(vmi) && !c.doesRequireMigration(vmi):
continue
}
data.allOutdatedVMIs = append(data.allOutdatedVMIs, vmi)
// don't consider VMIs with migrations inflight as migratable for our dataset
// while a migrating workload can still be counted towards
// the outDatedVMIs list, we don't want to add it to any
// of the lists that results in actions being performed on them
if migrationutils.IsMigrating(vmi) {
continue
} else if exists := lookup[vmi.Namespace+"/"+vmi.Name]; exists {
continue
}
if automatedMigrationAllowed && vmi.IsMigratable() {
data.migratableOutdatedVMIs = append(data.migratableOutdatedVMIs, vmi)
} else if automatedShutdownAllowed {
data.evictOutdatedVMIs = append(data.evictOutdatedVMIs, vmi)
}
}
return data
}
func (c *WorkloadUpdateController) execute(key string) error {
obj, exists, err := c.kubeVirtInformer.GetStore().GetByKey(key)
if err != nil {
return err
} else if !exists {
c.migrationExpectations.DeleteExpectations(key)
return nil
}
// don't process anything until expectations are satisfied
// this ensures we don't do things like creating multiple
// migrations for the same vmi
if !c.migrationExpectations.SatisfiedExpectations(key) {
return nil
}
kv := obj.(*virtv1.KubeVirt)
// don't update workloads unless the infra is completely deployed and not updating
if kv.Status.Phase != virtv1.KubeVirtPhaseDeployed {
return nil
} else if kv.Status.ObservedDeploymentID != kv.Status.TargetDeploymentID {
return nil
}
return c.sync(kv)
}
func (c *WorkloadUpdateController) sync(kv *virtv1.KubeVirt) error {
data := c.getUpdateData(kv)
key, err := controller.KeyFunc(kv)
if err != nil {
return err
}
metrics.SetOutdatedVirtualMachineInstanceWorkloads(len(data.allOutdatedVMIs))
// update outdated workload count on kv
if kv.Status.OutdatedVirtualMachineInstanceWorkloads == nil || *kv.Status.OutdatedVirtualMachineInstanceWorkloads != len(data.allOutdatedVMIs) {
l := len(data.allOutdatedVMIs)
kvCopy := kv.DeepCopy()
kvCopy.Status.OutdatedVirtualMachineInstanceWorkloads = &l
oldJson, err := json.Marshal(kv.Status.OutdatedVirtualMachineInstanceWorkloads)
if err != nil {
return err
}
newJson, err := json.Marshal(kvCopy.Status.OutdatedVirtualMachineInstanceWorkloads)
if err != nil {
return err
}
patch := ""
if kv.Status.OutdatedVirtualMachineInstanceWorkloads == nil {
update := fmt.Sprintf(`{ "op": "add", "path": "/status/outdatedVirtualMachineInstanceWorkloads", "value": %s}`, string(newJson))
patch = fmt.Sprintf("[%s]", update)
} else {
test := fmt.Sprintf(`{ "op": "test", "path": "/status/outdatedVirtualMachineInstanceWorkloads", "value": %s}`, string(oldJson))
update := fmt.Sprintf(`{ "op": "replace", "path": "/status/outdatedVirtualMachineInstanceWorkloads", "value": %s}`, string(newJson))
patch = fmt.Sprintf("[%s, %s]", test, update)
}
err = c.statusUpdater.PatchStatus(kv, types.JSONPatchType, []byte(patch))
if err != nil {
return fmt.Errorf("unable to patch kubevirt obj status to update the outdatedVirtualMachineInstanceWorkloads valued: %v", err)
}
}
// 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 || len(data.abortChangeVMIs) != 0 {
c.queue.AddAfter(key, periodicReEnqueueIntervalSeconds)
}
// Randomizes list so we don't always re-attempt the same vmis in
// the event that some are having difficulty being relocated
rand.Shuffle(len(data.migratableOutdatedVMIs), func(i, j int) {
data.migratableOutdatedVMIs[i], data.migratableOutdatedVMIs[j] = data.migratableOutdatedVMIs[j], data.migratableOutdatedVMIs[i]
})
batchDeletionInterval := time.Duration(defaultBatchDeletionIntervalSeconds) * time.Second
batchDeletionCount := defaultBatchDeletionCount
if kv.Spec.WorkloadUpdateStrategy.BatchEvictionSize != nil {
batchDeletionCount = *kv.Spec.WorkloadUpdateStrategy.BatchEvictionSize
}
if kv.Spec.WorkloadUpdateStrategy.BatchEvictionInterval != nil {
batchDeletionInterval = kv.Spec.WorkloadUpdateStrategy.BatchEvictionInterval.Duration
}
now := time.Now()
nextBatch := c.lastDeletionBatch.Add(batchDeletionInterval)
if now.After(nextBatch) && len(data.evictOutdatedVMIs) > 0 {
batchDeletionCount = int(math.Min(float64(batchDeletionCount), float64(len(data.evictOutdatedVMIs))))
c.lastDeletionBatch = now
} else {
batchDeletionCount = 0
}
// This is a best effort attempt at not creating a bunch of pending migrations
// in the event that we've hit the global max. This check isn't meant to prevent
// overloading the cluster. The migration controller handles that. We're merely
// optimizing here by not introducing new migration objects we know can't be processed
// right now.
maxParallelMigrations := int(*c.clusterConfig.GetMigrationConfiguration().ParallelMigrationsPerCluster)
maxNewMigrations := maxParallelMigrations - data.numActiveMigrations
if maxNewMigrations < 0 {
maxNewMigrations = 0
}
migrateCount := int(math.Min(float64(maxNewMigrations), float64(len(data.migratableOutdatedVMIs))))
var migrationCandidates []*virtv1.VirtualMachineInstance
if migrateCount > 0 {
migrationCandidates = data.migratableOutdatedVMIs[0:migrateCount]
}
var evictionCandidates []*virtv1.VirtualMachineInstance
if batchDeletionCount > 0 {
evictionCandidates = data.evictOutdatedVMIs[0:batchDeletionCount]
}
wgLen := len(migrationCandidates) + len(evictionCandidates) + len(data.abortChangeVMIs)
wg := &sync.WaitGroup{}
wg.Add(wgLen)
errChan := make(chan error, wgLen)
c.migrationExpectations.ExpectCreations(key, migrateCount)
for _, vmi := range migrationCandidates {
go func(vmi *virtv1.VirtualMachineInstance) {
defer wg.Done()
createdMigration, err := c.clientset.VirtualMachineInstanceMigration(vmi.Namespace).Create(context.Background(), &virtv1.VirtualMachineInstanceMigration{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
virtv1.WorkloadUpdateMigrationAnnotation: "",
},
GenerateName: "kubevirt-workload-update-",
},
Spec: virtv1.VirtualMachineInstanceMigrationSpec{
VMIName: vmi.Name,
},
}, metav1.CreateOptions{})
if err != nil {
log.Log.Object(vmi).Reason(err).Errorf("Failed to migrate vmi as part of workload update")
c.migrationExpectations.CreationObserved(key)
c.recorder.Eventf(vmi, k8sv1.EventTypeWarning, FailedCreateVirtualMachineInstanceMigrationReason, "Error creating a Migration for automated workload update: %v", err)
errChan <- err
return
} else {
log.Log.Object(vmi).Infof("Initiated migration of vmi as part of workload update")
c.recorder.Eventf(vmi, k8sv1.EventTypeNormal, SuccessfulCreateVirtualMachineInstanceMigrationReason, "Created Migration %s for automated workload update", createdMigration.Name)
}
}(vmi)
}
for _, vmi := range evictionCandidates {
go func(vmi *virtv1.VirtualMachineInstance) {
defer wg.Done()
pod, err := controller.CurrentVMIPod(vmi, c.podInformer.GetIndexer())
if err != nil {
log.Log.Object(vmi).Reason(err).Errorf("Failed to detect active pod for vmi during workload update")
c.recorder.Eventf(vmi, k8sv1.EventTypeWarning, FailedEvictVirtualMachineInstanceReason, "Error detecting active pod for VMI during workload update: %v", err)
errChan <- err
}
err = c.clientset.CoreV1().Pods(vmi.Namespace).EvictV1beta1(context.Background(),
&policy.Eviction{
ObjectMeta: metav1.ObjectMeta{
Name: pod.Name,
Namespace: pod.Namespace,
},
DeleteOptions: &metav1.DeleteOptions{},
})
if err != nil && !errors.IsNotFound(err) {
log.Log.Object(vmi).Reason(err).Errorf("Failed to evict vmi as part of workload update")
c.recorder.Eventf(vmi, k8sv1.EventTypeWarning, FailedEvictVirtualMachineInstanceReason, "Error deleting VMI during automated workload update: %v", err)
errChan <- err
} else {
log.Log.Object(vmi).Infof("Evicted vmi pod as part of workload update")
c.recorder.Eventf(vmi, k8sv1.EventTypeNormal, SuccessfulEvictVirtualMachineInstanceReason, "Initiated eviction of VMI as part of automated workload update: %v", err)
}
}(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 {
case err := <-errChan:
return err
default:
}
return nil
}