Skip to content

Commit 14f7104

Browse files
author
Arvind Thirumurugan
committed
address comments
1 parent d7eebb8 commit 14f7104

2 files changed

Lines changed: 10 additions & 24 deletions

File tree

tools/draincluster/drain/drain.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tools/uncordoncluster/uncordon/uncordon.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ func (h *Helper) Uncordon(ctx context.Context) error {
3434
}
3535

3636
// remove cordon taint from member cluster.
37-
cordonTaintIndex := -1
37+
var newTaints []clusterv1beta1.Taint
3838
for i := range mc.Spec.Taints {
3939
taint := mc.Spec.Taints[i]
4040
if taint == toolsutils.CordonTaint {
41-
cordonTaintIndex = i
42-
break
41+
continue
4342
}
43+
newTaints = append(newTaints, taint)
4444
}
45-
46-
if cordonTaintIndex >= 0 {
47-
mc.Spec.Taints = append(mc.Spec.Taints[:cordonTaintIndex], mc.Spec.Taints[cordonTaintIndex+1:]...)
48-
} else {
49-
return nil
50-
}
45+
mc.Spec.Taints = newTaints
5146

5247
return h.HubClient.Update(ctx, &mc)
5348
})

0 commit comments

Comments
 (0)