-
Notifications
You must be signed in to change notification settings - Fork 6
Add passthrough handlers and mcl setup to placement shim #692
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8b9272e
Scaffold cortex placement api shim
PhilippMatthes 1f7b644
Add monitoring labels and scaffold manager (w/o leader election)
PhilippMatthes 03fc007
Remove alerts
PhilippMatthes 154338f
PR feedback
PhilippMatthes 2305af3
PR feedback
PhilippMatthes 6252f5c
3 replicas by default
PhilippMatthes 33d181f
Scaffold empty placement api handlers
PhilippMatthes 7ba4f54
Add path parameter validation
PhilippMatthes 41c28b7
Add hypervisor informer cache
PhilippMatthes 45778ba
Connect shim to placement on startup
PhilippMatthes e5cdc1d
Implement passthrough for all http handlers
PhilippMatthes 5822daf
Unit tests and linting
PhilippMatthes af9841c
Fix SSRF
PhilippMatthes 271a910
Add multicluster client setup
PhilippMatthes 2b91b6f
Remove unused IndexHypervisorByID [skip ci]
PhilippMatthes 84c98ed
PR Feedback
PhilippMatthes 5bedfb5
Add configurable api-bind-address flag to shim
PhilippMatthes 0f9f112
Commit merge
PhilippMatthes ed6b4a0
Remove unnecessary healthcheck and restore original healthcheck
PhilippMatthes 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
Some comments aren't visible on the classic Files Changed page.
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
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,42 @@ | ||
| // Copyright SAP SE | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package placement | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| ) | ||
|
|
||
| // HandleListAllocationCandidates handles GET /allocation_candidates requests. | ||
| // | ||
| // Returns a collection of allocation requests and resource provider summaries | ||
| // that can satisfy a given set of resource and trait requirements. This is the | ||
| // primary endpoint used by Nova's scheduler to find suitable hosts for | ||
| // instance placement. | ||
| // | ||
| // The resources query parameter specifies required capacity as a comma- | ||
| // separated list (e.g. VCPU:4,MEMORY_MB:2048,DISK_GB:64). The required | ||
| // parameter filters by traits, supporting forbidden traits via ! prefix | ||
| // (since 1.22) and the in: syntax for any-of semantics (since 1.39). | ||
| // The member_of parameter filters by aggregate membership with support for | ||
| // forbidden aggregates via ! prefix (since 1.32). | ||
| // | ||
| // Since microversion 1.25, granular request groups are supported via numbered | ||
| // suffixes (resourcesN, requiredN, member_ofN) to express requirements that | ||
| // may be satisfied by different providers. The group_policy parameter (1.26+) | ||
| // controls whether groups must each be satisfied by a single provider or may | ||
| // span multiple. The in_tree parameter (1.31+) constrains results to a | ||
| // specific provider tree. | ||
| // | ||
| // Each returned allocation request is directly usable as the body for | ||
| // PUT /allocations/{consumer_uuid}. The provider_summaries section includes | ||
| // inventory capacity and usage for informed decision-making. Available since | ||
| // microversion 1.10. | ||
| func (s *Shim) HandleListAllocationCandidates(w http.ResponseWriter, r *http.Request) { | ||
| ctx := r.Context() | ||
| log := logf.FromContext(ctx) | ||
| log.Info("placement request", "method", r.Method, "path", r.URL.Path) | ||
| s.forward(w, r) | ||
| } |
21 changes: 21 additions & 0 deletions
21
internal/shim/placement/handle_allocation_candidates_test.go
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,21 @@ | ||
| // Copyright SAP SE | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package placement | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestHandleListAllocationCandidates(t *testing.T) { | ||
| var gotPath string | ||
| s := newTestShim(t, http.StatusOK, `{"allocation_requests":[]}`, &gotPath) | ||
| w := serveHandler(t, "GET", "/allocation_candidates", s.HandleListAllocationCandidates, "/allocation_candidates") | ||
| if w.Code != http.StatusOK { | ||
| t.Fatalf("status = %d, want %d", w.Code, http.StatusOK) | ||
| } | ||
| if gotPath != "/allocation_candidates" { | ||
| t.Fatalf("upstream path = %q, want /allocation_candidates", gotPath) | ||
| } | ||
| } |
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,95 @@ | ||
| // Copyright SAP SE | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package placement | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
| ) | ||
|
|
||
| // HandleManageAllocations handles POST /allocations requests. | ||
| // | ||
| // Atomically creates, updates, or deletes allocations for multiple consumers | ||
| // in a single request. This is the primary mechanism for operations that must | ||
| // modify allocations across several consumers atomically, such as live | ||
| // migrations and move operations where resources are transferred from one | ||
| // consumer to another. Available since microversion 1.13. | ||
| // | ||
| // The request body is keyed by consumer UUID, each containing an allocations | ||
| // dictionary (keyed by resource provider UUID), along with project_id and | ||
| // user_id. Since microversion 1.28, consumer_generation enables consumer- | ||
| // level concurrency control. Since microversion 1.38, a consumer_type field | ||
| // (e.g. INSTANCE, MIGRATION) is supported. Returns 204 No Content on | ||
| // success, or 409 Conflict if inventory is insufficient or a concurrent | ||
| // update is detected (error code: placement.concurrent_update). | ||
| func (s *Shim) HandleManageAllocations(w http.ResponseWriter, r *http.Request) { | ||
| ctx := r.Context() | ||
| log := logf.FromContext(ctx) | ||
| log.Info("placement request", "method", r.Method, "path", r.URL.Path) | ||
| s.forward(w, r) | ||
| } | ||
|
|
||
| // HandleListAllocations handles GET /allocations/{consumer_uuid} requests. | ||
| // | ||
| // Returns all allocation records for the consumer identified by | ||
| // {consumer_uuid}, across all resource providers. The response contains an | ||
| // allocations dictionary keyed by resource provider UUID. If the consumer has | ||
| // no allocations, an empty dictionary is returned. | ||
| // | ||
| // The response has grown across microversions: project_id and user_id were | ||
| // added at 1.12, consumer_generation at 1.28, and consumer_type at 1.38. | ||
| // The consumer_generation and consumer_type fields are absent when the | ||
| // consumer has no allocations. | ||
| func (s *Shim) HandleListAllocations(w http.ResponseWriter, r *http.Request) { | ||
| consumerUUID, ok := requiredUUIDPathParam(w, r, "consumer_uuid") | ||
| if !ok { | ||
| return | ||
| } | ||
| ctx := r.Context() | ||
| log := logf.FromContext(ctx) | ||
| log.Info("placement request", "method", r.Method, "path", r.URL.Path, | ||
| "consumer_uuid", consumerUUID) | ||
| s.forward(w, r) | ||
| } | ||
|
|
||
| // HandleUpdateAllocations handles PUT /allocations/{consumer_uuid} requests. | ||
| // | ||
| // Creates or replaces all allocation records for a single consumer. If | ||
| // allocations already exist for this consumer, they are entirely replaced | ||
| // by the new set. The request format changed at microversion 1.12 from an | ||
| // array-based layout to an object keyed by resource provider UUID. | ||
| // Microversion 1.28 added consumer_generation for concurrency control, | ||
| // and 1.38 introduced consumer_type. | ||
| // | ||
| // Returns 204 No Content on success. Returns 409 Conflict if there is | ||
| // insufficient inventory or if a concurrent update was detected. | ||
| func (s *Shim) HandleUpdateAllocations(w http.ResponseWriter, r *http.Request) { | ||
| consumerUUID, ok := requiredUUIDPathParam(w, r, "consumer_uuid") | ||
| if !ok { | ||
| return | ||
| } | ||
| ctx := r.Context() | ||
| log := logf.FromContext(ctx) | ||
| log.Info("placement request", "method", r.Method, "path", r.URL.Path, | ||
| "consumer_uuid", consumerUUID) | ||
| s.forward(w, r) | ||
| } | ||
|
|
||
| // HandleDeleteAllocations handles DELETE /allocations/{consumer_uuid} requests. | ||
| // | ||
| // Removes all allocation records for the consumer across all resource | ||
| // providers. Returns 204 No Content on success, or 404 Not Found if the | ||
| // consumer has no existing allocations. | ||
| func (s *Shim) HandleDeleteAllocations(w http.ResponseWriter, r *http.Request) { | ||
| consumerUUID, ok := requiredUUIDPathParam(w, r, "consumer_uuid") | ||
| if !ok { | ||
| return | ||
| } | ||
| ctx := r.Context() | ||
| log := logf.FromContext(ctx) | ||
| log.Info("placement request", "method", r.Method, "path", r.URL.Path, | ||
| "consumer_uuid", consumerUUID) | ||
| s.forward(w, r) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.