Reconcile converges the shard runtime.
(ctx context.Context, _ ctrl.Request)
| 72 | |
| 73 | // Reconcile converges the shard runtime. |
| 74 | func (r *ShardSetReconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) { |
| 75 | logger := log.FromContext(ctx) |
| 76 | |
| 77 | flux := &appsv1.Deployment{} |
| 78 | err := r.Get(ctx, types.NamespacedName{Namespace: r.Config.FluxNamespace, Name: FluxDeploymentName}, flux) |
| 79 | if apierrors.IsNotFound(err) { |
| 80 | logger.Info("flux Deployment not found yet, waiting", "namespace", r.Config.FluxNamespace) |
| 81 | return ctrl.Result{RequeueAfter: provisionRetry}, nil |
| 82 | } |
| 83 | if err != nil { |
| 84 | return ctrl.Result{}, fmt.Errorf("getting flux Deployment: %w", err) |
| 85 | } |
| 86 | |
| 87 | shardCount, err := r.effectiveShardCount(ctx) |
| 88 | if err != nil { |
| 89 | return ctrl.Result{}, err |
| 90 | } |
| 91 | |
| 92 | for i := 0; i < shardCount; i++ { |
| 93 | desired, err := BuildShardDeployment(flux, i, r.Config) |
| 94 | if err != nil { |
| 95 | return ctrl.Result{}, err |
| 96 | } |
| 97 | if err := r.Patch(ctx, desired, client.Apply, client.FieldOwner(FieldOwner), client.ForceOwnership); err != nil { |
| 98 | return ctrl.Result{}, fmt.Errorf("applying %s: %w", desired.Name, err) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | blocked := false |
| 103 | |
| 104 | pruneBlocked, err := r.pruneExtraShards(ctx, shardCount) |
| 105 | if err != nil { |
| 106 | return ctrl.Result{}, err |
| 107 | } |
| 108 | blocked = blocked || pruneBlocked |
| 109 | |
| 110 | legacyBlocked, err := r.retireLegacy(ctx) |
| 111 | if err != nil { |
| 112 | return ctrl.Result{}, err |
| 113 | } |
| 114 | blocked = blocked || legacyBlocked |
| 115 | |
| 116 | if blocked { |
| 117 | return ctrl.Result{RequeueAfter: provisionRetry}, nil |
| 118 | } |
| 119 | return ctrl.Result{}, nil |
| 120 | } |
| 121 | |
| 122 | // effectiveShardCount resolves the shard count for this sync: the configured |
| 123 | // value, or in auto mode the recommendation with hysteresis anchored on the |
nothing calls this directly
no test coverage detected