Skip to content

Commit

Permalink
chore: add the source reconcailer
Browse files Browse the repository at this point in the history
  • Loading branch information
alonbraymok committed Jan 1, 2025
1 parent 7024a7f commit 8056f3d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions autoscaler/controllers/source_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package controllers

import (
"context"

controllerconfig "github.com/odigos-io/odigos/autoscaler/controllers/controller_config"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"

v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
)

type SourceReconciler struct {
client.Client
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
Config *controllerconfig.ControllerConfig
}

// Reconcile ensures that any changes to Source CRDs (creation, deletion, or label modifications)
// trigger a recalculation of the ConfigMap that configures the routing filter processors.
func (r *SourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Source")

err := gateway.Sync(ctx, r.Client, r.Scheme, r.ImagePullSecrets, r.OdigosVersion, r.Config)
if err != nil {
logger.Error(err, "Failed to sync gateway configuration")
return ctrl.Result{}, err
}

logger.V(1).Info("Successfully synced gateway configuration for Source", "Source", req.NamespacedName)
return ctrl.Result{}, nil
}

func (r *SourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&v1.Source{}).
// Trigger reconciliation on create, delete, or label changes
WithEventFilter(predicate.Or(
predicate.GenerationChangedPredicate{},
predicate.LabelChangedPredicate{},
predicate.Funcs{
DeleteFunc: func(e event.DeleteEvent) bool {
return true
},
},
)).
Complete(r)
}
10 changes: 10 additions & 0 deletions autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "DaemonSet")
os.Exit(1)
}
if err = (&controllers.SourceReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ImagePullSecrets: imagePullSecrets,
OdigosVersion: odigosVersion,
Config: config,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Source")
os.Exit(1)
}

if err = actions.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create odigos actions controllers")
Expand Down

0 comments on commit 8056f3d

Please sign in to comment.