Skip to content
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

pkg/k8s: use a deep copy of CNP in UpdateStatus to avoid race condition #28364

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/k8s/watchers/cilium_network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ func (k *K8sWatcher) addCiliumNetworkPolicyV2(ciliumNPClient clientset.Interface
controller.ControllerParams{
Group: syncCNPStatusControllerGroup,
DoFunc: func(ctx context.Context) error {
return updateContext.UpdateStatus(ctx, cnp, rev, policyImportErr)
// We need to deep-copy the CNP object because UpdateStatus modifies it
// to clear the LastAppliedConfiguration key from annotations map.
return updateContext.UpdateStatus(ctx, cnp.DeepCopy(), rev, policyImportErr)
},
},
)
Expand Down Expand Up @@ -485,7 +487,9 @@ func (k *K8sWatcher) updateCiliumNetworkPolicyV2AnnotationsOnly(ciliumNPClient c
controller.ControllerParams{
Group: syncCNPStatusControllerGroup,
DoFunc: func(ctx context.Context) error {
return updateContext.UpdateStatus(ctx, cnp, meta.revision, meta.policyImportError)
// We need to deep-copy the CNP object because UpdateStatus modifies it
// to clear the LastAppliedConfiguration key from annotations map.
return updateContext.UpdateStatus(ctx, cnp.DeepCopy(), meta.revision, meta.policyImportError)
},
})

Expand Down