Repository navigation
fix(rest): unbreak CSI clone-from-volume and make snapshot restore idempotent #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Andrei Kvapil (kvaps)
wants to merge
10
commits into
main
Choose a base branch
from
fix/csi-clone-and-restore-idempotency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+23,891
−849
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b6c08d2
refactor(rest): split the store-error and body-decode answers from th…
kvaps 0908efd
fix(rest): read delete_namespaces the way LINSTOR does, on the props …
kvaps 2b549f3
fix(rest): honour delete_namespaces on the key-value store door
kvaps d58e58c
fix(rest): take golinstor's whole body on the volume-group doors
kvaps 06594ec
fix(clone,restore): accept linstor-csi's calls and resume their retries
kvaps 5b4b0a9
fix(rest,cli): keep the marks blockstor reads off a definition out of…
kvaps 24bd04b
test(e2e): pin the clone and restore retry semantics on a stand
kvaps 8503172
fix(satellite): move the snapshot stream off node-exporter's port
kvaps 23a08a5
fix(satellite): open no metrics listener
kvaps 9e6de7d
fix(apiserver): read the passphrase Secret without a cluster-wide inf…
kvaps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cli_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| apiv1 "github.com/cozystack/blockstor/pkg/api/v1" | ||
| "github.com/cozystack/blockstor/pkg/store" | ||
| ) | ||
|
|
||
| // A group's props are copied onto every definition spawned from it, so the CLI | ||
| // door refuses a prop blockstor reads back off a definition the way `rg c` and | ||
| // `rg modify` refuse it on the REST door, and still sets an ordinary one and | ||
| // still deletes a server-owned one a group already carries. | ||
| func TestResourceGroupSetPropertyRefusesServerOwnedProps(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| app, _, errBuf := newApp(t, func(ctx context.Context, backend store.Store) { | ||
| _ = backend.ResourceGroups().Create(ctx, &apiv1.ResourceGroup{ | ||
| Name: "rg-owned", | ||
| Props: map[string]string{store.RestoreAdoptedProp: "left-from-before"}, | ||
| }) | ||
| }) | ||
|
|
||
| if got := app.Run(t.Context(), []string{"rg", "set-property", "rg-owned", "Aux/team", "storage"}); got != 0 { | ||
| t.Fatalf("setting an ordinary prop exit = %d (stderr: %s)", got, errBuf.String()) | ||
| } | ||
|
|
||
| if got := app.Run(t.Context(), []string{"rg", "set-property", "rg-owned", store.RestoreFromSnapshotProp, "src:snap"}); got == 0 { | ||
| t.Fatal("a group took a restore marker every spawned definition would inherit") | ||
| } | ||
|
|
||
| if !strings.Contains(errBuf.String(), "blockstor sets this property itself") { | ||
| t.Errorf("stderr %q does not say why", errBuf.String()) | ||
| } | ||
|
|
||
| if got := app.Run(t.Context(), []string{"rg", "delete-property", "rg-owned", store.RestoreAdoptedProp}); got != 0 { | ||
| t.Fatalf("deleting a server-owned prop from a group exit = %d (stderr: %s)", got, errBuf.String()) | ||
| } | ||
|
|
||
| rg, err := appStore(t, app).ResourceGroups().Get(t.Context(), "rg-owned") | ||
| if err != nil { | ||
| t.Fatalf("read back: %v", err) | ||
| } | ||
|
|
||
| if rg.Props["Aux/team"] != "storage" { | ||
| t.Errorf("the ordinary prop was not set: %v", rg.Props) | ||
| } | ||
|
|
||
| if _, ok := rg.Props[store.RestoreFromSnapshotProp]; ok { | ||
| t.Errorf("the refused marker reached the group: %v", rg.Props) | ||
| } | ||
|
|
||
| if _, ok := rg.Props[store.RestoreAdoptedProp]; ok { | ||
| t.Errorf("the server-owned prop survived its delete: %v", rg.Props) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /* | ||
| Copyright 2026 Cozystack contributors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package cli | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "sync/atomic" | ||
| "testing" | ||
|
|
||
| apiv1 "github.com/cozystack/blockstor/pkg/api/v1" | ||
| "github.com/cozystack/blockstor/pkg/store" | ||
| ) | ||
|
|
||
| var errPlacementFailed = errors.New("placement failed") | ||
|
|
||
| // markFindsNothing answers the gone-th definition patch NotFound, while the | ||
| // backend holds a definition under the name: the one the rollback meant went, | ||
| // and another writer put a new one there. | ||
| type markFindsNothing struct { | ||
| store.ResourceDefinitionStore | ||
|
|
||
| patches *atomic.Int32 | ||
| gone int32 | ||
| } | ||
|
|
||
| func (r markFindsNothing) PatchResourceDefinitionSpec( | ||
| ctx context.Context, name string, mutate func(*apiv1.ResourceDefinition) error, | ||
| ) error { | ||
| if r.patches.Add(1) == r.gone { | ||
| return store.ErrNotFound | ||
| } | ||
|
|
||
| return r.ResourceDefinitionStore.PatchResourceDefinitionSpec(ctx, name, mutate) //nolint:wrapcheck // test double | ||
| } | ||
|
|
||
| type markFindsNothingStore struct { | ||
| store.Store | ||
|
|
||
| patches *atomic.Int32 | ||
| gone int32 | ||
| } | ||
|
|
||
| func (s markFindsNothingStore) ResourceDefinitions() store.ResourceDefinitionStore { | ||
| return markFindsNothing{ResourceDefinitionStore: s.Store.ResourceDefinitions(), patches: s.patches, gone: s.gone} | ||
| } | ||
|
|
||
| // A restore rollback whose definition is gone deletes nothing by name, and | ||
| // answers with the restore's own failure alone, since there was nothing left | ||
| // to roll back: whether it finds the definition gone on the mark that starts | ||
| // the rollback or on the one that takes it apart. | ||
| func TestRestoreRollbackWhoseDefinitionGoesBeforeItsDeleteDeletesNothing(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| for _, tc := range []struct { | ||
| name string | ||
| gone int32 | ||
| }{ | ||
| {name: "gone when the rollback starts", gone: 1}, | ||
| {name: "gone before the first delete", gone: 2}, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| backend := store.NewInMemory() | ||
| ctx := t.Context() | ||
|
|
||
| if err := backend.ResourceDefinitions().Create(ctx, &apiv1.ResourceDefinition{Name: "pvc-regone"}); err != nil { | ||
| t.Fatalf("seed: %v", err) | ||
| } | ||
|
|
||
| // The flags the rollback's advice reads, so a regression fails on | ||
| // this case's own assertions rather than a nil dereference that | ||
| // takes the sibling case down with it. | ||
| run := &runContext{ | ||
| Store: markFindsNothingStore{Store: backend, patches: new(atomic.Int32), gone: tc.gone}, | ||
| Flags: &flagSet{Values: map[string]string{}}, | ||
| } | ||
|
|
||
| err := rollbackRestore(ctx, run, "pvc-regone", nil, errPlacementFailed) | ||
| if err == nil || err.Error() != errPlacementFailed.Error() { | ||
| t.Errorf("rollback = %v, want the restore's own failure and nothing else", err) | ||
| } | ||
|
|
||
| if _, err := backend.ResourceDefinitions().Get(ctx, "pvc-regone"); err != nil { | ||
| t.Errorf("the definition now under the name was deleted: %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /* | ||
| Copyright 2026 Cozystack contributors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package cli | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
|
|
||
| apiv1 "github.com/cozystack/blockstor/pkg/api/v1" | ||
| "github.com/cozystack/blockstor/pkg/store" | ||
| ) | ||
|
|
||
| var errMarkPatchRefused = errors.New("patch refused") | ||
|
|
||
| // A rollback that yields to an adopter and cannot take its mark back off | ||
| // leaves a definition every re-run is refused over. The answer says so and | ||
| // names the command that clears the mark, rather than only the re-run. | ||
| func TestRestoreRollbackThatYieldsWithAStuckMarkNamesTheClear(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ctx := t.Context() | ||
| backend := store.NewInMemory() | ||
|
|
||
| if err := backend.ResourceDefinitions().Create(ctx, &apiv1.ResourceDefinition{ | ||
| Name: "pvc-yield", Props: map[string]string{store.RestoreAdoptedProp: "token"}, | ||
| }); err != nil { | ||
| t.Fatalf("seed: %v", err) | ||
| } | ||
|
|
||
| // The first patch, the in-progress mark, lands; the one that takes it | ||
| // back off fails. | ||
| run := &runContext{ | ||
| Store: patchesFailAfterStore{Store: backend, patches: new(atomic.Int32), after: 1}, | ||
| Flags: &flagSet{Values: map[string]string{ | ||
| "from-resource": "src", "from-snapshot": "snap", "to-resource": "pvc-yield", | ||
| }}, | ||
| } | ||
|
|
||
| err := rollbackRestore(ctx, run, "pvc-yield", nil, errPlacementFailed) | ||
| if !errors.Is(err, errPlacementFailed) { | ||
| t.Fatalf("rollback = %v, want the restore's own failure first", err) | ||
| } | ||
|
|
||
| if !strings.Contains(err.Error(), "delete-property pvc-yield "+store.RollbackAbandonedProp) { | ||
| t.Errorf("answer %q does not name the command that clears the stuck mark", err) | ||
| } | ||
| } | ||
|
|
||
| // patchesFailAfterStore lets the first after definition patches through and | ||
| // fails every one after them. | ||
| type patchesFailAfterStore struct { | ||
| store.Store | ||
|
|
||
| patches *atomic.Int32 | ||
| after int32 | ||
| } | ||
|
|
||
| type patchesFailAfter struct { | ||
| store.ResourceDefinitionStore | ||
|
|
||
| patches *atomic.Int32 | ||
| after int32 | ||
| } | ||
|
|
||
| func (s patchesFailAfterStore) ResourceDefinitions() store.ResourceDefinitionStore { | ||
| return patchesFailAfter{ResourceDefinitionStore: s.Store.ResourceDefinitions(), patches: s.patches, after: s.after} | ||
| } | ||
|
|
||
| func (r patchesFailAfter) PatchResourceDefinitionSpec( | ||
| ctx context.Context, name string, mutate func(*apiv1.ResourceDefinition) error, | ||
| ) error { | ||
| if r.patches.Add(1) > r.after { | ||
| return errMarkPatchRefused | ||
| } | ||
|
|
||
| return r.ResourceDefinitionStore.PatchResourceDefinitionSpec(ctx, name, mutate) //nolint:wrapcheck // test double | ||
| } | ||
|
|
||
| // A replica the plan put on a pool of its own is named with that pool: without | ||
| // it `resource create` takes the pool of the first diskful sibling. | ||
| func TestPlaceCommandsNameThePoolThePlanChose(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| planned := []apiv1.Resource{ | ||
| {Name: "pvc-x", NodeName: "node-a", Props: map[string]string{storPoolNameProp: "fast"}}, | ||
| {Name: "pvc-x", NodeName: "node-b", Props: map[string]string{storPoolNameProp: "slow"}}, | ||
| {Name: "pvc-x", NodeName: "node-c"}, | ||
| } | ||
|
|
||
| got := placeCommands("pvc-x", planned, []string{"node-b", "node-c"}) | ||
|
|
||
| want := "run `blockstor resource create node-b pvc-x --storage-pool slow`, `blockstor resource create node-c pvc-x`" | ||
| if got != want { | ||
| t.Errorf("commands = %q, want %q", got, want) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NIT] the new subtest reddens by panic rather than by its own assertion, and takes its sibling with it
It does catch the mutation it was added for, which is what I asked for. But under that mutation it fails with a nil-pointer dereference inside
restoreAgainrather than through either of its own assertions, so the oracle is incidental, and because the panic kills the test binary it aborts the sibling case in the same table. A real regression here reports one case instead of two and hides whether the other still holds. A guard on the client before the call, or asserting the error, keeps both cases reporting.