diff --git a/controllers/schedulingpolicy_controller.go b/controllers/schedulingpolicy_controller.go index 4736bd4..c7f028c 100644 --- a/controllers/schedulingpolicy_controller.go +++ b/controllers/schedulingpolicy_controller.go @@ -48,6 +48,7 @@ const ( ReconcilerField = "spec.reconciler" NamespaceServiceField = "spec.namespaceService" DeploymentTargetField = "spec.deploymentTarget" + EnvironmentField = "spec.environment" ) // +kubebuilder:rbac:groups=scheduler.kalypso.io,resources=schedulingpolicies,verbs=get;list;watch;create;update;patch;delete @@ -267,6 +268,13 @@ func (r *SchedulingPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } + // 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 + } + return ctrl.NewControllerManagedBy(mgr). For(&schedulerv1alpha1.SchedulingPolicy{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). Owns(&schedulerv1alpha1.Assignment{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})). diff --git a/controllers/workload_controller.go b/controllers/workload_controller.go index 0f6b111..b8c7abb 100644 --- a/controllers/workload_controller.go +++ b/controllers/workload_controller.go @@ -40,10 +40,6 @@ 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 @@ -240,18 +236,6 @@ 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{}).