|
// 调谐逻辑主要做事的函数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}
|
|