-
Notifications
You must be signed in to change notification settings - Fork 198
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
fix(instrumentor): reconcile device on restarts #1710
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b80508
fix(instrumentor): ensure device is reconciled and removed when neede…
blumamir 82cc1ad
chore: update comment
blumamir f483bc2
chore: remove deprecated annotation
blumamir cc32cf7
refactor: change CreateOrPatch to Update and retry on conflict
blumamir e26684d
Merge remote-tracking branch 'upstream/main' into clean-device-on-res…
blumamir d687145
Merge remote-tracking branch 'upstream/main' into clean-device-on-res…
blumamir 696a3c2
refactor: controller runtime retry on conflict
blumamir 8baf997
chore: add missing file
blumamir 2e225de
Merge branch 'main' into clean-device-on-restart
blumamir 9a4031f
fix(instrumentor): pull entire workload to cache for update
blumamir 4a82a20
Merge remote-tracking branch 'origin/clean-device-on-restart' into cl…
blumamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,9 @@ import ( | |||||||||||||||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/odigos-io/odigos/k8sutils/pkg/utils" | ||||||||||||||||||||||||||||||||||||||||||
"github.com/odigos-io/odigos/k8sutils/pkg/workload" | ||||||||||||||||||||||||||||||||||||||||||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||||||||||||||||||||||||||||||||||||||||||
"k8s.io/apimachinery/pkg/types" | ||||||||||||||||||||||||||||||||||||||||||
ctrl "sigs.k8s.io/controller-runtime" | ||||||||||||||||||||||||||||||||||||||||||
"sigs.k8s.io/controller-runtime/pkg/client" | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -17,7 +19,7 @@ type DeploymentReconciler struct { | |||||||||||||||||||||||||||||||||||||||||
func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||||||||||||||||||||||||||||||||||||||||||
instrumentedAppName := workload.CalculateWorkloadRuntimeObjectName(req.Name, workload.WorkloadKindDeployment) | ||||||||||||||||||||||||||||||||||||||||||
err := reconcileSingleInstrumentedApplicationByName(ctx, r.Client, instrumentedAppName, req.Namespace) | ||||||||||||||||||||||||||||||||||||||||||
return ctrl.Result{}, err | ||||||||||||||||||||||||||||||||||||||||||
return utils.RetryOnConflict(err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
type DaemonSetReconciler struct { | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -27,7 +29,7 @@ type DaemonSetReconciler struct { | |||||||||||||||||||||||||||||||||||||||||
func (r *DaemonSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||||||||||||||||||||||||||||||||||||||||||
instrumentedAppName := workload.CalculateWorkloadRuntimeObjectName(req.Name, workload.WorkloadKindDaemonSet) | ||||||||||||||||||||||||||||||||||||||||||
err := reconcileSingleInstrumentedApplicationByName(ctx, r.Client, instrumentedAppName, req.Namespace) | ||||||||||||||||||||||||||||||||||||||||||
return ctrl.Result{}, err | ||||||||||||||||||||||||||||||||||||||||||
return utils.RetryOnConflict(err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
type StatefulSetReconciler struct { | ||||||||||||||||||||||||||||||||||||||||||
|
@@ -37,16 +39,26 @@ type StatefulSetReconciler struct { | |||||||||||||||||||||||||||||||||||||||||
func (r *StatefulSetReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||||||||||||||||||||||||||||||||||||||||||
instrumentedAppName := workload.CalculateWorkloadRuntimeObjectName(req.Name, workload.WorkloadKindStatefulSet) | ||||||||||||||||||||||||||||||||||||||||||
err := reconcileSingleInstrumentedApplicationByName(ctx, r.Client, instrumentedAppName, req.Namespace) | ||||||||||||||||||||||||||||||||||||||||||
return ctrl.Result{}, err | ||||||||||||||||||||||||||||||||||||||||||
return utils.RetryOnConflict(err) | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
func reconcileSingleInstrumentedApplicationByName(ctx context.Context, k8sClient client.Client, instrumentedAppName string, namespace string) error { | ||||||||||||||||||||||||||||||||||||||||||
var instrumentedApplication odigosv1.InstrumentedApplication | ||||||||||||||||||||||||||||||||||||||||||
err := k8sClient.Get(ctx, types.NamespacedName{Name: instrumentedAppName, Namespace: namespace}, &instrumentedApplication) | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
// changes in workload when there is no instrumented application is not interesting | ||||||||||||||||||||||||||||||||||||||||||
return client.IgnoreNotFound(err) | ||||||||||||||||||||||||||||||||||||||||||
if apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||||
// if there is no instrumented application, make sure the device is removed from the workload pod template manifest | ||||||||||||||||||||||||||||||||||||||||||
workloadName, workloadKind, err := workload.ExtractWorkloadInfoFromRuntimeObjectName(instrumentedAppName) | ||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
err = removeInstrumentationDeviceFromWorkload(ctx, k8sClient, namespace, workloadKind, workloadName, ApplyInstrumentationDeviceReasonNoRuntimeDetails) | ||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this means that a conflict error will be printed by the controller runtime - right? |
||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+49
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
isNodeCollectorReady := isDataCollectionReady(ctx, k8sClient) | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
return reconcileSingleWorkload(ctx, k8sClient, &instrumentedApplication, isNodeCollectorReady) | ||||||||||||||||||||||||||||||||||||||||||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe we should add a check here that the odigos label is present?
Since after this change, when the instrumentor is starting this will cause it to have an event for each workload in the cluster - even those which odigos does not care about.
For those the new check added in this PR below
if apierrors.IsNotFound(err)
will be true.That means the even for workloads which were not instrumented at all we will call
removeInstrumentationDeviceFromWorkload
.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 need to handle workloads which has no label.
Consider the following sequence:
When the instrumentor starts, we need to remove the device from this workload. if we add the filter you suggested, nothing will remove the device from this workload
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.
How about checking if there is a device present in the pod spec? Since we have the workload object here I think we can check that.
I assume it will be fine with the current approach as well, but since this has the potential of bringing a huge batch of events, we should try to handle them as fast as possible by filtering here.