Skip to content

Commit 7ffb84b

Browse files
Cleanup: move reservations config to reservations module
1 parent d34d055 commit 7ffb84b

6 files changed

Lines changed: 26 additions & 20 deletions

File tree

cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ func main() {
386386
if slices.Contains(config.EnabledControllers, "reservations-controller") {
387387
monitor := reservationscontroller.NewControllerMonitor(multiclusterClient)
388388
metrics.Registry.MustRegister(&monitor)
389+
reservationsControllerConfig := conf.GetConfigOrDie[reservationscontroller.Config]()
389390
if err := (&reservationscontroller.ReservationReconciler{
390391
Client: multiclusterClient,
391392
Scheme: mgr.GetScheme(),
392-
Conf: config,
393+
Conf: reservationsControllerConfig,
393394
HypervisorClient: reservationscontroller.NewHypervisorClient(),
394395
}).SetupWithManager(mgr, multiclusterClient); err != nil {
395396
setupLog.Error(err, "unable to create controller", "controller", "Reservation")

internal/scheduling/reservations/controller/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"net/http"
1111

12-
"github.com/cobaltcore-dev/cortex/pkg/conf"
1312
"github.com/cobaltcore-dev/cortex/pkg/keystone"
1413
"github.com/cobaltcore-dev/cortex/pkg/sso"
1514
"github.com/gophercloud/gophercloud/v2"
@@ -36,7 +35,7 @@ type Hypervisor struct {
3635
// Client to fetch hypervisor data.
3736
type HypervisorClient interface {
3837
// Init the client.
39-
Init(ctx context.Context, client client.Client, conf conf.Config) error
38+
Init(ctx context.Context, client client.Client, conf Config) error
4039
// List all hypervisors.
4140
ListHypervisors(ctx context.Context) ([]Hypervisor, error)
4241
}
@@ -56,7 +55,7 @@ func NewHypervisorClient() HypervisorClient {
5655
}
5756

5857
// Init the client.
59-
func (c *hypervisorClient) Init(ctx context.Context, client client.Client, conf conf.Config) error {
58+
func (c *hypervisorClient) Init(ctx context.Context, client client.Client, conf Config) error {
6059
var authenticatedHTTP = http.DefaultClient
6160
if conf.SSOSecretRef != nil {
6261
var err error

internal/scheduling/reservations/controller/client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package controller
66
import (
77
"context"
88

9-
"github.com/cobaltcore-dev/cortex/pkg/conf"
109
"sigs.k8s.io/controller-runtime/pkg/client"
1110
)
1211

@@ -15,7 +14,7 @@ type mockHypervisorClient struct {
1514
errToReturn error
1615
}
1716

18-
func (m *mockHypervisorClient) Init(ctx context.Context, client client.Client, conf conf.Config) error {
17+
func (m *mockHypervisorClient) Init(ctx context.Context, client client.Client, conf Config) error {
1918
return nil
2019
}
2120

internal/scheduling/reservations/controller/controller.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,27 @@ import (
2323

2424
schedulerdelegationapi "github.com/cobaltcore-dev/cortex/api/external/nova"
2525
"github.com/cobaltcore-dev/cortex/api/v1alpha1"
26-
"github.com/cobaltcore-dev/cortex/pkg/conf"
2726
"github.com/cobaltcore-dev/cortex/pkg/multicluster"
27+
corev1 "k8s.io/api/core/v1"
2828
)
2929

30+
// Endpoints for the reservations operator.
31+
type EndpointsConfig struct {
32+
// The nova external scheduler endpoint.
33+
NovaExternalScheduler string `json:"novaExternalScheduler"`
34+
}
35+
36+
type Config struct {
37+
// The endpoint where to find the nova external scheduler endpoint.
38+
Endpoints EndpointsConfig `json:"endpoints"`
39+
40+
// Secret ref to SSO credentials stored in a k8s secret, if applicable.
41+
SSOSecretRef *corev1.SecretReference `json:"ssoSecretRef"`
42+
43+
// Secret ref to keystone credentials stored in a k8s secret.
44+
KeystoneSecretRef corev1.SecretReference `json:"keystoneSecretRef"`
45+
}
46+
3047
// ReservationReconciler reconciles a Reservation object
3148
type ReservationReconciler struct {
3249
// Client to fetch hypervisors.
@@ -36,7 +53,7 @@ type ReservationReconciler struct {
3653
// Kubernetes scheme to use for the reservations.
3754
Scheme *runtime.Scheme
3855
// Configuration for the controller.
39-
Conf conf.Config
56+
Conf Config
4057
}
4158

4259
// Reconcile is part of the main kubernetes reconciliation loop which aims to

internal/scheduling/reservations/controller/controller_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
schedulerdelegationapi "github.com/cobaltcore-dev/cortex/api/external/nova"
2121
"github.com/cobaltcore-dev/cortex/api/v1alpha1"
22-
"github.com/cobaltcore-dev/cortex/pkg/conf"
2322
)
2423

2524
func TestReservationReconciler_Reconcile(t *testing.T) {
@@ -185,8 +184,8 @@ func TestReservationReconciler_reconcileInstanceReservation_Success(t *testing.T
185184
}))
186185
defer server.Close()
187186

188-
config := conf.Config{
189-
Endpoints: conf.EndpointsConfig{
187+
config := Config{
188+
Endpoints: EndpointsConfig{
190189
NovaExternalScheduler: server.URL,
191190
},
192191
}

pkg/conf/conf.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,13 @@ import (
1212
corev1 "k8s.io/api/core/v1"
1313
)
1414

15-
// Endpoints for the reservations operator.
16-
type EndpointsConfig struct {
17-
// The nova external scheduler endpoint.
18-
NovaExternalScheduler string `json:"novaExternalScheduler"`
19-
}
20-
2115
type Config struct {
2216
// The controller will only touch resources with this scheduling domain.
2317
SchedulingDomain v1alpha1.SchedulingDomain `json:"schedulingDomain"`
2418

2519
// ID used to identify leader election participants.
2620
LeaderElectionID string `json:"leaderElectionID,omitempty"`
2721

28-
// The endpoint where to find the nova external scheduler endpoint.
29-
Endpoints EndpointsConfig `json:"endpoints"`
30-
3122
// Whether to disable dry-run for descheduler steps.
3223
DisableDeschedulerDryRun bool `json:"disableDeschedulerDryRun"`
3324

0 commit comments

Comments
 (0)