-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: record instrumented application in all cases (#1416)
- Loading branch information
Showing
7 changed files
with
90 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,80 +19,33 @@ package instrumentationdevice | |
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||
"github.com/odigos-io/odigos/k8sutils/pkg/workload" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
// CollectorsGroupReconciler reconciles a CollectorsGroup object | ||
type CollectorsGroupReconciler struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
//+kubebuilder:rbac:groups=odigos.io,resources=collectorsgroups,verbs=get;list;watch;create;update;patch;delete | ||
//+kubebuilder:rbac:groups=odigos.io,resources=collectorsgroups/status,verbs=get;update;patch | ||
//+kubebuilder:rbac:groups=odigos.io,resources=collectorsgroups/finalizers,verbs=update | ||
|
||
// Reconcile is part of the main kubernetes reconciliation loop which aims to | ||
// move the current state of the cluster closer to the desired state. | ||
// the CollectorsGroup object against the actual cluster state, and then | ||
// perform operations to make the cluster state reflect the state specified by | ||
// the user. | ||
// | ||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logger := log.FromContext(ctx) | ||
if isDataCollectionReady(ctx, r.Client) { | ||
logger.V(0).Info("data collection is ready, instrumenting selected applications") | ||
var instApps odigosv1.InstrumentedApplicationList | ||
if err := r.List(ctx, &instApps); err != nil { | ||
logger.Error(err, "failed to list InstrumentedApps") | ||
return ctrl.Result{}, err | ||
} | ||
|
||
for _, instApp := range instApps.Items { | ||
err := instrument(logger, ctx, r.Client, &instApp) | ||
if err != nil { | ||
logger.Error(err, "failed to instrument application", "application", instApp.Name, "namespace", instApp.Namespace) | ||
return ctrl.Result{}, err | ||
} | ||
} | ||
} else { | ||
err := r.removeAllInstrumentations(ctx, logger) | ||
if err != nil { | ||
logger.Error(err, "failed to remove instrumentations") | ||
return ctrl.Result{}, err | ||
} | ||
} | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
isDataCollectionReady := isDataCollectionReady(ctx, r.Client) | ||
|
||
func (r *CollectorsGroupReconciler) removeAllInstrumentations(ctx context.Context, logger logr.Logger) error { | ||
var instApps odigosv1.InstrumentedApplicationList | ||
if err := r.List(ctx, &instApps); err != nil { | ||
return err | ||
return ctrl.Result{}, err | ||
} | ||
|
||
for _, instApp := range instApps.Items { | ||
name, kind, err := workload.GetWorkloadInfoRuntimeName(instApp.Name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = uninstrument(logger, ctx, r.Client, instApp.Namespace, name, kind, UnInstrumentReasonRemoveAll) | ||
for _, runtimeDetails := range instApps.Items { | ||
err := reconcileSingleWorkload(ctx, r.Client, &runtimeDetails, isDataCollectionReady) | ||
if err != nil { | ||
logger.Error(err, "failed to remove instrumentation", "application", name, "namespace", instApp.Namespace, "kind", kind) | ||
return err | ||
return ctrl.Result{}, err | ||
} | ||
} | ||
|
||
return nil | ||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.