Repository navigation
fix(rest,satellite): unbreak CSI clone and restore, move the satellite stream to 3372 #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
11
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6c08d2
refactor(rest): split the store-error and body-decode answers from th…
kvaps e9c7b19
fix(rest): read delete_namespaces the way LINSTOR does, on the props …
kvaps 784f0e4
fix(rest): honour delete_namespaces on the key-value store door
kvaps 313a586
fix(rest): take golinstor's whole body on the volume-group doors
kvaps 1d5c18a
fix(clone,restore): accept linstor-csi's calls and resume their retries
kvaps e5376b2
fix(rest,cli): keep the marks blockstor reads off a definition out of…
kvaps 2feb52a
test(e2e): pin the clone and restore retry semantics on a stand
kvaps 69ef612
fix(satellite): move the snapshot stream off node-exporter's port
kvaps 1197f98
fix(satellite): open no metrics listener
kvaps 0dbd4c1
fix(apiserver): read the passphrase Secret without a cluster-wide inf…
kvaps 53929ba
fix(satellite): take down at start only the DRBD resources it owns
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "go/ast" | ||
| "go/parser" | ||
| "go/token" | ||
| "testing" | ||
| ) | ||
|
|
||
| // Every rest.Server this binary builds reads the passphrase Secret through | ||
| // the manager's API reader. Left unset, the server falls back to the cached | ||
| // client, whose first Secret read starts a cluster-wide Secret informer that | ||
| // the namespaced Role does not allow to list, and every passphrase read hangs. | ||
| func TestRESTServerReadsSecretsPastTheCache(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| fset := token.NewFileSet() | ||
|
|
||
| file, err := parser.ParseFile(fset, "main.go", nil, 0) | ||
| if err != nil { | ||
| t.Fatalf("parse main.go: %v", err) | ||
| } | ||
|
|
||
| servers := 0 | ||
|
|
||
| ast.Inspect(file, func(n ast.Node) bool { | ||
| lit, ok := n.(*ast.CompositeLit) | ||
| if !ok || !isRESTServer(lit.Type) { | ||
| return true | ||
| } | ||
|
|
||
| servers++ | ||
|
|
||
| if !setsSecretReaderToAPIReader(lit) { | ||
| t.Errorf("rest.Server at %s does not set SecretReader: mgr.GetAPIReader()", fset.Position(lit.Lbrace)) | ||
| } | ||
|
|
||
| return true | ||
| }) | ||
|
|
||
| if servers == 0 { | ||
| t.Fatal("main.go builds no rest.Server, so this guard checks nothing") | ||
| } | ||
| } | ||
|
|
||
| func isRESTServer(expr ast.Expr) bool { | ||
| sel, ok := expr.(*ast.SelectorExpr) | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| pkg, ok := sel.X.(*ast.Ident) | ||
|
|
||
| return ok && pkg.Name == "rest" && sel.Sel.Name == "Server" | ||
| } | ||
|
|
||
| func setsSecretReaderToAPIReader(lit *ast.CompositeLit) bool { | ||
| for _, elt := range lit.Elts { | ||
| kv, ok := elt.(*ast.KeyValueExpr) | ||
| if !ok { | ||
| continue | ||
| } | ||
|
|
||
| key, ok := kv.Key.(*ast.Ident) | ||
| if !ok || key.Name != "SecretReader" { | ||
| continue | ||
| } | ||
|
|
||
| call, ok := kv.Value.(*ast.CallExpr) | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| sel, ok := call.Fun.(*ast.SelectorExpr) | ||
|
|
||
| return ok && sel.Sel.Name == "GetAPIReader" | ||
| } | ||
|
|
||
| return false | ||
| } |
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,82 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "go/ast" | ||
| "go/parser" | ||
| "go/token" | ||
| "testing" | ||
| ) | ||
|
|
||
| // Every rest.Server this binary builds reads the passphrase Secret through | ||
| // the manager's API reader. Left unset, the server falls back to the cached | ||
| // client, whose first Secret read starts a cluster-wide Secret informer that | ||
| // the namespaced Role does not allow to list, and every passphrase read hangs. | ||
| func TestRESTServerReadsSecretsPastTheCache(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| fset := token.NewFileSet() | ||
|
|
||
| file, err := parser.ParseFile(fset, "main.go", nil, 0) | ||
| if err != nil { | ||
| t.Fatalf("parse main.go: %v", err) | ||
| } | ||
|
|
||
| servers := 0 | ||
|
|
||
| ast.Inspect(file, func(n ast.Node) bool { | ||
| lit, ok := n.(*ast.CompositeLit) | ||
| if !ok || !isRESTServer(lit.Type) { | ||
| return true | ||
| } | ||
|
|
||
| servers++ | ||
|
|
||
| if !setsSecretReaderToAPIReader(lit) { | ||
| t.Errorf("rest.Server at %s does not set SecretReader: mgr.GetAPIReader()", fset.Position(lit.Lbrace)) | ||
| } | ||
|
|
||
| return true | ||
| }) | ||
|
|
||
| if servers == 0 { | ||
| t.Fatal("main.go builds no rest.Server, so this guard checks nothing") | ||
| } | ||
| } | ||
|
|
||
| func isRESTServer(expr ast.Expr) bool { | ||
| sel, ok := expr.(*ast.SelectorExpr) | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| pkg, ok := sel.X.(*ast.Ident) | ||
|
|
||
| return ok && pkg.Name == "rest" && sel.Sel.Name == "Server" | ||
| } | ||
|
|
||
| func setsSecretReaderToAPIReader(lit *ast.CompositeLit) bool { | ||
| for _, elt := range lit.Elts { | ||
| kv, ok := elt.(*ast.KeyValueExpr) | ||
| if !ok { | ||
| continue | ||
| } | ||
|
|
||
| key, ok := kv.Key.(*ast.Ident) | ||
| if !ok || key.Name != "SecretReader" { | ||
| continue | ||
| } | ||
|
|
||
| call, ok := kv.Value.(*ast.CallExpr) | ||
| if !ok { | ||
| return false | ||
| } | ||
|
|
||
| sel, ok := call.Fun.(*ast.SelectorExpr) | ||
|
|
||
| return ok && sel.Sel.Name == "GetAPIReader" | ||
| } | ||
|
|
||
| return false | ||
| } |
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,73 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/cockroachdb/errors" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/client-go/rest" | ||
| ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| blockstoriov1alpha1 "github.com/cozystack/blockstor/api/v1alpha1" | ||
| k8sstore "github.com/cozystack/blockstor/pkg/store/k8s" | ||
| ) | ||
|
|
||
| // ownedKernelResources names the DRBD resources blockstor has a replica of on | ||
| // nodeName: the definitions of the Resource objects scheduled there, read from | ||
| // the API server rather than a cache, since the cache is not up yet. | ||
| func ownedKernelResources(ctx context.Context, cfg *rest.Config, nodeName string) (map[string]struct{}, error) { | ||
| scheme := runtime.NewScheme() | ||
|
|
||
| err := blockstoriov1alpha1.AddToScheme(scheme) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "register the blockstor types") | ||
| } | ||
|
|
||
| c, err := ctrlclient.New(cfg, ctrlclient.Options{Scheme: scheme}) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "build an API client") | ||
| } | ||
|
|
||
| return ownedOnNode(ctx, c, nodeName) | ||
| } | ||
|
|
||
| // ownedOnNode is ownedKernelResources over a given client. | ||
| func ownedOnNode(ctx context.Context, c ctrlclient.Client, nodeName string) (map[string]struct{}, error) { | ||
| replicas, err := k8sstore.New(c).Resources().ListByNode(ctx, nodeName) | ||
| if err != nil { | ||
| return nil, errors.Wrapf(err, "list the replicas on %q", nodeName) | ||
| } | ||
|
|
||
| owned := make(map[string]struct{}, len(replicas)) | ||
| for i := range replicas { | ||
| owned[replicas[i].Name] = struct{}{} | ||
| } | ||
|
|
||
| return owned, nil | ||
| } | ||
|
|
||
| // selectOrphans splits the kernel's resources that are not healthy into the | ||
| // ones blockstor takes down, which it has a replica of here, and foreign ones | ||
| // it leaves alone: another DRBD user's, or a resource whose Resource object is | ||
| // already gone, which is not blockstor's to judge. | ||
| func selectOrphans(names []string, healthy, owned map[string]struct{}) ([]string, []string) { | ||
| var orphans, foreign []string | ||
|
|
||
| for _, name := range names { | ||
| if _, ok := healthy[name]; ok { | ||
| continue | ||
| } | ||
|
|
||
| if _, ok := owned[name]; !ok { | ||
| foreign = append(foreign, name) | ||
|
|
||
| continue | ||
| } | ||
|
|
||
| orphans = append(orphans, name) | ||
| } | ||
|
|
||
| return orphans, foreign | ||
| } | ||
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.
This call is what
TestManagerBackedStoresComeFromNewManagerinpkg/store/k8sreports, so Unit is red on the head and the E2E lanes were skipped. The client built above has no cache, so an entry inuncachedStoreConstructionswith that reason should be enough.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.
Right, I ran only the packages I touched and missed it. Added the site to
uncachedStoreConstructions: the satellite reads its own replicas at startup with a plain client, before any manager or cache exists.go test ./...is green now apart from the 2s shutdown flake inpkg/rest.