Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 58 additions & 41 deletions cmd/manager/main.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions helm/bundles/cortex-nova/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ cortex: &cortex
- kvm.cloud.sap/v1/Hypervisor
- kvm.cloud.sap/v1/HypervisorList
- v1/Secret
clientcache:
gvks:
- cortex.cloud/v1alpha1/Reservation
keystoneSecretRef:
Comment thread
SoWieMarkus marked this conversation as resolved.
name: cortex-nova-openstack-keystone
namespace: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (c *HypervisorOvercommitController) predicateRemoteHypervisor() predicate.P
// SetupWithManager sets up the controller with the Manager and a multicluster
// client. The multicluster client is used to watch for changes in the
// Hypervisor CRD across all clusters and trigger reconciliations accordingly.
func (c *HypervisorOvercommitController) SetupWithManager(mgr ctrl.Manager) (err error) {
func (c *HypervisorOvercommitController) SetupWithManager(mgr ctrl.Manager, mcl *multicluster.Client) (err error) {
// This will load the config in a safe way and gracefully handle errors.
c.config, err = conf.GetConfig[HypervisorOvercommitConfig]()
if err != nil {
Expand All @@ -227,12 +227,6 @@ func (c *HypervisorOvercommitController) SetupWithManager(mgr ctrl.Manager) (err
if err := c.config.Validate(); err != nil {
return err
}
// Check that the provided client is a multicluster client, since we need
// that to watch for hypervisors across clusters.
mcl, ok := c.Client.(*multicluster.Client)
if !ok {
return errors.New("provided client must be a multicluster client")
}
bldr := multicluster.BuildController(mcl, mgr)
// The hypervisor crd may be distributed across multiple remote clusters.
bldr, err = bldr.WatchesMulticluster(&hv1.Hypervisor{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func TestHypervisorOvercommitController_SetupWithManager_InvalidClient(t *testin
// SetupWithManager should fail - either because config loading fails
// (in test environment without config files) or because the client
// is not a multicluster client.
err := controller.SetupWithManager(mgr)
err := controller.SetupWithManager(mgr, nil)
if err == nil {
t.Error("expected error when calling SetupWithManager, got nil")
}
Expand Down
16 changes: 8 additions & 8 deletions internal/scheduling/reservations/inflight/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,7 @@ func (c *Controller) predicateHypervisors() predicate.Predicate {
// SetupWithManager sets up the controller with the Manager and a multicluster
// client. The multicluster client is used to watch for changes in the
// Reservation CRD across all clusters and trigger reconciliations accordingly.
func (c *Controller) SetupWithManager(ctx context.Context, mgr ctrl.Manager) (err error) {
// Check that the provided client is a multicluster client, since we need
// that to watch for hypervisors across clusters. Do this before adding
// any runnables so a misconfigured setup fails fast.
mcl, ok := c.Client.(*multicluster.Client)
if !ok {
return errors.New("provided client must be a multicluster client")
}
func (c *Controller) SetupWithManager(ctx context.Context, mgr ctrl.Manager, mcl *multicluster.Client) (err error) {
// Add the vm client as runnable to the manager.
if err := mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
return c.VMClient.StartWithKubernetesSecrets(ctx, c.Client)
Expand All @@ -412,6 +405,13 @@ func (c *Controller) SetupWithManager(ctx context.Context, mgr ctrl.Manager) (er
); err != nil {
return err
}
// Register the same index with the overlay so that List calls with
// MatchingFields correctly filter in-flight overlay entries.
if fi, ok := c.Client.(client.FieldIndexer); ok {
if err := fi.IndexField(ctx, &v1alpha1.Reservation{}, idxReservationByTargetHost, idxReservationByTargetHostFn); err != nil {
return err
}
}
// Watch hypervisor changes and requeue reservations targeting
// the changed hypervisor.
bldr, err = bldr.WatchesMulticluster(&hv1.Hypervisor{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,3 @@ func TestHandleHypervisors_NoMatchingReservations(t *testing.T) {
t.Errorf("queue = %+v, want empty", q.items)
}
}

func TestSetupWithManager_RejectsNonMulticlusterClient(t *testing.T) {
scheme := newTestScheme(t)
c := &Controller{Client: newTestClient(scheme), VMClient: &stubVMClient{}}
err := c.SetupWithManager(context.Background(), nil)
if err == nil {
t.Fatal("expected error for non-multicluster client, got nil")
}
}
Loading