Default one-shot create cluster to the catalog default · Entire
Default one-shot create cluster to the catalog default
289a796→main·
toothbrush·3w ago·2 files·+94 added/-6 removed
`entire repo mirror create github.com/octocat/hello-world` (no cluster-host) now resolves the target from GET /api/v1/clusters — the is_default cluster (or the sole one) — instead of the hardcoded constant, matching the wizard. Prints the chosen cluster; errors asking for an explicit [cluster-host] when the catalog is empty or has no clear default.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
cfcf2050076dView transcript
[?
Interactive Repo Mirror Onboarding WizardClaude Code·2 steps](/content/gh/entireio/cli/session/b1f77cad-1b19-4ba8-bc01-a412c9c54e2a#timeline-cfcf2050076d/index.html)
Changes
2
cmd/entire/cli
Mrepo_mirror.go+59/-6
Mrepo_mirror_test.go+35
144 unmodified lines
145
146
147
148
149
148
149
150
151
152
7 unmodified lines
160
161
162
163
164
165
166
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
12 unmodified lines
201
202
203
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
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 " +
defaultClusterHost + " when omitted.",
"(upstream, cluster). The cluster-host defaults to your catalog's " +
"default cluster when omitted.",
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 eu-west-1.entire.io",
7 unmodified lines
cmd.SilenceUsage = true
return fmt.Errorf("invalid <github-url>: %w", err)
}
clusterHost := clusterArg(args)
if err := validateClusterHost(clusterHost); err != nil {
cmd.SilenceUsage = true
return fmt.Errorf("invalid [cluster-host]: %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
}
}
return runCoreForCluster(cmd, clusterHost, func(ctx context.Context, c *coreapi.Client) error {
errorW := 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
}
return pickDefaultRegionHost(regions)
}
// pickDefaultRegionHost chooses the default cluster host from the catalog: the
// is-default cluster, or the sole cluster when there's exactly one. Empty or
// ambiguous catalogs error 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) (string, error) {
for _, r := range regions {
if r.isDefault {
return r.host, nil
}
}
switch len(regions) {
case 0:
return "", errors.New("no clusters available to mirror into; pass [cluster-host] explicitly")
case 1:
return regions[0].host, nil
default:
return "", errors.New("no default cluster configured; 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.
Mcmd/entire/cli/repo_mirror.go+59/-6
451 unmodified lines
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
451 unmodified lines
}
}
func TestPickDefaultRegionHost(t *testing.T) {
t.Parallel()
t.Run("prefers the is-default cluster", func(t *testing.T) {
t.Parallel()
host, err := pickDefaultRegionHost([]regionChoice{
{host: "eu-west-1.entire.io"},
{host: "aws-us-east-2.entire.io", isDefault: true},
})
require.NoError(t, err)
require.Equal(t, "aws-us-east-2.entire.io", host)
})
t.Run("sole cluster is the default", func(t *testing.T) {
t.Parallel()
host, err := pickDefaultRegionHost([]regionChoice{{host: "only.entire.io"}})
require.NoError(t, err)
require.Equal(t, "only.entire.io", host)
})
t.Run("empty catalog errors", func(t *testing.T) {
t.Parallel()
_, err := pickDefaultRegionHost(nil)
require.Error(t, err)
})
t.Run("ambiguous (multiple, none default) errors", func(t *testing.T) {
t.Parallel()
_, err := pickDefaultRegionHost([]regionChoice{
{host: "a.entire.io"}, {host: "b.entire.io"},
})
require.Error(t, err)
})
}
func TestClusterArg(t *testing.T) {
t.Parallel()
if got := clusterArg([]string{"github.com/o/r", "eu-west-1.entire.io"}); got != "eu-west-1.entire.io" {