From 4b7f112d544a2f08201b024a04b97b95a9e77729 Mon Sep 17 00:00:00 2001 From: Eugene Fedorenko Date: Tue, 10 Dec 2024 12:26:58 -0800 Subject: [PATCH] index on environment --- controllers/workload_controller.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/controllers/workload_controller.go b/controllers/workload_controller.go index ec63bce..0f6b111 100644 --- a/controllers/workload_controller.go +++ b/controllers/workload_controller.go @@ -40,6 +40,10 @@ type WorkloadReconciler struct { Scheme *runtime.Scheme } +const ( + EnvironmentField = "spec.environment" +) + // +kubebuilder:rbac:groups=scheduler.kalypso.io,resources=workloads,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=scheduler.kalypso.io,resources=workloads/status,verbs=get;update;patch // +kubebuilder:rbac:groups=scheduler.kalypso.io,resources=workloads/finalizers,verbs=update @@ -236,6 +240,19 @@ func (h *WorkloadReconciler) manageFailure(ctx context.Context, logger logr.Logg // SetupWithManager sets up the controller with the Manager. func (r *WorkloadReconciler) SetupWithManager(mgr ctrl.Manager) error { + // Add the field index for the environmrnt in the deployment target + if err := mgr.GetFieldIndexer().IndexField(context.Background(), &schedulerv1alpha1.DeploymentTarget{}, EnvironmentField, func(rawObj client.Object) []string { + return []string{rawObj.(*schedulerv1alpha1.DeploymentTarget).Spec.Environment} + }); err != nil { + return err + } + + // if err := mgr.GetFieldIndexer().IndexField(context.Background(), &schedulerv1alpha1.Assignment{}, DeploymentTargetField, func(rawObj client.Object) []string { + // return []string{rawObj.(*schedulerv1alpha1.Assignment).Spec.DeploymentTarget} + // }); err != nil { + // return err + // } + return ctrl.NewControllerManagedBy(mgr). For(&schedulerv1alpha1.Workload{}). Owns(&schedulerv1alpha1.DeploymentTarget{}).