Skip to content

Commit

Permalink
Merge pull request #31 from microsoft/eedorenko/deployment-target-env…
Browse files Browse the repository at this point in the history
…ironment

Deployment target environment
  • Loading branch information
eedorenko authored Dec 16, 2024
2 parents 2201d81 + 3960fa1 commit 696d534
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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: |
Expand Down
12 changes: 10 additions & 2 deletions controllers/schedulingpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{})).
Expand Down
1 change: 1 addition & 0 deletions controllers/workload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}).
Expand Down

0 comments on commit 696d534

Please # to comment.