@@ -411,35 +411,35 @@ func (dsc *DaemonSetsController) dedupCurHistories(ctx context.Context, ds *apps
411
411
maxRevision = cur .Revision
412
412
}
413
413
}
414
- // Clean up duplicates and relabel pods
414
+ // Relabel pods before dedup
415
+ pods , err := dsc .getDaemonPods (ctx , ds )
416
+ if err != nil {
417
+ return nil , err
418
+ }
419
+ for _ , pod := range pods {
420
+ if pod .Labels [apps .DefaultDaemonSetUniqueLabelKey ] != keepCur .Labels [apps .DefaultDaemonSetUniqueLabelKey ] {
421
+ patchRaw := map [string ]interface {}{
422
+ "metadata" : map [string ]interface {}{
423
+ "labels" : map [string ]interface {}{
424
+ apps .DefaultDaemonSetUniqueLabelKey : keepCur .Labels [apps .DefaultDaemonSetUniqueLabelKey ],
425
+ },
426
+ },
427
+ }
428
+ patchJSON , err := json .Marshal (patchRaw )
429
+ if err != nil {
430
+ return nil , err
431
+ }
432
+ _ , err = dsc .kubeClient .CoreV1 ().Pods (ds .Namespace ).Patch (ctx , pod .Name , types .MergePatchType , patchJSON , metav1.PatchOptions {})
433
+ if err != nil {
434
+ return nil , err
435
+ }
436
+ }
437
+ }
438
+ // Clean up duplicates
415
439
for _ , cur := range curHistories {
416
440
if cur .Name == keepCur .Name {
417
441
continue
418
442
}
419
- // Relabel pods before dedup
420
- pods , err := dsc .getDaemonPods (ctx , ds )
421
- if err != nil {
422
- return nil , err
423
- }
424
- for _ , pod := range pods {
425
- if pod .Labels [apps .DefaultDaemonSetUniqueLabelKey ] != keepCur .Labels [apps .DefaultDaemonSetUniqueLabelKey ] {
426
- patchRaw := map [string ]interface {}{
427
- "metadata" : map [string ]interface {}{
428
- "labels" : map [string ]interface {}{
429
- apps .DefaultDaemonSetUniqueLabelKey : keepCur .Labels [apps .DefaultDaemonSetUniqueLabelKey ],
430
- },
431
- },
432
- }
433
- patchJson , err := json .Marshal (patchRaw )
434
- if err != nil {
435
- return nil , err
436
- }
437
- _ , err = dsc .kubeClient .CoreV1 ().Pods (ds .Namespace ).Patch (ctx , pod .Name , types .MergePatchType , patchJson , metav1.PatchOptions {})
438
- if err != nil {
439
- return nil , err
440
- }
441
- }
442
- }
443
443
// Remove duplicates
444
444
err = dsc .kubeClient .AppsV1 ().ControllerRevisions (ds .Namespace ).Delete (ctx , cur .Name , metav1.DeleteOptions {})
445
445
if err != nil {
0 commit comments