Skip to content

Commit

Permalink
fix(controllerutil): avoid panic when the MutateFn is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
0xff-dev committed May 14, 2024
1 parent 5dcea7e commit 1f9016c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/controller/controllerutil/controllerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,23 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f M
if !apierrors.IsNotFound(err) {
return OperationResultNone, err
}
if err := mutate(f, key, obj); err != nil {
return OperationResultNone, err
if f != nil {
if err := mutate(f, key, obj); err != nil {
return OperationResultNone, err
}
}

if err := c.Create(ctx, obj); err != nil {
return OperationResultNone, err
}
return OperationResultCreated, nil
}

existing := obj.DeepCopyObject()
if err := mutate(f, key, obj); err != nil {
return OperationResultNone, err
if f != nil {
if err := mutate(f, key, obj); err != nil {
return OperationResultNone, err
}
}

if equality.Semantic.DeepEqual(existing, obj) {
Expand Down

0 comments on commit 1f9016c

Please sign in to comment.