Skip to content

Commit

Permalink
Set Elem() value if data is of pointer type (#536)
Browse files Browse the repository at this point in the history
Signed-off-by: Masudur Rahman <masud@appscode.com>
  • Loading branch information
masudur-rahman authored Jul 12, 2023
1 parent 4f1c62e commit aba17ce
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, tran
if err != nil {
return kutil.VerbUnchanged, err
}
reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(mod))

setValue(mod, obj)
return kutil.VerbCreated, err
} else if err != nil {
return kutil.VerbUnchanged, err
Expand All @@ -114,10 +115,19 @@ func CreateOrPatch(ctx context.Context, c client.Client, obj client.Object, tran
if err != nil {
return kutil.VerbUnchanged, err
}
reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(mod))

setValue(mod, obj)
return kutil.VerbPatched, nil
}

func setValue(src, target any) {
srcValue := reflect.ValueOf(src)
if srcValue.Kind() == reflect.Pointer {
srcValue = srcValue.Elem()
}
reflect.ValueOf(target).Elem().Set(srcValue)
}

func PatchStatus(ctx context.Context, c client.Client, obj client.Object, transform TransformStatusFunc, opts ...client.PatchOption) (client.Object, kutil.VerbType, error) {
key := types.NamespacedName{
Namespace: obj.GetNamespace(),
Expand Down

0 comments on commit aba17ce

Please sign in to comment.