diff --git a/pkg/controller/sidecarset/sidecarset_processor.go b/pkg/controller/sidecarset/sidecarset_processor.go index 0d50e31553..bac2b832ed 100644 --- a/pkg/controller/sidecarset/sidecarset_processor.go +++ b/pkg/controller/sidecarset/sidecarset_processor.go @@ -155,7 +155,13 @@ func (p *Processor) UpdateSidecarSet(sidecarSet *appsv1alpha1.SidecarSet) (recon func (p *Processor) updatePods(control sidecarcontrol.SidecarControl, pods []*corev1.Pod) error { sidecarset := control.GetSidecarset() // compute next updated pods based on the sidecarset upgrade strategy - upgradePods := NewStrategy().GetNextUpgradePods(control, pods) + upgradePods, notUpgradablePods := NewStrategy().GetNextUpgradePods(control, pods) + if len(notUpgradablePods) > 0 { + // send event for pods that are not upgradable, so that user can know the reason + for _, pod := range notUpgradablePods { + p.recorder.Eventf(pod, corev1.EventTypeNormal, "SidecarSetNotUpgradable", "SidecarSet %s is not upgradable for this pod", sidecarset.Name) + } + } if len(upgradePods) == 0 { klog.V(3).Infof("sidecarSet next update is nil, skip this round, name: %s", sidecarset.Name) return nil diff --git a/pkg/controller/sidecarset/sidecarset_strategy.go b/pkg/controller/sidecarset/sidecarset_strategy.go index edb14d0295..81ae25d590 100644 --- a/pkg/controller/sidecarset/sidecarset_strategy.go +++ b/pkg/controller/sidecarset/sidecarset_strategy.go @@ -22,7 +22,8 @@ type Strategy interface { //2. Sort Pods with default sequence //3. sort waitUpdateIndexes based on the scatter rules //4. calculate max count of pods can update with maxUnavailable - GetNextUpgradePods(control sidecarcontrol.SidecarControl, pods []*corev1.Pod) []*corev1.Pod + //5. also return the pods that are not upgradable + GetNextUpgradePods(control sidecarcontrol.SidecarControl, pods []*corev1.Pod) (upgradePods []*corev1.Pod, notUpgradablePods []*corev1.Pod) } type spreadingStrategy struct{} @@ -35,10 +36,12 @@ func NewStrategy() Strategy { return globalSpreadingStrategy } -func (p *spreadingStrategy) GetNextUpgradePods(control sidecarcontrol.SidecarControl, pods []*corev1.Pod) (upgradePods []*corev1.Pod) { +func (p *spreadingStrategy) GetNextUpgradePods(control sidecarcontrol.SidecarControl, pods []*corev1.Pod) (upgradePods []*corev1.Pod, notUpgradablePods []*corev1.Pod) { sidecarset := control.GetSidecarset() // wait to upgrade pod index var waitUpgradedIndexes []int + // the pod that are not upgradable, will be skipped + var notUpgradableIndexes []int strategy := sidecarset.Spec.UpdateStrategy // If selector is not nil, check whether the pods is selected to upgrade @@ -68,12 +71,16 @@ func (p *spreadingStrategy) GetNextUpgradePods(control sidecarcontrol.SidecarCon // * It is to determine whether there are other fields that have been modified for pod. for index, pod := range pods { isUpdated := sidecarcontrol.IsPodSidecarUpdated(sidecarset, pod) - if !isUpdated && isSelected(pod) && control.IsSidecarSetUpgradable(pod) { - waitUpgradedIndexes = append(waitUpgradedIndexes, index) + if !isUpdated && isSelected(pod) { + if control.IsSidecarSetUpgradable(pod) { + waitUpgradedIndexes = append(waitUpgradedIndexes, index) + } else { + notUpgradableIndexes = append(notUpgradableIndexes, index) + } } } - klog.V(3).Infof("sidecarSet(%s) matchedPods(%d) waitUpdated(%d)", sidecarset.Name, len(pods), len(waitUpgradedIndexes)) + klog.V(3).Infof("sidecarSet(%s) matchedPods(%d) waitUpdated(%d) notUpgradable(%d)", sidecarset.Name, len(pods), len(waitUpgradedIndexes), len(notUpgradableIndexes)) //2. sort Pods with default sequence and scatter waitUpgradedIndexes = SortUpdateIndexes(strategy, pods, waitUpgradedIndexes) @@ -87,6 +94,10 @@ func (p *spreadingStrategy) GetNextUpgradePods(control sidecarcontrol.SidecarCon for _, idx := range waitUpgradedIndexes { upgradePods = append(upgradePods, pods[idx]) } + // 5. pods that are not upgradable will not be skipped in the following process + for _, idx := range notUpgradableIndexes { + notUpgradablePods = append(notUpgradablePods, pods[idx]) + } return }