Skip to content

Commit

Permalink
chore: upgrade ops is always running (#8417)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Nov 7, 2024
1 parent eb6f934 commit 1fd8585
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions pkg/operations/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package operations

import (
"fmt"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -100,28 +101,11 @@ func (u upgradeOpsHandler) ReconcileAction(reqCtx intctrlutil.RequestCtx, cli cl
if componentDefMap, err = u.getComponentDefMapWithUpdatedImages(reqCtx, cli, opsRes); err != nil {
return opsRes.OpsRequest.Status.Phase, 0, err
}
componentUpgraded := func(cluster *appsv1.Cluster,
lastCompConfiguration opsv1alpha1.LastComponentConfiguration,
upgradeComp opsv1alpha1.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 *opsv1alpha1.OpsRequest,
pod *corev1.Pod,
pgRes *progressResource) bool {
upgradeComponent := pgRes.compOps.(opsv1alpha1.UpgradeComponent)
lastCompConfiguration := opsRes.OpsRequest.Status.LastConfiguration.Components[upgradeComponent.GetComponentName()]
if !componentUpgraded(opsRes.Cluster, lastCompConfiguration, upgradeComponent) {
// if componentDefinition and serviceVersion no changes, return true
return true
}
compDef, ok := componentDefMap[upgradeComponent.GetComponentName()]
if !ok {
return true
Expand Down Expand Up @@ -179,14 +163,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 1fd8585

Please sign in to comment.