Repository: kubernetes
Issue: Cannot upgrade APIVersion and add new field at the same time with server-side apply
Labels: kind/bug,sig/api-machinery,triage/accepted

### What happened?

When SSA-ing an object that has been created with an old storage version (i.e. v1alpha1) to the latest storage version (i.e. v1beta1) and adding a new property property that only exists in the new version, the attempt fails with an error.

### What did you expect to happen?

The API server should use the schema of the new version specified in the SSA payload instead of using the old version and upgrade the object and add the new property.

### How can we reproduce it (as minimally and precisely as possible)?

1. Create an empty cluster (we have been using kind for testing)
2. Apply a new CRD with an alpha version:
```yaml
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: examples.example.com
spec:
  group: example.com
  names:
    kind: Example
    listKind: ExampleList
    plural: examples
    singular: example
  scope: Cluster
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              alphaField:
                type: string
```

3. Apply a sample object
```yaml
---
apiVersion: example.com/v1alpha1
kind: Example
metadata:
  name: example
spec:
  alphaField: "test"
```

4. Update the CRD and add a new version `v1beta1` that contains a new field `spec.betaField`.
```yaml
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: examples.example.com
spec:
  group: example.com
  names:
    kind: Example
    listKind: ExampleList
    plural: examples
    singular: example
  scope: Cluster
  versions:
  - name: v1alpha1
    served: true
    storage: false    
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              alphaField:
                type: string
  - name: v1beta1
    served: true
    storage: true    
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              alphaField:
                type: string
              betaField:
                type: string
```

5. Add `betaField` to the object and apply it with `kubectl apply --server-side`
```yaml
---
apiVersion: example.com/v1beta1
kind: Example
metadata:
  name: example
spec:
  alphaField: "test"
  betaField: "test2"
```


Kubectl will fail with an error:

```
Error from server: failed to convert new object: .spec.betaField: field not declared in schema
```

If using CSA `kubectl apply` it works without an issue:
```
example.example.com/example configured
```

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
Client Version: v1.29.2
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.2
```

</details>


### Cloud provider

<details>
n.a. since everything was run locally with Kind.
</details>


### OS version

<details>

```console
$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="39 (Server Edition)"
ID=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
PRETTY_NAME="Fedora Linux 39 (Server Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:39"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=39
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=39
SUPPORT_END=2024-11-12
VARIANT="Server Edition"
VARIANT_ID=server
$ uname -a
Linux localhost.localdomain 6.7.4-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Feb  5 22:21:14 UTC 2024 x86_64 GNU/Linux
```

</details>


### Install tools

<details>
$ kind version
kind v0.22.0 go1.20.13 linux/amd64
</details>


### Container runtime (CRI) and version (if applicable)

<details>
n.a.
</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>
n.a.
</details>