Repository: kubernetes
Issue: Schema violations in patches result in empty API status error reason string 
Labels: kind/bug,sig/api-machinery,triage/accepted

### What happened?

A patch was applied using client-go:

```
rawPatch := `
{
  "apiVersion":"apps/v1",
  "kind":"Deployment",
  "metadata":{
    "labels":{
      "app":"metrics-forwarder"
    },
    "name":"metrics-forwarder-deployment-1"
  },
  "spec":{
    "replicas":1,
    "selector":{
      "matchLabels":{
        "app":"metrics-forwarder"
      }
    },
    "template":{
      "metadata":{
        "labels":{
          "app":"metrics-forwarder"
        }
      },
      "spec":{
        "nodeAffinity":{
          "preferredDuringSchedulingIgnoredDuringExecution":[
            {
              "preference":{
                "matchExpressions":[
                  {
                    "key":"XXXXX",
                    "operator":"In",
                    "values":[
                      "true"
                    ]
                  }
                ]
              },
              "weight":50
            }
          ]
        }
      }
    }
  }
}
`

patch := client.RawPatch(types.ApplyPatchType, []byte(rawPatch))
dst := obj.DeepCopyObject().(*unstructured.Unstructured)
err := p.client.Patch(ctx, dst, patch, client.DryRunAll)
```

Please note that the patch contains the key `spec.template.spec.nodeAffinity` while it should correctly be `spec.template.spec.affinity.nodeAffinity` .

`err` returned is of type APIStatus, its `Status()` method returns
```
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"failed to create typed patch object (XXXX/metrics-forwarder-deployment-1; apps/v1, Kind=Deployment): .spec.template.spec.nodeAffinity: field not declared in schema","code":500}
```

Note that the `Reason` field is empty.

### What did you expect to happen?

The reason field of the returned status should not be empty. I personally would have expected `StatusReasonInvalid` or `StatusReasonBadRequest`.

### How can we reproduce it (as minimally and precisely as possible)?

Create and apply a patch that contains key that are not part of the schema of the patched object.

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.3", GitCommit:"25b4e43193bcda6c7328a6d147b1fb73a33f1598", GitTreeState:"archive", BuildDate:"2023-06-15T08:14:06Z", GoVersion:"go1.20.5", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-05-12T19:03:40Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
```

</details>


### Cloud provider

<details>
running locally with kind v0.20.0 go1.20.4 linux/amd64
</details>


### OS version

<details>

```console
# On Linux:
$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
$ uname -a
Linux XXX 6.3.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 20:46:20 +0000 x86_64 GNU/Linux
# paste output here
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>