Skip to content

Commit 1f9016c

Browse files
committed
fix(controllerutil): avoid panic when the MutateFn is nil
1 parent 5dcea7e commit 1f9016c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/controller/controllerutil/controllerutil.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,23 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f M
279279
if !apierrors.IsNotFound(err) {
280280
return OperationResultNone, err
281281
}
282-
if err := mutate(f, key, obj); err != nil {
283-
return OperationResultNone, err
282+
if f != nil {
283+
if err := mutate(f, key, obj); err != nil {
284+
return OperationResultNone, err
285+
}
284286
}
287+
285288
if err := c.Create(ctx, obj); err != nil {
286289
return OperationResultNone, err
287290
}
288291
return OperationResultCreated, nil
289292
}
290293

291294
existing := obj.DeepCopyObject()
292-
if err := mutate(f, key, obj); err != nil {
293-
return OperationResultNone, err
295+
if f != nil {
296+
if err := mutate(f, key, obj); err != nil {
297+
return OperationResultNone, err
298+
}
294299
}
295300

296301
if equality.Semantic.DeepEqual(existing, obj) {

0 commit comments

Comments
 (0)