Skip to content

Commit

Permalink
chore(scheduler): use instrumentation config instead of application (#…
Browse files Browse the repository at this point in the history
…1602)

This PR moves the scheduler component to use `instrumentationconfigs`
instead of `instrumentedapplications`. There is an effort to merge them
any only use one CRD - the `instrumentationconfigs`.

The content of the object is not examined, it only checks if we have any
`instrumentationconfigs` or not. Thus it should be safe.
  • Loading branch information
blumamir authored Oct 20, 2024
1 parent 72e7b66 commit b976b0a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/resources/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func NewSchedulerClusterRole() *rbacv1.ClusterRole {
"watch",
},
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentedapplications"},
Resources: []string{"instrumentationconfigs"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion helm/odigos/templates/scheduler/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rules:
- apiGroups:
- odigos.io
resources:
- instrumentedapplications
- instrumentationconfigs
verbs:
- get
- list
Expand Down
2 changes: 1 addition & 1 deletion scheduler/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repo: github.com/odigos-io/odigos/scheduler
resources:
- controller: true
domain: odigos.io
kind: InstrumentedApplication
kind: InstrumentationConfig
version: v1alpha1
- controller: true
domain: odigos.io
Expand Down
4 changes: 2 additions & 2 deletions scheduler/controllers/collectorsgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
}

var instApps odigosv1.InstrumentedApplicationList
var instApps odigosv1.InstrumentationConfigList
if err = r.List(ctx, &instApps); err != nil {
logger.Error(err, "failed to list InstrumentedApps")
logger.Error(err, "failed to list InstrumentationConfigs")
return ctrl.Result{}, err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
Expand All @@ -14,27 +15,26 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// InstrumentedApplicationReconciler reconciles a InstrumentedApplication object
type InstrumentedApplicationReconciler struct {
type InstrumentationConfigReconciler struct {
client.Client
Scheme *runtime.Scheme
ImagePullSecrets []string
OdigosVersion string
}

func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *InstrumentationConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling InstrumentedApps")
logger.V(0).Info("Reconciling InstrumentationConfig")

namespace := env.GetCurrentNamespace()

var instrumentedApps odigosv1.InstrumentedApplicationList
err := r.List(ctx, &instrumentedApps)
var instrumentedConfigs odigosv1.InstrumentationConfigList
err := r.List(ctx, &instrumentedConfigs)
if err != nil {
logger.Error(err, "failed to list InstrumentedApplications")
logger.Error(err, "failed to list InstrumentationConfigs")
return ctrl.Result{}, err
}
numberOfInstrumentedApps := len(instrumentedApps.Items)
numberOfInstrumentedApps := len(instrumentedConfigs.Items)

if numberOfInstrumentedApps == 0 {
if err = utils.DeleteCollectorGroup(ctx, r.Client, namespace, consts.OdigosNodeCollectorCollectorGroupName); err != nil {
Expand Down Expand Up @@ -74,9 +74,8 @@ func (r *InstrumentedApplicationReconciler) Reconcile(ctx context.Context, req c
return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *InstrumentedApplicationReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *InstrumentationConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&odigosv1.InstrumentedApplication{}).
For(&odigosv1.InstrumentationConfig{}).
Complete(r)
}
4 changes: 2 additions & 2 deletions scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Destination")
os.Exit(1)
}
if err = (&controllers.InstrumentedApplicationReconciler{
if err = (&controllers.InstrumentationConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "InstrumentedApplication")
setupLog.Error(err, "unable to create controller", "controller", "InstrumentationConfig")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
Expand Down

0 comments on commit b976b0a

Please sign in to comment.