@@ -40,6 +40,7 @@ func (h *Helper) Drain(ctx context.Context) (bool, error) {
4040 if err := h .cordon (ctx ); err != nil {
4141 return false , fmt .Errorf ("failed to cordon member cluster %s: %w" , h .ClusterName , err )
4242 }
43+ log .Printf ("Successfully cordoned member cluster %s by addding cordon taint" , h .ClusterName )
4344
4445 if err := h .fetchClusterResourcePlacementToEvict (ctx ); err != nil {
4546 return false , err
@@ -50,6 +51,7 @@ func (h *Helper) Drain(ctx context.Context) (bool, error) {
5051 return true , nil
5152 }
5253
54+ isDrainSuccessful := true
5355 // create eviction objects for all <crpName, targetCluster>.
5456 for crpName := range h .ClusterResourcePlacementResourcesMap {
5557 evictionName := fmt .Sprintf (drainEvictionNameFormat , crpName , h .ClusterName )
@@ -76,13 +78,10 @@ func (h *Helper) Drain(ctx context.Context) (bool, error) {
7678 if err != nil {
7779 return false , fmt .Errorf ("failed to create eviction for CRP %s: %w" , crpName , err )
7880 }
79- }
8081
81- // wait until all evictions reach a terminal state.
82- for crpName := range h .ClusterResourcePlacementResourcesMap {
83- err := wait .ExponentialBackoffWithContext (ctx , retry .DefaultBackoff , func (ctx context.Context ) (bool , error ) {
84- evictionName := fmt .Sprintf (drainEvictionNameFormat , crpName , h .ClusterName )
85- eviction := placementv1beta1.ClusterResourcePlacementEviction {}
82+ // wait until evictions reach a terminal state.
83+ var eviction placementv1beta1.ClusterResourcePlacementEviction
84+ err = wait .ExponentialBackoffWithContext (ctx , retry .DefaultBackoff , func (ctx context.Context ) (bool , error ) {
8685 if err := h .HubClient .Get (ctx , types.NamespacedName {Name : evictionName }, & eviction ); err != nil {
8786 return false , fmt .Errorf ("failed to get eviction %s: %w" , evictionName , err )
8887 }
@@ -92,15 +91,7 @@ func (h *Helper) Drain(ctx context.Context) (bool, error) {
9291 if err != nil {
9392 return false , fmt .Errorf ("failed to wait for evictions to reach terminal state: %w" , err )
9493 }
95- }
9694
97- isDrainSuccessful := true
98- for crpName := range h .ClusterResourcePlacementResourcesMap {
99- evictionName := fmt .Sprintf (drainEvictionNameFormat , crpName , h .ClusterName )
100- eviction := placementv1beta1.ClusterResourcePlacementEviction {}
101- if err := h .HubClient .Get (ctx , types.NamespacedName {Name : evictionName }, & eviction ); err != nil {
102- return false , fmt .Errorf ("failed to get eviction %s: %w" , evictionName , err )
103- }
10495 validCondition := eviction .GetCondition (string (placementv1beta1 .PlacementEvictionConditionTypeValid ))
10596 if validCondition != nil && validCondition .Status == metav1 .ConditionFalse {
10697 // check to see if CRP is missing or CRP is being deleted or CRB is missing.
@@ -120,7 +111,7 @@ func (h *Helper) Drain(ctx context.Context) (bool, error) {
120111 // log each resource evicted by CRP.
121112 for i := range h .ClusterResourcePlacementResourcesMap [crpName ] {
122113 resourceIdentifier := h.ClusterResourcePlacementResourcesMap [crpName ][i ]
123- log .Printf ("evicted resource %s propagated by CRP %s" , fmt .Sprintf (resourceIdentifierKeyFormat , resourceIdentifier .Group , resourceIdentifier .Version , resourceIdentifier .Kind , resourceIdentifier .Name , resourceIdentifier .Namespace ), crpName )
114+ log .Printf ("evicted resource %s propagated by CRP %s" , fmt .Sprintf (resourceIdentifierKeyFormat , resourceIdentifier .Group , resourceIdentifier .Version , resourceIdentifier .Kind , resourceIdentifier .Namespace , resourceIdentifier .Name ), crpName )
124115 }
125116 }
126117
0 commit comments