Skip to content

Commit

Permalink
chore: upgrade ops always running (#8420)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Nov 7, 2024
1 parent cd4b7e0 commit d8b3f9f
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions controllers/apps/operations/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package operations
import (
"context"
"fmt"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -118,18 +119,6 @@ func (u upgradeOpsHandler) ReconcileAction(reqCtx intctrlutil.RequestCtx, cli cl
return opsRes.OpsRequest.Status.Phase, 0, err
}
}
componentUpgraded := func(cluster *appsv1alpha1.Cluster,
lastCompConfiguration appsv1alpha1.LastComponentConfiguration,
upgradeComp appsv1alpha1.UpgradeComponent) bool {
if u.needUpdateCompDef(upgradeComp, opsRes.Cluster) &&
lastCompConfiguration.ComponentDefinitionName != *upgradeComp.ComponentDefinitionName {
return true
}
if upgradeComp.ServiceVersion != nil && lastCompConfiguration.ServiceVersion != *upgradeComp.ServiceVersion {
return true
}
return false
}
podApplyCompOps := func(
ops *appsv1alpha1.OpsRequest,
pod *corev1.Pod,
Expand All @@ -147,12 +136,6 @@ func (u upgradeOpsHandler) ReconcileAction(reqCtx intctrlutil.RequestCtx, cli cl
}
return u.podImageApplied(pod, compVersion.VersionsCtx.Containers)
}
upgradeComponent := compOps.(appsv1alpha1.UpgradeComponent)
lastCompConfiguration := opsRes.OpsRequest.Status.LastConfiguration.Components[compOps.GetComponentName()]
if !componentUpgraded(opsRes.Cluster, lastCompConfiguration, upgradeComponent) {
// if componentDefinition and serviceVersion no changes, return true
return true
}
compDef, ok := componentDefMap[compOps.GetComponentName()]
if !ok {
return true
Expand Down Expand Up @@ -236,14 +219,18 @@ func (u upgradeOpsHandler) podImageApplied(pod *corev1.Pod, expectContainers []c
if len(expectContainers) == 0 {
return true
}
imageName := func(image string) string {
images := strings.Split(image, "/")
return images[len(images)-1]
}
for _, v := range expectContainers {
for _, cs := range pod.Status.ContainerStatuses {
if cs.Name == v.Name && cs.Image != v.Image {
if cs.Name == v.Name && imageName(cs.Image) != imageName(v.Image) {
return false
}
}
for _, c := range pod.Spec.Containers {
if c.Name == v.Name && c.Image != v.Image {
if c.Name == v.Name && imageName(c.Image) != imageName(v.Image) {
return false
}
}
Expand Down

0 comments on commit d8b3f9f

Please sign in to comment.