找回密码
 会员注册
查看: 17|回复: 0

SidecarSet到底如何实现|OpenKruise源码浅析

[复制链接]

2万

主题

0

回帖

7万

积分

超级版主

积分
72278
发表于 2024-10-6 15:09:34 | 显示全部楼层 |阅读模式
// 调谐逻辑主要做事的函数func (p *Processor) UpdateSidecarSet(sidecarSet *appsv1alpha1.SidecarSet) (reconcile.Result, error) { ...... // 1. get matching pods with the sidecarSet pods, err := p.getMatchingPods(sidecarSet) // 2. calculate SidecarSet status based on pods status := calculateStatus(control, pods) ...... // 3. If sidecar container hot upgrade complete, then set the other one(empty sidecar container) image to HotUpgradeEmptyImage if isSidecarSetHasHotUpgradeContainer(sidecarSet) { var podsInHotUpgrading []*corev1.Pod for _, pod := range pods { // flip other hot sidecar container to empty, in the following: // 1. the empty sidecar container image isn't equal HotUpgradeEmptyImage // 2. all containers with exception of empty sidecar containers is updated and consistent // 3. all containers with exception of empty sidecar containers is ready // don't contain sidecar empty containers sidecarContainers := sidecarcontrol.GetSidecarContainersInPod(sidecarSet) for _, sidecarContainer := range sidecarSet.Spec.Containers { if sidecarcontrol.IsHotUpgradeContainer(&sidecarContainer) { _, emptyContainer := sidecarcontrol.GetPodHotUpgradeContainers(sidecarContainer.Name, pod) sidecarContainers.Delete(emptyContainer) } } if isPodSidecarInHotUpgrading(sidecarSet, pod) & control.IsPodUpdatedConsistently(pod, sidecarContainers) & isHotUpgradingReady(sidecarSet, pod) { podsInHotUpgrading = append(podsInHotUpgrading, pod) } } if err := p.flipHotUpgradingContainers(control, podsInHotUpgrading); err != nil { return reconcile.Result{}, err } } // 4. SidecarSet upgrade strategy type is NotUpdate if !isSidecarSetNotUpdate(sidecarSet) { return reconcile.Result{}, nil } // 5. sidecarset already updates all matched pods, then return if isSidecarSetUpdateFinish(status) { klog.V(3).Infof("sidecarSet(%s) matched pods(number=%d) are latest, and don't need update", sidecarSet.Name, len(pods)) return reconcile.Result{}, nil } // 6. Paused indicates that the SidecarSet is paused to update matched pods if sidecarSet.Spec.UpdateStrategy.Paused { klog.V(3).Infof("sidecarSet is paused, name: %s", sidecarSet.Name) return reconcile.Result{}, nil } // 7. upgrade pod sidecar if err := p.updatePods(control, pods); err != nil { return reconcile.Result{}, err } return reconcile.Result{}, nil}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-11 09:55 , Processed in 0.442761 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表