Skip to content

Commit e6a37e3

Browse files
ivan-caizmberg
authored andcommitted
the UID of new object is empty, and set the UID of old object to new object, while using some CD tools(like OCM,Karmada) to update workload (#319)
move set logic into handle workload function Signed-off-by: caijing <caijing.cai@alibaba-inc.com>
1 parent 2e34e48 commit e6a37e3

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

pkg/webhook/workload/mutating/workload_update_handler.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
193193
}
194194

195195
func (h *WorkloadHandler) handleDeployment(newObj, oldObj *apps.Deployment) (bool, error) {
196+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
197+
if len(newObj.GetUID()) == 0 {
198+
newObj.SetUID(oldObj.GetUID())
199+
}
200+
201+
// make sure matched Rollout CR always exists
202+
rollout, err := h.fetchMatchedRollout(newObj)
203+
if err != nil {
204+
return false, err
205+
} else if rollout == nil || rollout.Spec.Strategy.IsEmptyRelease() {
206+
return false, nil
207+
}
208+
196209
// in rollout progressing
197210
if newObj.Annotations[util.InRolloutProgressingAnnotation] != "" {
198211
modified := false
@@ -257,12 +270,6 @@ func (h *WorkloadHandler) handleDeployment(newObj, oldObj *apps.Deployment) (boo
257270
return false, nil
258271
}
259272

260-
rollout, err := h.fetchMatchedRollout(newObj)
261-
if err != nil {
262-
return false, err
263-
} else if rollout == nil || rollout.Spec.Strategy.IsEmptyRelease() {
264-
return false, nil
265-
}
266273
rss, err := h.Finder.GetReplicaSetsForDeployment(newObj)
267274
if err != nil || len(rss) == 0 {
268275
klog.Warningf("Cannot find any activate replicaset for deployment %s/%s, no need to rolling", newObj.Namespace, newObj.Name)
@@ -313,6 +320,11 @@ func (h *WorkloadHandler) handleCloneSet(newObj, oldObj *kruiseappsv1alpha1.Clon
313320
return false, nil
314321
}
315322

323+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
324+
if len(newObj.GetUID()) == 0 {
325+
newObj.SetUID(oldObj.GetUID())
326+
}
327+
316328
rollout, err := h.fetchMatchedRollout(newObj)
317329
if err != nil {
318330
return false, err
@@ -347,6 +359,11 @@ func (h *WorkloadHandler) handleDaemonSet(newObj, oldObj *kruiseappsv1alpha1.Dae
347359
return false, nil
348360
}
349361

362+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
363+
if len(newObj.GetUID()) == 0 {
364+
newObj.SetUID(oldObj.GetUID())
365+
}
366+
350367
rollout, err := h.fetchMatchedRollout(newObj)
351368
if err != nil {
352369
return false, err

0 commit comments

Comments
 (0)