mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 21:36:24 +00:00
Merge pull request #108349 from LastNight1997/optimize-dedup
optimize dedupCurHistories func in DaemonSetsController
This commit is contained in:
commit
de7d9a9897
@ -411,11 +411,6 @@ func (dsc *DaemonSetsController) dedupCurHistories(ctx context.Context, ds *apps
|
|||||||
maxRevision = cur.Revision
|
maxRevision = cur.Revision
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clean up duplicates and relabel pods
|
|
||||||
for _, cur := range curHistories {
|
|
||||||
if cur.Name == keepCur.Name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Relabel pods before dedup
|
// Relabel pods before dedup
|
||||||
pods, err := dsc.getDaemonPods(ctx, ds)
|
pods, err := dsc.getDaemonPods(ctx, ds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -430,16 +425,21 @@ func (dsc *DaemonSetsController) dedupCurHistories(ctx context.Context, ds *apps
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
patchJson, err := json.Marshal(patchRaw)
|
patchJSON, err := json.Marshal(patchRaw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
_, err = dsc.kubeClient.CoreV1().Pods(ds.Namespace).Patch(ctx, pod.Name, types.MergePatchType, patchJson, metav1.PatchOptions{})
|
_, err = dsc.kubeClient.CoreV1().Pods(ds.Namespace).Patch(ctx, pod.Name, types.MergePatchType, patchJSON, metav1.PatchOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Clean up duplicates
|
||||||
|
for _, cur := range curHistories {
|
||||||
|
if cur.Name == keepCur.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Remove duplicates
|
// Remove duplicates
|
||||||
err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(ctx, cur.Name, metav1.DeleteOptions{})
|
err = dsc.kubeClient.AppsV1().ControllerRevisions(ds.Namespace).Delete(ctx, cur.Name, metav1.DeleteOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user