Skip to content

Commit 36082b2

Browse files
committed
chore(tests): merge upstream main with LINSTOR bootstrap fix
Keep the fork test environment aligned with the platform images so LINSTOR database migration and controller versions agree during setup. Signed-off-by: Ahmed Kamal <[email protected]> Assisted-by: LLM
2 parents 865874e + f123009 commit 36082b2

200 files changed

Lines changed: 8146 additions & 4718 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ rd-presets-check:
139139
migrations-target-check:
140140
hack/check-migrations-target.sh
141141

142-
# Scoped go test over the cozystack-api surface that this repo owns. Kept
143-
# narrow intentionally - running `go test ./...` pulls in generated code
144-
# round-trip suites whose behavior depends on tool versions outside this
145-
# repo's control (kubebuilder, openapi-gen, etc.) and is better exercised
146-
# from their generator workflows.
142+
# Go tests of the cozystack-api surface and of the standalone packages and
143+
# commands listed here, whose tests need no cluster. Kept narrow
144+
# intentionally - running `go test ./...` pulls in generated code round-trip
145+
# suites whose behavior depends on tool versions outside this repo's control
146+
# (kubebuilder, openapi-gen, etc.) and is better exercised from their
147+
# generator workflows.
147148
go-unit-tests:
148-
go test ./pkg/registry/... ./pkg/config/... ./pkg/cmd/server/...
149+
go test ./pkg/registry/... ./pkg/config/... ./pkg/cmd/server/... ./pkg/lineage/... ./pkg/ovnstatus/... ./pkg/reservation/... ./cmd/cozypkg/... ./cmd/check-readiness/...
149150

150151
# The nested Go modules (image sources and the published API types) are
151152
# outside ./... of the root module, so no other target reaches their tests.
@@ -158,9 +159,7 @@ go-module-tests:
158159
done
159160

160161
# Go tests for the controllers and supporting packages under ./internal.
161-
# Excludes ./pkg/... and ./cmd/... — those are run separately by
162-
# go-unit-tests above (pkg subset) and skipped (cmd) until their tests
163-
# stabilise. CI schedules this target in the same four-slot make invocation as
162+
# CI schedules this target in the same four-slot make invocation as
164163
# unit-tests; locally invoke it directly or chain the two targets.
165164
test-controllers:
166165
go test ./internal/... -count=1
@@ -195,7 +194,8 @@ test-controllers-envtest: $(SETUP_ENVTEST)
195194
test-check-readiness:
196195
go test ./test/check-readiness/ -count=1
197196

198-
# ./cmd/... is excluded from go-unit-tests, so the batch tool needs its own target.
197+
# The batch tool's suite drives real git repositories for minutes, so it is
198+
# kept out of go-unit-tests in a target of its own.
199199
test-backport-batch:
200200
go test ./cmd/backport-batch/... -count=1
201201

‎api/apps/v1alpha1/redis/types.go‎

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/apps/v1alpha1/redis/zz_generated.deepcopy.go‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎cmd/backport-batch/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Requires `git` and an authenticated `gh` on PATH, and a remote called `origin`.
2727

2828
Build the binary wherever an exit code matters: `go run` turns any non-zero exit into its own `1`, so under it a check that could not be completed looks the same as one that found something missing.
2929

30+
Output is written before a push or a publish. Once a write to stdout or stderr fails, a closed pipe included, the run changes nothing more: no push, no GitHub write, no local branch move, and no new pick; a pick already in flight still finishes its rollback. It exits 2 where it would have exited 0, saying on stderr, while it still can, that the output was lost. A confirmation lost after a push or a publish fails the run the same way.
31+
3032
### run
3133

3234
Switches the current working tree to `backport-batch/<line>-<yyyymmdd>`, created at `origin/<line>`, and picks onto it one original at a time, in the order they merged into `main`, as one unit each on the branch's first-parent line. A pull request merged into `main` with a merge commit `M` goes on as its own commits, `git rev-list --reverse --topo-order --no-merges M^1..M^2`, each picked with `git cherry-pick -x --signoff`, so each keeps its author, message and sign-offs and gains the `(cherry picked from commit …)` line; the merges that brought `main` into its branch are left out, since `main` already has what they brought. A merge commit then joins the picks to the batch: its first parent is the batch before the original, its second the last pick, and its message is `M`'s with a paragraph of its own, `Backported-from: M`. A pull request squash-merged into `main` goes on as one pick. When any commit of an original conflicts, the pick is aborted, the branch goes back to where it was before that original, and the original is recorded with the commit that failed and its files; the run goes on with the next one. A commit the branch already carries is skipped as empty, and an original none of whose commits changes anything is reported as carried. The tree has to be clean. A local branch of that name is reset to where the run starts; when that drops commits only it has, the run first prints its tip and the `git branch` command that restores them, and so does `--defer`. Signing follows your git configuration; hooks are off for the picks and the merge, so each commit carries its message as git writes it.

‎cmd/backport-batch/apisurface.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func apiSnapshot(commit string) (apigate.Snapshot, error) {
9999
if err != nil {
100100
return nil, err
101101
}
102-
defer os.RemoveAll(dir)
102+
defer func() { _ = os.RemoveAll(dir) }()
103103
for name, blob := range paths {
104104
file := filepath.Join(dir, filepath.FromSlash(name))
105105
if err := os.MkdirAll(filepath.Dir(file), 0o700); err != nil {

‎cmd/backport-batch/assemble.go‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (a *app) run(args []string) int {
153153
}
154154
// The scheduled job has half an hour for every line; this says where it
155155
// goes.
156-
fmt.Fprintf(a.stderr, "prepared %s in %s, %s of it judging partial units and what originals build on\n", l.branch(), time.Since(started).Round(time.Millisecond), b.detecting.Round(time.Millisecond))
156+
_, _ = fmt.Fprintf(a.stderr, "prepared %s in %s, %s of it judging partial units and what originals build on\n", l.branch(), time.Since(started).Round(time.Millisecond), b.detecting.Round(time.Millisecond))
157157
if drops != nil {
158158
return a.redrop(b, drops, reason, *undropArg != "", *push)
159159
}
@@ -273,7 +273,7 @@ func (a *app) run(args []string) int {
273273
continue
274274
}
275275
}
276-
p, err := pickOriginal(v, func(base, head string) ([]string, error) {
276+
p, err := a.pickUnit(v, func(base, head string) ([]string, error) {
277277
omitted, diag, err := b.omittedEffects(v, base, head)
278278
v.addDiag(diag...)
279279
return omitted, err
@@ -449,20 +449,20 @@ func (a *app) finish(b *batch, r *report, branch string, date time.Time, push, r
449449
}
450450
body, left := r.body(template)
451451
p.body = body
452-
fmt.Fprint(a.stdout, body)
452+
_, _ = fmt.Fprint(a.stdout, body)
453453
skipped := 0
454454
for _, items := range r.skipped {
455455
skipped += len(items)
456456
}
457457
for _, rule := range left {
458458
for _, v := range r.skipped[rule] {
459-
fmt.Fprintf(a.stderr, "skipped by %s: %s %s (%s)\n", ruleName(rule), v.o.url(), terminalSafe(v.o.title), terminalSafe(v.reason))
459+
_, _ = fmt.Fprintf(a.stderr, "skipped by %s: %s %s (%s)\n", ruleName(rule), v.o.url(), terminalSafe(v.o.title), terminalSafe(v.reason))
460460
}
461461
}
462462
for _, p := range r.waiting {
463-
fmt.Fprintf(a.stderr, "waiting for a maintainer: %s %s changes %s\n", p.v.o.url(), terminalSafe(p.v.o.title), terminalSafe(strings.Join(p.files, ", ")))
463+
_, _ = fmt.Fprintf(a.stderr, "waiting for a maintainer: %s %s changes %s\n", p.v.o.url(), terminalSafe(p.v.o.title), terminalSafe(strings.Join(p.files, ", ")))
464464
}
465-
fmt.Fprintf(a.stderr, "%s at %.12s: %d on the branch, %d deferred, %d waiting for a maintainer, %d skipped\ntitle: %s\nreport: %s\n",
465+
_, _ = fmt.Fprintf(a.stderr, "%s at %.12s: %d on the branch, %d deferred, %d waiting for a maintainer, %d skipped\ntitle: %s\nreport: %s\n",
466466
branch, head, len(r.onBranch), len(r.deferred)+len(r.held), len(r.waiting), skipped, p.title, doc.ID)
467467
if !push {
468468
return 0
@@ -471,8 +471,8 @@ func (a *app) finish(b *batch, r *report, branch string, date time.Time, push, r
471471
// Picking nothing is not a failure of the run; check still reports
472472
// whatever the line lacks. Merged and closed batches are never
473473
// written, so there is nowhere to keep what the run found.
474-
fmt.Fprintf(a.stderr, "%s carries nothing beyond %s; nothing to push\n", branch, b.line.branch())
475-
fmt.Fprintf(a.stderr, "no batch pull request is open on %s; this run's classification is not retained\n", b.line.branch())
474+
_, _ = fmt.Fprintf(a.stderr, "%s carries nothing beyond %s; nothing to push\n", branch, b.line.branch())
475+
_, _ = fmt.Fprintf(a.stderr, "no batch pull request is open on %s; this run's classification is not retained\n", b.line.branch())
476476
return 0
477477
}
478478
if err := a.publish(b, p, rebuilt); err != nil {
@@ -529,6 +529,9 @@ func cleanTree() error {
529529
// the move drops commits of and how to get them back: a clean tree says
530530
// nothing about commits only a local branch has.
531531
func (a *app) warnReset(branch, start string) error {
532+
if err := a.mayAct(); err != nil {
533+
return err
534+
}
532535
old, err := lookup("refs/heads/" + branch)
533536
if err != nil || old == "" || old == start {
534537
return err
@@ -537,7 +540,11 @@ func (a *app) warnReset(branch, start string) error {
537540
if err != nil || kept {
538541
return err
539542
}
540-
fmt.Fprintf(a.stderr, "resetting the local %s from %s, dropping commits %.12s does not carry; git branch %s-%.12s %s restores them\n", branch, old, start, branch, old, old)
543+
// The hint is the only way back to the dropped commits, so the reset does
544+
// not run when it could not be written.
545+
if _, err := fmt.Fprintf(a.stderr, "resetting the local %s from %s, dropping commits %.12s does not carry; git branch %s-%.12s %s restores them\n", branch, old, start, branch, old, old); err != nil {
546+
return fmt.Errorf("not resetting the local %s: %w", branch, err)
547+
}
541548
return nil
542549
}
543550

@@ -719,6 +726,9 @@ func (a *app) publish(b *batch, p publication, rebuilt bool) error {
719726
}
720727
}
721728
if pushed != p.head {
729+
if err := a.mayAct(); err != nil {
730+
return err
731+
}
722732
if _, err := git(pushArgs(p.branch, p.head, lease)...); err != nil {
723733
return err
724734
}
@@ -727,13 +737,13 @@ func (a *app) publish(b *batch, p publication, rebuilt bool) error {
727737
if err != nil {
728738
return err
729739
}
730-
defer os.Remove(name)
740+
defer func() { _ = os.Remove(name) }()
731741
if b.pr == nil {
732742
n, url, err := a.gh.createPull(b.line.branch(), p.branch, p.title, name)
733743
if err != nil {
734744
return err
735745
}
736-
fmt.Fprintf(a.stderr, "opened draft %s\n", url)
746+
_, _ = fmt.Fprintf(a.stderr, "opened draft %s\n", url)
737747
if err := a.postReport(n, p.report); err != nil {
738748
return fmt.Errorf("posting report %.12s on #%d: %w; the body keeps it, and the next run --push posts it", p.report.doc.ID, n, err)
739749
}
@@ -745,7 +755,7 @@ func (a *app) publish(b *batch, p publication, rebuilt bool) error {
745755
if err := a.gh.editPull(b.pr.Number, p.title, name); err != nil {
746756
return err
747757
}
748-
fmt.Fprintf(a.stderr, "updated %s\n", pullURL(b.pr))
758+
_, _ = fmt.Fprintf(a.stderr, "updated %s\n", pullURL(b.pr))
749759
return nil
750760
}
751761

@@ -828,7 +838,7 @@ func (a *app) closeBatch(b *batch, p publication) error {
828838
if err != nil {
829839
return err
830840
}
831-
defer os.Remove(name)
841+
defer func() { _ = os.Remove(name) }()
832842
if err := a.stillOpen(c.PR); err != nil {
833843
return err
834844
}
@@ -861,7 +871,7 @@ func (a *app) finishClose(l line, url string, c closing) error {
861871
if err := a.deleteBranch(l, c); err != nil {
862872
return err
863873
}
864-
fmt.Fprintf(a.stderr, "closed %s: without what is deferred it carries nothing beyond %s; the next batch tries them again\n", url, l.branch())
874+
_, _ = fmt.Fprintf(a.stderr, "closed %s: without what is deferred it carries nothing beyond %s; the next batch tries them again\n", url, l.branch())
865875
return nil
866876
}
867877

@@ -878,6 +888,9 @@ func (a *app) deleteBranch(l line, c closing) error {
878888
case h != c.Head:
879889
return movedBranch(c, h)
880890
}
891+
if err := a.mayAct(); err != nil {
892+
return err
893+
}
881894
if _, err := git(deleteArgs(c.Branch, c.Head)...); err != nil {
882895
return fmt.Errorf("deleting %s, left by the close of #%d: %w; backport-batch run --line %s --push deletes it", c.Branch, c.PR, err, l.branch())
883896
}
@@ -933,7 +946,7 @@ func (a *app) resumeClose(b *batch, push, changing bool) (bool, int) {
933946
if err := a.deleteBranch(b.line, c); err != nil {
934947
return false, a.fail(err)
935948
}
936-
fmt.Fprintf(a.stderr, "deleted %s, which the close of #%d left\n", c.Branch, c.PR)
949+
_, _ = fmt.Fprintf(a.stderr, "deleted %s, which the close of #%d left\n", c.Branch, c.PR)
937950
return false, a.finished(c, changing)
938951
}
939952

‎cmd/backport-batch/check.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ func (a *app) check(args []string) int {
7373
case d.kind == outcomeWarning:
7474
a.warn("%s", d.text)
7575
case d.kind == outcomeNote:
76-
fmt.Fprintf(a.stderr, "note: %s\n", d.text)
76+
_, _ = fmt.Fprintf(a.stderr, "note: %s\n", d.text)
7777
}
7878
}
7979
if len(missing)+len(failing) == 0 {
8080
if *cut {
81-
fmt.Fprintf(a.stdout, "%s: no change the policy takes is missing before the cut\n", l.branch())
81+
_, _ = fmt.Fprintf(a.stdout, "%s: no change the policy takes is missing before the cut\n", l.branch())
8282
} else {
83-
fmt.Fprintf(a.stdout, "%s: every change the policy takes is on the line or on the batch\n", l.branch())
83+
_, _ = fmt.Fprintf(a.stdout, "%s: every change the policy takes is on the line or on the batch\n", l.branch())
8484
}
8585
return 0
8686
}
@@ -89,13 +89,13 @@ func (a *app) check(args []string) int {
8989
where = "nor on batch pull request #" + strconv.Itoa(b.pr.Number)
9090
}
9191
if len(missing) > 0 {
92-
fmt.Fprintf(a.stdout, "%s: %d changes the policy takes are not on the line, %s:\n", l.branch(), len(missing), where)
92+
_, _ = fmt.Fprintf(a.stdout, "%s: %d changes the policy takes are not on the line, %s:\n", l.branch(), len(missing), where)
9393
for _, text := range missing {
94-
fmt.Fprintf(a.stdout, " %s\n", text)
94+
_, _ = fmt.Fprintf(a.stdout, " %s\n", text)
9595
}
9696
}
9797
for _, text := range failing {
98-
fmt.Fprintf(a.stdout, "%s: %s\n", l.branch(), text)
98+
_, _ = fmt.Fprintf(a.stdout, "%s: %s\n", l.branch(), text)
9999
}
100100
return 1
101101
}
@@ -326,10 +326,10 @@ func (a *app) fold(args []string) int {
326326
return a.fail(err)
327327
}
328328
if why != "" {
329-
fmt.Fprintf(a.stdout, "refused: %s\n", why)
329+
_, _ = fmt.Fprintf(a.stdout, "refused: %s\n", why)
330330
return 1
331331
}
332-
fmt.Fprintln(a.stdout, "ok")
332+
_, _ = fmt.Fprintln(a.stdout, "ok")
333333
return 0
334334
}
335335

‎cmd/backport-batch/defer.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (a *app) reassemble(b *batch, out, hold map[int]string, drops []droppedEntr
102102
return a.fail(err)
103103
}
104104
for _, u := range replay {
105-
failed, files, err := replayUnit(u)
105+
failed, files, err := a.replayNext(u)
106106
switch {
107107
case err != nil:
108108
return a.fail(err)

‎cmd/backport-batch/effects.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (b *batch) alreadyApplied(pre, cur, post string) (applied, unsupported bool
367367
if err != nil {
368368
return false, false, err
369369
}
370-
defer os.RemoveAll(dir)
370+
defer func() { _ = os.RemoveAll(dir) }()
371371
names := map[string]string{}
372372
for _, f := range []struct{ name, oid string }{{"cur", cur}, {"pre", pre}, {"post", post}} {
373373
names[f.name] = filepath.Join(dir, f.name)

‎cmd/backport-batch/effects_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func emptyBatch(f *fixture, gh *fakeGH, body string) *foldWorld {
5353
// and every check of the batch's shape takes the old name as the same file:
5454
// verify, a hand fold, and a rebuild by --defer.
5555
func TestRenamePickThroughFoldAndVerify(t *testing.T) {
56-
f, mc5 := renameWorld(t)
56+
f, _ := renameWorld(t)
5757
f.pr(6, "fix(app): six", "", map[string]string{"app/six.txt": "6\n"})
5858
gh := &fakeGH{}
5959
head := openBatch(t, f, gh)
@@ -74,7 +74,7 @@ func TestRenamePickThroughFoldAndVerify(t *testing.T) {
7474
t.Errorf("verify after the rebuild = %d\n%s\n%s", code, out, stderr)
7575
}
7676

77-
f, mc5 = renameWorld(t)
77+
f, mc5 := renameWorld(t)
7878
w := emptyBatch(f, &fakeGH{}, "")
7979
pick := w.pick(w.head, f.git("rev-parse", mc5+"^2"), map[string]string{"app/old.txt": strings.Replace(appFile, "three", "THREE", 1)})
8080
fold := w.merge(w.head, pick, "fix(app): fix the app file (#5)\n\n"+batchTrailer+": "+mc5)

0 commit comments

Comments
 (0)