Skip to content

Commit

Permalink
optimize the situation where the ImageID remains unchanged but changi…
Browse files Browse the repository at this point in the history
…ng the Tag for in-place upgrades

Signed-off-by: liuzhenwei <dui_zhang@163.com>

optimize the situation for in-place upgrades in IsSidecarContainerUpdateCompleted method

Signed-off-by: liuzhenwei <dui_zhang@163.com>
  • Loading branch information
diannaowa committed May 14, 2023
1 parent 019ca89 commit bab03e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apis/apps/pub/inplace_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type InPlaceUpdateContainerBatch struct {
// to determine whether the InPlaceUpdate is completed.
type InPlaceUpdateContainerStatus struct {
ImageID string `json:"imageID,omitempty"`
ContainerID string `json:"containerID,omitempty""`
ContainerID string `json:"containerID,omitempty"`
}

// InPlaceUpdateStrategy defines the strategies for in-place update.
Expand Down
10 changes: 5 additions & 5 deletions pkg/control/sidecarcontrol/sidecarset_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ func (c *commonControl) UpdatePodAnnotationsInUpgrade(changedContainers []string
cStatus := make(map[string]string, len(pod.Status.ContainerStatuses))
for i := range pod.Status.ContainerStatuses {
c := &pod.Status.ContainerStatuses[i]
cStatus[c.Name] = fmt.Sprintf("%s %s", c.ImageID, c.ContainerID)
cStatus[c.Name] = fmt.Sprintf("%s,%s", c.ImageID, c.ContainerID)
}
for _, cName := range changedContainers {
cStatusItems := strings.Split(" ", cStatus[cName])
cStatusItems := strings.Split(cStatus[cName], ",")
updateStatus := pub.InPlaceUpdateContainerStatus{
ImageID: cStatusItems[0],
ContainerID: cStatusItems[1],
Expand Down Expand Up @@ -257,14 +257,14 @@ func IsSidecarContainerUpdateCompleted(pod *v1.Pod, sidecarSets, containers sets
if oldStatus, ok := lastContainerStatus[cs.Name]; ok {
// we assume that users should not update workload template with new image
// which actually has the same imageID as the old image
if oldStatus.ImageID == cs.ImageID && containerImages[cs.Name] != cs.Image {
klog.V(5).Infof("pod(%s/%s) container %s status imageID not changed, then inconsistent", pod.Namespace, pod.Name, cs.Name)
if oldStatus.ImageID == cs.ImageID && oldStatus.ContainerID == cs.ContainerID {
klog.V(5).Infof("pod(%s/%s) container %s status imageID and ContainerID not changed, then inconsistent", pod.Namespace, pod.Name, cs.Name)
return false
}
}
klog.V(5).Infof("pod(%s/%s) container %s status imageID and ContainerID changed, then consistent", pod.Namespace, pod.Name, cs.Name)
// If sidecar container status.ImageID changed, or this oldStatus ImageID don't exist
// indicate the sidecar container update is complete
}

return true
}
8 changes: 4 additions & 4 deletions pkg/util/inplaceupdate/inplace_update_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ func defaultCheckContainersInPlaceUpdateCompleted(pod *v1.Pod, inPlaceUpdateStat
for _, cs := range pod.Status.ContainerStatuses {
if oldStatus, ok := inPlaceUpdateState.LastContainerStatuses[cs.Name]; ok {
// TODO: we assume that users should not update workload template with new image which actually has the same imageID as the old image
if oldStatus.ImageID == cs.ImageID {
if oldStatus.ContainerID == cs.ContainerID || (cs.LastTerminationState.Terminated.ContainerID == oldStatus.ContainerID && !cs.Ready) {
return fmt.Errorf("container %s imageID not changed", cs.Name)
}
if oldStatus.ImageID == cs.ImageID && oldStatus.ContainerID == cs.ContainerID {
klog.V(5).Infof("container %s imageID or containerID not changed, in-place update not completed", cs.Name)
return fmt.Errorf("container %s imageID or containerID not changed", cs.Name)
}
klog.V(5).Infof("container %s imageID or containerID changed, in-place update completed", cs.Name)
delete(inPlaceUpdateState.LastContainerStatuses, cs.Name)
}
}
Expand Down

0 comments on commit bab03e4

Please sign in to comment.