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

fix: use update instead of patch to set pod's role #8871

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: use update instand of patch to set pod's role
xuriwuyun committed Jan 23, 2025
commit e7b2be5876e9aef92bb666603e915f4b70cc1cd3
14 changes: 7 additions & 7 deletions pkg/controller/instanceset/pod_role_event_handler.go
Original file line number Diff line number Diff line change
@@ -210,22 +210,22 @@ func updatePodRoleLabel(cli client.Client, reqCtx intctrlutil.RequestCtx,
roleName = strings.ToLower(roleName)

// update pod role label
patch := client.MergeFrom(pod.DeepCopy())
newPod := pod.DeepCopy()
role, ok := roleMap[roleName]
switch ok {
case true:
pod.Labels[RoleLabelKey] = role.Name
pod.Labels[AccessModeLabelKey] = string(role.AccessMode)
newPod.Labels[RoleLabelKey] = role.Name
newPod.Labels[AccessModeLabelKey] = string(role.AccessMode)
case false:
delete(pod.Labels, RoleLabelKey)
delete(pod.Labels, AccessModeLabelKey)
delete(newPod.Labels, RoleLabelKey)
delete(newPod.Labels, AccessModeLabelKey)
}

if pod.Annotations == nil {
pod.Annotations = map[string]string{}
}
pod.Annotations[constant.LastRoleSnapshotVersionAnnotationKey] = version
return cli.Patch(ctx, pod, patch, inDataContext())
newPod.Annotations[constant.LastRoleSnapshotVersionAnnotationKey] = version
return cli.Update(ctx, newPod, inDataContext())
}

func inDataContext() *multicluster.ClientOption {