-
Notifications
You must be signed in to change notification settings - Fork 137
fix ProviderData.Update() semantics wrt controller-runtime client cache #2008
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,20 +99,27 @@ func GetMachineUpdater(ctx context.Context, client ctrlruntimeclient.Client) Mac | |
| // Store name here, because the machine can be nil if an update failed. | ||
| namespacedName := types.NamespacedName{Namespace: machine.Namespace, Name: machine.Name} | ||
| return retry.RetryOnConflict(retry.DefaultBackoff, func() error { | ||
| if err := client.Get(ctx, namespacedName, machine); err != nil { | ||
| cachedMachine := &clusterv1alpha1.Machine{} | ||
| if err := client.Get(ctx, namespacedName, cachedMachine); err != nil { | ||
| return fmt.Errorf("failed to get machine: %w", err) | ||
| } | ||
|
|
||
| // Check if we actually change something and only update if that is the case. | ||
| unmodifiedMachine := machine.DeepCopy() | ||
| unmodifiedMachine := cachedMachine.DeepCopy() | ||
| for _, modify := range modifiers { | ||
| modify(machine) | ||
| modify(cachedMachine) | ||
| } | ||
| if equality.Semantic.DeepEqual(unmodifiedMachine, machine) { | ||
| if equality.Semantic.DeepEqual(unmodifiedMachine, cachedMachine) { | ||
|
Comment on lines
107
to
+112
|
||
| return nil | ||
| } | ||
|
Comment on lines
+112
to
114
|
||
|
|
||
| return client.Update(ctx, machine) | ||
| if err := client.Update(ctx, cachedMachine); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| cachedMachine.DeepCopyInto(machine) | ||
|
|
||
| return 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.
The comment says the passed-in
machinecan be nil, but this function dereferencesmachineimmediately (Namespace/Name) and later callsDeepCopyInto(machine), which would panic if it were nil. Either adjust the comment to reflect the actual contract (non-nil required) or add an explicit nil check that returns a clear error.