Limit cluster guessing to the interactive wizard · Entire
Limit cluster guessing to the interactive wizard
68e81f3→main·
toothbrush·3w ago·2 files·+11 added/-140 removed
Revert the one-shot repo mirror create <url> to the fixed defaultClusterHost
when [cluster-host] is omitted; catalog/jurisdiction-based cluster guessing is
now confined to the no-args interactive wizard, so non-interactive invocations
(and scripts) keep stable, predictable defaults. remove/collaborators were
already on the fixed default and are unchanged.
Drops the one-shot-only resolveDefaultClusterHost/callerJurisdiction/
pickDefaultRegionHost helpers; the wizard keeps its jurisdiction-aware region
pre-selection.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
a03599d356ffView transcript
Changes
2
cmd/entire/cli
Mrepo_mirror.go+11/-87
Mrepo_mirror_test.go-53
144 unmodified lines
145
146
147
148
149
148
149
150
151
152
153
7 unmodified lines
161
162
163
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
164
165
166
167
168
169
170
171
172
173
174
12 unmodified lines
187
188
189
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
190
191
192
144 unmodified lines
"the target cluster, then waits for the initial GitHub→EntireDB clone " +
"to finish so `git clone` works on return. Pass --no-wait to return " +
"as soon as the placement is registered. Idempotent on " +
"(upstream, cluster). The cluster-host defaults to your catalog's " +
"default cluster when omitted.",
"(upstream, cluster). The cluster-host defaults to " +
defaultClusterHost + " when omitted (the interactive wizard, with " +
"no args, instead lets you pick clusters).",
Example: " entire repo mirror create\n" +
" entire repo mirror create github.com/octocat/hello-world\n" +
" entire repo mirror create github.com/octocat/hello-world aws-us-east-2.entire.io"
7 unmodified lines
cmd.SilenceUsage = true
return fmt.Errorf("invalid <github-url>: %w", err)
}
var clusterHost string
if len(args) > 1 {
clusterHost = args[1]
if err := validateClusterHost(clusterHost); err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("invalid [cluster-host]: %w", err)
}
} else {
// No cluster given: pick the catalog's default cluster (the same
// GET /api/v1/clusters source the wizard uses), resolved via the
// active context. runCore owns the active-client preamble
// (silence-usage, --insecure-http-auth, error mapping).
if err := runCore(cmd, func(ctx context.Context, c *coreapi.Client) error {
h, rerr := resolveDefaultClusterHost(ctx, c)
if rerr != nil {
return rerr
}
clusterHost = h
fmt.Fprintf(cmd.ErrOrStderr(), "Using default cluster %s\n", clusterHost)
return nil
}); err != nil {
return err
}
// The non-interactive one-shot keeps a fixed default cluster
// (defaultClusterHost) when [cluster-host] is omitted — catalog-based
// cluster guessing is intentionally limited to the interactive
// wizard (the no-args path above), so scripts get stable behavior.
clusterHost := clusterArg(args)
if err := validateClusterHost(clusterHost); err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("invalid [cluster-host]: %w", err)
}
return runCoreForCluster(cmd, clusterHost, func(ctx context.Context, c *coreapi.Client) error {
errW := cmd.ErrOrStderr()
12 unmodified lines
return cmd
}
// resolveDefaultClusterHost picks the cluster a `repo mirror create
// <github-url>` targets when [cluster-host] is omitted, from the control plane's
// cluster catalog (the same GET /api/v1/clusters the wizard uses): the cluster
// flagged is_default, or the sole cluster when there is exactly one. It errors
// when the catalog is empty or has no clear default so the user knows to pass
// [cluster-host] explicitly, rather than silently guessing.
func resolveDefaultClusterHost(ctx context.Context, c *coreapi.Client) (string, error) {
regions, err := availableRegions(ctx, c)
if err != nil {
return "", err
}
jurisdiction, err := callerJurisdiction(ctx, c)
if err != nil {
return "", err
}
return pickDefaultRegionHost(regions, jurisdiction)
}
// callerJurisdiction returns the active principal's home jurisdiction slug from
// GET /me (e.g. "eu"). May return "" if the server doesn't report one.
func callerJurisdiction(ctx context.Context, c *coreapi.Client) (string, error) {
me, err := c.GetMe(ctx)
if err != nil {
return "", renderCoreError(err)
}
j, _ := me.Jurisdiction.Get()
return j, nil
}
// pickDefaultRegionHost chooses the default cluster host for the caller's
// jurisdiction. is_default is per-jurisdiction (each jurisdiction has one), so a
// known jurisdiction selects its default directly. With no jurisdiction it falls
// back to a lone cluster or a lone default; anything ambiguous errors so the
// caller can tell the user to pass [cluster-host]. Pure, so the selection is
// unit-testable without a live core.
func pickDefaultRegionHost(regions []regionChoice, jurisdiction string) (string, error) {
if len(regions) == 0 {
return "", errors.New("no clusters available to mirror into; pass [cluster-host] explicitly")
}
if jurisdiction != "" {
for _, r := range regions {
if r.isDefault && r.jurisdiction == jurisdiction {
return r.host, nil
}
}
return "", fmt.Errorf("no default cluster for your jurisdiction (%s); pass [cluster-host] explicitly", jurisdiction)
}
if len(regions) == 1 {
return regions[0].host, nil
}
var defaults []regionChoice
for _, r := range regions {
if r.isDefault {
defaults = append(defaults, r)
}
}
if len(defaults) == 1 {
return defaults[0].host, nil
}
return "", errors.New("could not determine your jurisdiction's default cluster; pass [cluster-host] explicitly")
}
// mirrorCreateOutcome bundles the create response with the clone status
// observed while waiting. polled is false for --no-wait and for empty upstreams,
// where there is nothing to await; in those cases status is unset.