Skip to content

Commit 7285f39

Browse files
committed
move set logic into handle workload function
Signed-off-by: caijing <caijing.cai@alibaba-inc.com>
1 parent 4525dcf commit 7285f39

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

pkg/webhook/workload/mutating/workload_update_handler.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
107107
oldObj); err != nil {
108108
return admission.Errored(http.StatusBadRequest, err)
109109
}
110-
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
111-
if len(newObjClone.GetUID()) == 0 {
112-
newObjClone.SetUID(oldObj.GetUID())
113-
}
114110
changed, err := h.handleCloneSet(newObjClone, oldObj)
115111
if err != nil {
116112
return admission.Errored(http.StatusBadRequest, err)
@@ -140,10 +136,6 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
140136
oldObj); err != nil {
141137
return admission.Errored(http.StatusBadRequest, err)
142138
}
143-
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
144-
if len(newObjClone.GetUID()) == 0 {
145-
newObjClone.SetUID(oldObj.GetUID())
146-
}
147139
changed, err := h.handleDaemonSet(newObjClone, oldObj)
148140
if err != nil {
149141
return admission.Errored(http.StatusBadRequest, err)
@@ -178,10 +170,6 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
178170
oldObj); err != nil {
179171
return admission.Errored(http.StatusBadRequest, err)
180172
}
181-
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
182-
if len(newObjClone.GetUID()) == 0 {
183-
newObjClone.SetUID(oldObj.GetUID())
184-
}
185173
changed, err := h.handleDeployment(newObjClone, oldObj)
186174
if err != nil {
187175
return admission.Errored(http.StatusBadRequest, err)
@@ -211,10 +199,6 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
211199
oldObj); err != nil {
212200
return admission.Errored(http.StatusBadRequest, err)
213201
}
214-
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
215-
if len(newObjClone.GetUID()) == 0 {
216-
newObjClone.SetUID(oldObj.GetUID())
217-
}
218202
changed, err := h.handleNativeDaemonSet(newObjClone, oldObj)
219203
if err != nil {
220204
return admission.Errored(http.StatusBadRequest, err)
@@ -238,6 +222,11 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
238222
}
239223

240224
func (h *WorkloadHandler) handleDeployment(newObj, oldObj *apps.Deployment) (bool, error) {
225+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
226+
if len(newObj.GetUID()) == 0 {
227+
newObj.SetUID(oldObj.GetUID())
228+
}
229+
241230
// make sure matched Rollout CR always exists
242231
rollout, err := h.fetchMatchedRollout(newObj)
243232
if err != nil {
@@ -360,6 +349,11 @@ func (h *WorkloadHandler) handleCloneSet(newObj, oldObj *kruiseappsv1alpha1.Clon
360349
return false, nil
361350
}
362351

352+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
353+
if len(newObj.GetUID()) == 0 {
354+
newObj.SetUID(oldObj.GetUID())
355+
}
356+
363357
rollout, err := h.fetchMatchedRollout(newObj)
364358
if err != nil {
365359
return false, err
@@ -394,6 +388,11 @@ func (h *WorkloadHandler) handleDaemonSet(newObj, oldObj *kruiseappsv1alpha1.Dae
394388
return false, nil
395389
}
396390

391+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
392+
if len(newObj.GetUID()) == 0 {
393+
newObj.SetUID(oldObj.GetUID())
394+
}
395+
397396
rollout, err := h.fetchMatchedRollout(newObj)
398397
if err != nil {
399398
return false, err
@@ -516,6 +515,11 @@ func (h *WorkloadHandler) handleNativeDaemonSet(newObj, oldObj *apps.DaemonSet)
516515
return false, nil
517516
}
518517

518+
// if the resources is updated by CD tools(like OCM,Karmada), the uid of new object is empty
519+
if len(newObj.GetUID()) == 0 {
520+
newObj.SetUID(oldObj.GetUID())
521+
}
522+
519523
rollout, err := h.fetchMatchedRollout(newObj)
520524
if err != nil {
521525
return false, err

0 commit comments

Comments
 (0)