@@ -29,8 +29,6 @@ import (
2929 "github.com/arangodb/kube-arangodb/pkg/apis/deployment"
3030 "github.com/arangodb/kube-arangodb/pkg/deployment/pod"
3131
32- "github.com/arangodb/kube-arangodb/pkg/deployment/pod"
33-
3432 "github.com/arangodb/go-driver"
3533 upgraderules "github.com/arangodb/go-upgrade-rules"
3634 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@@ -85,9 +83,17 @@ func createRotateOrUpgradePlan(log zerolog.Logger, apiObject k8sutil.APIObject,
8583 ! decision .AutoUpgradeNeeded )
8684 } else {
8785 // Upgrade is not needed, see if rotation is needed
88- rotNeeded , reason := podNeedsRotation (log , pod , apiObject , spec , group , status , m .ID , context )
89- if rotNeeded {
90- newPlan = createRotateMemberPlan (log , m , group , reason )
86+ if m .PodUID == "" {
87+ rotNeeded , reason := podNeedsRotation (log , pod , apiObject , spec , group , status , m .ID , context )
88+ if rotNeeded {
89+ newPlan = createRotateMemberPlan (log , m , group , reason )
90+ }
91+ } else {
92+ // Use new level of rotate logic
93+ rotNeeded , reason := podNeedsRotationNew (log , pod , apiObject , spec , group , status , m , context )
94+ if rotNeeded {
95+ newPlan = createRotateMemberPlan (log , m , group , reason )
96+ }
9197 }
9298 }
9399
@@ -186,6 +192,46 @@ func podNeedsUpgrading(log zerolog.Logger, p core.Pod, spec api.DeploymentSpec,
186192 return upgradeDecision {UpgradeNeeded : false }
187193}
188194
195+ // podNeedsRotationNew returns true when the specification of the
196+ // given pod differs from what it should be according to the
197+ // given deployment spec.
198+ // When true is returned, a reason for the rotation is already returned.
199+ func podNeedsRotationNew (log zerolog.Logger , p core.Pod , apiObject metav1.Object , spec api.DeploymentSpec ,
200+ group api.ServerGroup , status api.DeploymentStatus , m api.MemberStatus ,
201+ context PlanBuilderContext ) (bool , string ) {
202+ if m .PodUID != p .UID {
203+ return true , "Pod UID does not match, this pod is not managed by Operator. Recreating"
204+ }
205+
206+ if m .PodSpecVersion == "" {
207+ return true , "Pod Spec Version is nil - recreating pod"
208+ }
209+
210+ imageInfo , imageFound := context .SelectImage (spec , status )
211+ if ! imageFound {
212+ // Image is not found, so rotation is not needed
213+ return false , ""
214+ }
215+
216+ renderedPod , err := context .RenderPodForMember (spec , status , m .ID , imageInfo )
217+ if err != nil {
218+ log .Err (err ).Msg ("Error while rendering pod" )
219+ return false , ""
220+ }
221+
222+ checksum , err := k8sutil .GetPodSpecChecksum (renderedPod .Spec )
223+ if err != nil {
224+ log .Err (err ).Msg ("Error while getting pod checksum" )
225+ return false , ""
226+ }
227+
228+ if m .PodSpecVersion != checksum {
229+ return true , "Pod needs rotation - checksum does not match"
230+ }
231+
232+ return false , ""
233+ }
234+
189235// podNeedsRotation returns true when the specification of the
190236// given pod differs from what it should be according to the
191237// given deployment spec.
0 commit comments