Skip to content

Commit

Permalink
squash: return reconcileResult directly
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <[email protected]>
  • Loading branch information
ncdc committed Mar 16, 2023
1 parent 7547f60 commit 539f493
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,19 @@ func (c *controller) reconcilePlacementBind(
_ string,
ns *corev1.Namespace,
) (reconcileResult, error) {
result := reconcileResult{}
clusterName := logicalcluster.From(ns)

validPlacements, err := c.validPlacements(clusterName, ns)
if err != nil {
result.stop = true
return result, err
return reconcileResult{stop: true}, err
}

_, hasPlacement := ns.Annotations[schedulingv1alpha1.PlacementAnnotationKey]
shouldHavePlacement := len(validPlacements) > 0

switch {
case shouldHavePlacement && hasPlacement, !shouldHavePlacement && !hasPlacement:
return result, nil
return reconcileResult{}, nil
case shouldHavePlacement && !hasPlacement:
if ns.Annotations == nil {
ns.Annotations = make(map[string]string)
Expand All @@ -63,8 +61,7 @@ func (c *controller) reconcilePlacementBind(
delete(ns.Annotations, schedulingv1alpha1.PlacementAnnotationKey)
}

result.stop = true
return result, nil
return reconcileResult{stop: true}, nil
}

func (c *controller) validPlacements(clusterName logicalcluster.Name, ns *corev1.Namespace) ([]*schedulingv1alpha1.Placement, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ const removingGracePeriod = 5 * time.Second
// on each placement.
func (c *controller) reconcileScheduling(
ctx context.Context,
key string,
_ string,
ns *corev1.Namespace,
) (reconcileResult, error) {
result := reconcileResult{}
logger := klog.FromContext(ctx)
clusterName := logicalcluster.From(ns)

Expand All @@ -51,7 +50,7 @@ func (c *controller) reconcileScheduling(
if foundPlacement {
placements, err := c.listPlacements(clusterName)
if err != nil {
return result, err
return reconcileResult{}, err
}

validPlacements = filterValidPlacements(ns, placements)
Expand Down Expand Up @@ -120,16 +119,13 @@ func (c *controller) reconcileScheduling(
}

// 6. Requeue at last to check if removing syncTarget should be removed later.
var requeueAfter time.Duration
if minEnqueueDuration <= removingGracePeriod {
logger.WithValues("after", minEnqueueDuration).V(2).Info("enqueue Namespace later")
result.requeueAfter = minEnqueueDuration
requeueAfter = minEnqueueDuration
}

if changed {
result.stop = true
}

return result, nil
return reconcileResult{stop: changed, requeueAfter: requeueAfter}, nil
}

func syncStatusFor(ns *corev1.Namespace) namespaceSyncStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,26 @@ const (
// reconcileStatus ensures the status of the given namespace reflects the
// namespace's scheduled state.
func (c *controller) reconcileStatus(_ context.Context, _ string, ns *corev1.Namespace) (reconcileResult, error) {
result := reconcileResult{}
conditionsAdapter := &NamespaceConditionsAdapter{ns}

_, found := ns.Annotations[schedulingv1alpha1.PlacementAnnotationKey]
if !found {
conditions.MarkFalse(conditionsAdapter, NamespaceScheduled, NamespaceReasonUnschedulable,
conditionsv1alpha1.ConditionSeverityNone, // NamespaceCondition doesn't support severity
"No available placements")
return result, nil
return reconcileResult{}, nil
}

syncStatus := syncStatusFor(ns)
if len(syncStatus.active) == 0 {
conditions.MarkFalse(conditionsAdapter, NamespaceScheduled, NamespaceReasonUnschedulable,
conditionsv1alpha1.ConditionSeverityNone, // NamespaceCondition doesn't support severity
"No available sync targets")
return result, nil
return reconcileResult{}, nil
}

conditions.MarkTrue(conditionsAdapter, NamespaceScheduled)
return result, nil
return reconcileResult{}, nil
}

// NamespaceConditionsAdapter enables the use of the conditions helper
Expand Down

0 comments on commit 539f493

Please sign in to comment.