Skip to content

Commit

Permalink
index on environment
Browse files Browse the repository at this point in the history
  • Loading branch information
eedorenko committed Dec 10, 2024
1 parent 66560e4 commit 4b7f112
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions controllers/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}).
Expand Down

0 comments on commit 4b7f112

Please # to comment.