@@ -99,48 +99,58 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
9999 if err := h .Decoder .Decode (req , newObj ); err != nil {
100100 return admission .Errored (http .StatusBadRequest , err )
101101 }
102+ newObjClone := newObj .DeepCopy ()
102103 oldObj := & kruiseappsv1alpha1.CloneSet {}
103104 if err := h .Decoder .Decode (
104105 admission.Request {AdmissionRequest : admissionv1.AdmissionRequest {Object : req .AdmissionRequest .OldObject }},
105106 oldObj ); err != nil {
106107 return admission .Errored (http .StatusBadRequest , err )
107108 }
108- changed , err := h .handleCloneSet (newObj , oldObj )
109+ changed , err := h .handleCloneSet (newObjClone , oldObj )
109110 if err != nil {
110111 return admission .Errored (http .StatusBadRequest , err )
111112 }
112113 if ! changed {
113114 return admission .Allowed ("" )
114115 }
115- marshalled , err := json .Marshal (newObj )
116+ marshalled , err := json .Marshal (newObjClone )
116117 if err != nil {
117118 return admission .Errored (http .StatusInternalServerError , err )
118119 }
119- return admission .PatchResponseFromRaw (req .AdmissionRequest .Object .Raw , marshalled )
120+ original , err := json .Marshal (newObj )
121+ if err != nil {
122+ return admission .Errored (http .StatusInternalServerError , err )
123+ }
124+ return admission .PatchResponseFromRaw (original , marshalled )
120125 case util .ControllerKruiseKindDS .Kind :
121126 // check daemonset
122127 newObj := & kruiseappsv1alpha1.DaemonSet {}
123128 if err := h .Decoder .Decode (req , newObj ); err != nil {
124129 return admission .Errored (http .StatusBadRequest , err )
125130 }
131+ newObjClone := newObj .DeepCopy ()
126132 oldObj := & kruiseappsv1alpha1.DaemonSet {}
127133 if err := h .Decoder .Decode (
128134 admission.Request {AdmissionRequest : admissionv1.AdmissionRequest {Object : req .AdmissionRequest .OldObject }},
129135 oldObj ); err != nil {
130136 return admission .Errored (http .StatusBadRequest , err )
131137 }
132- changed , err := h .handleDaemonSet (newObj , oldObj )
138+ changed , err := h .handleDaemonSet (newObjClone , oldObj )
133139 if err != nil {
134140 return admission .Errored (http .StatusBadRequest , err )
135141 }
136142 if ! changed {
137143 return admission .Allowed ("" )
138144 }
139- marshalled , err := json .Marshal (newObj )
145+ marshalled , err := json .Marshal (newObjClone )
140146 if err != nil {
141147 return admission .Errored (http .StatusInternalServerError , err )
142148 }
143- return admission .PatchResponseFromRaw (req .AdmissionRequest .Object .Raw , marshalled )
149+ original , err := json .Marshal (newObj )
150+ if err != nil {
151+ return admission .Errored (http .StatusInternalServerError , err )
152+ }
153+ return admission .PatchResponseFromRaw (original , marshalled )
144154 }
145155
146156 // native k8s deloyment
@@ -152,24 +162,29 @@ func (h *WorkloadHandler) Handle(ctx context.Context, req admission.Request) adm
152162 if err := h .Decoder .Decode (req , newObj ); err != nil {
153163 return admission .Errored (http .StatusBadRequest , err )
154164 }
165+ newObjClone := newObj .DeepCopy ()
155166 oldObj := & apps.Deployment {}
156167 if err := h .Decoder .Decode (
157168 admission.Request {AdmissionRequest : admissionv1.AdmissionRequest {Object : req .AdmissionRequest .OldObject }},
158169 oldObj ); err != nil {
159170 return admission .Errored (http .StatusBadRequest , err )
160171 }
161- changed , err := h .handleDeployment (newObj , oldObj )
172+ changed , err := h .handleDeployment (newObjClone , oldObj )
162173 if err != nil {
163174 return admission .Errored (http .StatusBadRequest , err )
164175 }
165176 if ! changed {
166177 return admission .Allowed ("" )
167178 }
168- marshalled , err := json .Marshal (newObj )
179+ marshalled , err := json .Marshal (newObjClone )
180+ if err != nil {
181+ return admission .Errored (http .StatusInternalServerError , err )
182+ }
183+ original , err := json .Marshal (newObj )
169184 if err != nil {
170185 return admission .Errored (http .StatusInternalServerError , err )
171186 }
172- return admission .PatchResponseFromRaw (req . AdmissionRequest . Object . Raw , marshalled )
187+ return admission .PatchResponseFromRaw (original , marshalled )
173188 }
174189 }
175190
0 commit comments