Skip to content

Commit

Permalink
feat: migrate elasticquota controller to ctrl runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
nayihz committed Mar 11, 2023
1 parent 7da686c commit 2f5cf9b
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 462 deletions.
13 changes: 8 additions & 5 deletions cmd/controller/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"

schedulingv1a1 "sigs.k8s.io/scheduler-plugins/apis/scheduling/v1alpha1"
"sigs.k8s.io/scheduler-plugins/pkg/controller"
"sigs.k8s.io/scheduler-plugins/pkg/controllers"
schedclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
schedformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
Expand Down Expand Up @@ -86,11 +85,8 @@ func Run(s *ServerRunOptions) error {
kubeClient := kubernetes.NewForConfigOrDie(config)

schedInformerFactory := schedformers.NewSharedInformerFactory(schedClient, 0)
eqInformer := schedInformerFactory.Scheduling().V1alpha1().ElasticQuotas()

coreInformerFactory := informers.NewSharedInformerFactory(kubeClient, 0)
podInformer := coreInformerFactory.Core().V1().Pods()
eqCtrl := controller.NewElasticQuotaController(kubeClient, eqInformer, podInformer, schedClient)

// Controller Runtime Controllers
ctrl.SetLogger(klogr.New())
Expand All @@ -116,6 +112,14 @@ func Run(s *ServerRunOptions) error {
return err
}

if err = (&controllers.ElasticQuotaReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ElasticQuota")
return err
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
return err
Expand All @@ -126,7 +130,6 @@ func Run(s *ServerRunOptions) error {
}

run := func(ctx context.Context) {
go eqCtrl.Run(s.Workers, ctx.Done())
setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
3 changes: 3 additions & 0 deletions manifests/install/all-in-one.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ rules:
- apiGroups: ["scheduling.x-k8s.io"]
resources: ["podgroups", "elasticquotas", "podgroups/status", "elasticquotas/status"]
verbs: ["get", "list", "watch", "create", "delete", "update", "patch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch", "update"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch", "update"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch", "patch"]
Expand Down
Loading

0 comments on commit 2f5cf9b

Please sign in to comment.