-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Source CRD instrumentation #2059
base: feature/source-crd
Are you sure you want to change the base?
Conversation
// GetSourceListForWorkload returns a SourceList of all Sources that have matching | ||
// workload name, namespace, and kind labels for an object. In theory, this should only | ||
// ever return a list with 0 or 1 items, but due diligence should handle unexpected cases. | ||
func GetSourceListForWorkload(ctx context.Context, kubeClient client.Client, obj client.Object) (*SourceList, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
func GetSourceListForWorkload(ctx context.Context, kubeClient client.Client, obj client.Object) (*SourceList, error) { | |
func GetSourceListForWorkload(ctx context.Context, kubeClient client.Client, obj client.Object) (SourceList, error) { |
// Added by startlangdetection controller when Source is created | ||
var instrumentedApplicationFinalizer = "odigos.io/source-instrumentedapplication-finalizer" | ||
|
||
type SourceDeletedPredicate struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a utils package for predicates.
This one exists in k8sutils/pkg.predicate/deletion.go
source.Labels[workloadNamespaceLabel] = source.Spec.Workload.Namespace | ||
source.Labels[workloadKindLabel] = string(source.Spec.Workload.Kind) | ||
|
||
if err := r.Update(ctx, source); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is possible here but since we are using Get
modify Update
we could get a conflict error if the update is on a stale object.
We have k8sutils/pkg/utils/retryconflict.go
if it is relevant here.
// GetSourceListForWorkload returns a SourceList of all Sources that have matching | ||
// workload name, namespace, and kind labels for an object. In theory, this should only | ||
// ever return a list with 0 or 1 items, but due diligence should handle unexpected cases. | ||
func GetSourceListForWorkload(ctx context.Context, kubeClient client.Client, obj client.Object) (*SourceList, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought: maybe we could wrap this function in another once returning a single source or an error.
workloadNameLabel = "odigos.io/workload-name" | ||
workloadNamespaceLabel = "odigos.io/workload-namespace" | ||
workloadKindLabel = "odigos.io/workload-kind" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these consts will be used in other places as well, so maybe worth considering placing them in k8sutils/pkg/consts
@@ -74,5 +76,17 @@ func SetupWithManager(mgr ctrl.Manager) error { | |||
return err | |||
} | |||
|
|||
err = builder. | |||
ControllerManagedBy(mgr). | |||
Named("startlangdetection-source"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an event filter here to pass only Create events?
// Check if a Source object exists for this workload | ||
sourceList, err := v1alpha1.GetSourceListForWorkload(ctx, k8sClient, obj) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
if len(sourceList.Items) == 0 { | ||
return ctrl.Result{}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which cases are handled here?
@@ -200,6 +200,11 @@ cli-install: | |||
@echo "Installing odigos from source. version: $(ODIGOS_CLI_VERSION)" | |||
cd ./cli ; go run -tags=embed_manifests . install --version $(ODIGOS_CLI_VERSION) | |||
|
|||
.PHONY: cli-uninstall | |||
cli-uninstall: | |||
@echo "Installing odigos from source. version: $(ODIGOS_CLI_VERSION)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
@echo "Installing odigos from source. version: $(ODIGOS_CLI_VERSION)" | |
@echo "Uninstalling odigos from source. version: $(ODIGOS_CLI_VERSION)" |
This introduces the basic implementation for instrumenting/uninstrumenting via
Source
objects (#2037)This does not remove current instrumentation with the
odigos-instrumentation
label, and does not do any checks to avoid conflicts etc. That work will follow. Right now this just drops in the basic workflow alongside the current label approach.Changes:
SourceReconciler
to thestartlangdetection
Instrumentor controller.Source
objectSource
is not being deleted, add 2 finalizers (one used forSource
deletion, and another used by thedeleteinstrumentedapplication
controller), add workload labels to theSource
for lookup, and continue with flow of creating anInstrumentationConfig
by callingrequestOdigletsToCalculateRuntimeDetails
Source
is being deleted (determined by aDeletionTimestamp
being present in an Update event, with the finalizer blocking deletion), remove the source finalizer and delete theInstrumentationConfig
.GetSourceListForWorkload
everywhere we currently callworkload.IsWorkloadInstrumentationEffectiveEnabled
that returns anySource
objects referencing the workload.SourceReconciler
todeleteinstrumentedapplication
Instrumentor controllerSource
object is deleted, remove instrumented application finalizer and continue with reconciling the workload, which should trigger uninstrumentation based on the new checks forGetSourceListForWorkload
throughoutI'm not a fan of using 2 finalizers and worry that we could end up with a deadlock/race. This is mostly due to InstrumentedApplication, and deprecating InstrumentedApplication should simplify the work required for this greatly.
Still needs:
odigos-instrumentation
label to be shorthand for creating aSource
on that workload/namespaceworkload.IsWorkloadInstrumentationEffectiveEnabled