diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 03baed8..1b3ce66 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,6 @@ jobs: IMAGE_TAG=${{ vars.MAJOR_VERSION }}.${{ vars.MINOR_VERSION }}.${{ vars.HF_VERSION }}-${{ github.run_number }} echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV echo $IMAGE_TAG > $GITHUB_WORKSPACE/IMAGE_TAG - make build - name: Build and Push to GHCR uses: docker/build-push-action@v2 @@ -38,7 +37,7 @@ jobs: tags: ghcr.io/microsoft/kalypso-scheduler:${{ env.IMAGE_TAG }}, ghcr.io/microsoft/kalypso-scheduler:latest - name: Upload Image Tags - uses: actions/upload-artifact@v2.2.2 + uses: actions/upload-artifact@v4.4.3 with: name: image_tag_paris path: ${{ github.workspace }}/IMAGE_TAG @@ -52,6 +51,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: '1.20' - name: Install Helmify run: | diff --git a/controllers/schedulingpolicy_controller.go b/controllers/schedulingpolicy_controller.go index 7c5c9a5..d45f187 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 @@ -100,9 +101,9 @@ func (r *SchedulingPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Req return r.manageFailure(ctx, reqLogger, schedulingPolicy, err, "Failed to list ClusterTypes") } - // fetch the list if deployment targets in the namespace + // fetch the list of deployment targets in the namespace with environment field equal to the namespace name deploymentTargets := &schedulerv1alpha1.DeploymentTargetList{} - err = r.List(ctx, deploymentTargets, client.InNamespace(req.Namespace)) + err = r.List(ctx, deploymentTargets, client.InNamespace(req.Namespace), client.MatchingFields{EnvironmentField: req.Namespace}) if err != nil { return r.manageFailure(ctx, reqLogger, schedulingPolicy, err, "Failed to list DeploymentTargets") } @@ -267,6 +268,13 @@ func (r *SchedulingPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error { return err } + // Add the field index for the environment 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 ec63bce..b8c7abb 100644 --- a/controllers/workload_controller.go +++ b/controllers/workload_controller.go @@ -236,6 +236,7 @@ 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 { + return ctrl.NewControllerManagedBy(mgr). For(&schedulerv1alpha1.Workload{}). Owns(&schedulerv1alpha1.DeploymentTarget{}).