@@ -25,6 +25,8 @@ package reconcile
2525import (
2626 "context"
2727
28+ "github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
29+
2830 "github.com/arangodb/kube-arangodb/pkg/util/errors"
2931
3032 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
@@ -56,41 +58,17 @@ type actionRotateMember struct {
5658// the start time needs to be recorded and a ready condition needs to be checked.
5759func (a * actionRotateMember ) Start (ctx context.Context ) (bool , error ) {
5860 log := a .log
59- group := a .action .Group
6061 m , ok := a .actionCtx .GetMemberStatusByID (a .action .MemberID )
6162 if ! ok {
6263 log .Error ().Msg ("No such member" )
6364 }
64- // Remove finalizers, so Kubernetes will quickly terminate the pod
65- if err := a .actionCtx .RemovePodFinalizers (m .PodName ); err != nil {
66- return false , errors .WithStack (err )
67- }
68- if group .IsArangod () {
69- // Invoke shutdown endpoint
70- c , err := a .actionCtx .GetServerClient (ctx , group , a .action .MemberID )
71- if err != nil {
72- log .Debug ().Err (err ).Msg ("Failed to create member client" )
73- return false , errors .WithStack (err )
74- }
75- removeFromCluster := false
76- log .Debug ().Bool ("removeFromCluster" , removeFromCluster ).Msg ("Shutting down member" )
77- ctx , cancel := context .WithTimeout (ctx , shutdownTimeout )
78- defer cancel ()
79- if err := c .Shutdown (ctx , removeFromCluster ); err != nil {
80- // Shutdown failed. Let's check if we're already done
81- if ready , _ , err := a .CheckProgress (ctx ); err == nil && ready {
82- // We're done
83- return true , nil
84- }
85- log .Debug ().Err (err ).Msg ("Failed to shutdown member" )
86- return false , errors .WithStack (err )
87- }
88- } else if group .IsArangosync () {
89- // Terminate pod
90- if err := a .actionCtx .DeletePod (m .PodName ); err != nil {
91- return false , errors .WithStack (err )
92- }
65+
66+ if ready , err := getShutdownHelper (& a .action , a .actionCtx , a .log ).Start (ctx ); err != nil {
67+ return false , err
68+ } else if ready {
69+ return true , nil
9370 }
71+
9472 // Update status
9573 m .Phase = api .MemberPhaseRotating
9674
@@ -110,13 +88,18 @@ func (a *actionRotateMember) CheckProgress(ctx context.Context) (bool, bool, err
11088 log .Error ().Msg ("No such member" )
11189 return true , false , nil
11290 }
113- if ! m .Conditions .IsTrue (api .ConditionTypeTerminated ) {
114- // Pod is not yet terminated
91+
92+ if ready , abort , err := getShutdownHelper (& a .action , a .actionCtx , a .log ).CheckProgress (ctx ); err != nil {
93+ return false , abort , err
94+ } else if ! ready {
11595 return false , false , nil
11696 }
97+
11798 // Pod is terminated, we can now remove it
11899 if err := a .actionCtx .DeletePod (m .PodName ); err != nil {
119- return false , false , errors .WithStack (err )
100+ if ! k8sutil .IsNotFound (err ) {
101+ return false , false , errors .WithStack (err )
102+ }
120103 }
121104 // Pod is now gone, update the member status
122105 m .Phase = api .MemberPhaseNone
0 commit comments