Skip to content

Commit 537f9a0

Browse files
Use kubebuilder and start refactoring out into lib and api packages
1 parent ca9eb18 commit 537f9a0

135 files changed

Lines changed: 4781 additions & 2757 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.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Reservations Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v5
14+
path: reservations
15+
16+
- name: Get all changed files
17+
id: changed-files
18+
uses: tj-actions/changed-files@v46
19+
with:
20+
files: |
21+
**/*
22+
23+
- name: Setup Go
24+
if: steps.changed-files.outputs.files != ''
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
29+
- name: Run linter
30+
if: steps.changed-files.outputs.files != ''
31+
uses: golangci/golangci-lint-action@v8
32+
with:
33+
version: v2.1.6
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Reservations E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v5
14+
path: reservations
15+
16+
- name: Get all changed files
17+
id: changed-files
18+
uses: tj-actions/changed-files@v46
19+
with:
20+
files: |
21+
**/*
22+
23+
- name: Setup Go
24+
if: steps.changed-files.outputs.files != ''
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
29+
- name: Install the latest version of kind
30+
if: steps.changed-files.outputs.files != ''
31+
run: |
32+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
33+
chmod +x ./kind
34+
sudo mv ./kind /usr/local/bin/kind
35+
36+
- name: Verify kind installation
37+
if: steps.changed-files.outputs.files != ''
38+
run: kind version
39+
40+
- name: Running Test e2e
41+
if: steps.changed-files.outputs.files != ''
42+
run: |
43+
go mod tidy
44+
make test-e2e
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Reservations Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v5
14+
path: reservations
15+
16+
- name: Get all changed files
17+
id: changed-files
18+
uses: tj-actions/changed-files@v46
19+
with:
20+
files: |
21+
**/*
22+
23+
- name: Setup Go
24+
if: steps.changed-files.outputs.files != ''
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version-file: go.mod
28+
29+
- name: Running Tests
30+
if: steps.changed-files.outputs.files != ''
31+
run: |
32+
go mod tidy
33+
make test

api/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/cobaltcore-dev/cortex/api
2+
3+
go 1.24.0
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2025 SAP SE
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cinder
5+
6+
// Host object from the Cinder scheduler pipeline.
7+
type ExternalSchedulerHost struct {
8+
// Name of the Cinder share host.
9+
VolumeHost string `json:"host"`
10+
}
11+
12+
// Request generated by the Cinder scheduler when calling cortex.
13+
// The request contains a spec of the share to be scheduled, a list of hosts and
14+
// their status, and a map of weights that were calculated by the Cinder weigher
15+
// pipeline. Some additional flags are also included.
16+
type ExternalSchedulerRequest struct {
17+
// TODO: Use a more specific type for the spec.
18+
Spec any `json:"spec"`
19+
// Request context from Cinder that contains additional meta information.
20+
Context CinderRequestContext `json:"context"`
21+
// The share hosts that are available for scheduling.
22+
Hosts []ExternalSchedulerHost `json:"hosts"`
23+
// Weights map of share hosts to their weights calculated by the Cinder weigher pipeline.
24+
Weights map[string]float64 `json:"weights"`
25+
26+
// Whether the request is a sandboxed request. By default, this is false.
27+
//
28+
// Sandboxed requests can be used to notify cortex that the resource is not
29+
// actually being scheduled, and that sandboxed scheduler steps should be
30+
// executed for additional validation.
31+
Sandboxed bool `json:"sandboxed"`
32+
}
33+
34+
// Response generated by cortex for the Cinder scheduler.
35+
// Cortex returns an ordered list of hosts that the share should be scheduled on.
36+
type ExternalSchedulerResponse struct {
37+
Hosts []string `json:"hosts"`
38+
}
39+
40+
// TODO add specs
41+
type CinderRequestContext struct {
42+
// Fields added by oslo.context
43+
44+
UserID string `json:"user"`
45+
ProjectID string `json:"project_id"`
46+
SystemScope string `json:"system_scope"`
47+
DomainID string `json:"domain"`
48+
UserDomainID string `json:"user_domain"`
49+
ProjectDomainID string `json:"project_domain"`
50+
IsAdmin bool `json:"is_admin"`
51+
ReadOnly bool `json:"read_only"`
52+
ShowDeleted bool `json:"show_deleted"`
53+
RequestID string `json:"request_id"`
54+
GlobalRequestID string `json:"global_request_id"`
55+
ResourceUUID string `json:"resource_uuid"`
56+
Roles []string `json:"roles"`
57+
UserIdentity string `json:"user_identity"`
58+
IsAdminProject bool `json:"is_admin_project"`
59+
60+
// Fields added by the Cinder scheduler
61+
62+
RemoteAddress string `json:"remote_address"`
63+
Timestamp string `json:"timestamp"`
64+
QuotaClass *string `json:"quota_class"`
65+
ProjectName string `json:"project_name"`
66+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2025 SAP SE
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package manila
5+
6+
// Host object from the Manila scheduler pipeline.
7+
type ExternalSchedulerHost struct {
8+
// Name of the Manila share host.
9+
ShareHost string `json:"host"`
10+
}
11+
12+
// Request generated by the Manila scheduler when calling cortex.
13+
// The request contains a spec of the share to be scheduled, a list of hosts and
14+
// their status, and a map of weights that were calculated by the Manila weigher
15+
// pipeline. Some additional flags are also included.
16+
type ExternalSchedulerRequest struct {
17+
// TODO: Use a more specific type for the spec.
18+
Spec any `json:"spec"`
19+
// Request context from Manila that contains additional meta information.
20+
Context ManilaRequestContext `json:"context"`
21+
// The share hosts that are available for scheduling.
22+
Hosts []ExternalSchedulerHost `json:"hosts"`
23+
// Weights map of share hosts to their weights calculated by the Manila weigher pipeline.
24+
Weights map[string]float64 `json:"weights"`
25+
26+
// Whether the request is a sandboxed request. By default, this is false.
27+
//
28+
// Sandboxed requests can be used to notify cortex that the resource is not
29+
// actually being scheduled, and that sandboxed scheduler steps should be
30+
// executed for additional validation.
31+
Sandboxed bool `json:"sandboxed"`
32+
}
33+
34+
// Response generated by cortex for the Manila scheduler.
35+
// Cortex returns an ordered list of hosts that the share should be scheduled on.
36+
type ExternalSchedulerResponse struct {
37+
Hosts []string `json:"hosts"`
38+
}
39+
40+
// Manila request context object. For the spec of this object, see:
41+
//
42+
// - This: https://github.com/sapcc/manila/blob/4ffdfc/manila/context.py#L29
43+
// - And: https://github.com/openstack/oslo.context/blob/db20dd/oslo_context/context.py#L329
44+
//
45+
// Some fields are omitted: "service_catalog", "read_deleted" (same as "show_deleted")
46+
type ManilaRequestContext struct {
47+
// Fields added by oslo.context
48+
49+
UserID string `json:"user"`
50+
ProjectID string `json:"project_id"`
51+
SystemScope string `json:"system_scope"`
52+
DomainID string `json:"domain"`
53+
UserDomainID string `json:"user_domain"`
54+
ProjectDomainID string `json:"project_domain"`
55+
IsAdmin bool `json:"is_admin"`
56+
ReadOnly bool `json:"read_only"`
57+
ShowDeleted bool `json:"show_deleted"`
58+
RequestID string `json:"request_id"`
59+
GlobalRequestID string `json:"global_request_id"`
60+
ResourceUUID string `json:"resource_uuid"`
61+
Roles []string `json:"roles"`
62+
UserIdentity string `json:"user_identity"`
63+
IsAdminProject bool `json:"is_admin_project"`
64+
65+
// Fields added by the Manila scheduler
66+
67+
RemoteAddress string `json:"remote_address"`
68+
Timestamp string `json:"timestamp"`
69+
QuotaClass string `json:"quota_class"`
70+
ProjectName string `json:"project_name"`
71+
}

0 commit comments

Comments
 (0)