# Process for rolling back CRD versions
This is painful but generally needs to be done in order to ensure the CRD is fully migrated back to a previous version.
> **Warning** Before rolling back the CRD version, you should migrate any CRs using the version you're about to rollback from. Failure to do this will generate errors from the API server such as
>
> ```nohighlight
> Error from server: request to convert CR from an invalid group/version: kustomize.toolkit.fluxcd.io/v1
> ```
>
> If you do not migrate the resources correctly, there is a process at the bottom to achieve this directly in etcd but this process is dangerous and not guaranteed to work.
First: Using the process defined in the Operator Lifecycle Management design doc for [Dependency Resolution](https://github.com/operator-framework/operator-lifecycle-manager/blob/5a5389cb8d831e79acade535d947d4ad4a5c40a7/doc/design/dependency-resolution.md#deprecateremove-a-version-of-crd)
- Edit the CRD you need to change `k edit crd kustomizations.kustomize.toolkit.fluxcd.io`
- Find the version you wish to downgrade from and set `spec.versions[X].served: false` and `spec.versions[X].storage: false`
- Find the version you wish to roll back to, and set `spec.versions[X].served: true` and `spec.versions[X].storage: true`
- Apply the edited CRD
Secondly. You need to remove the version from `status.storedVersions`. To achieve this, I used the script from this comment: [https://github.com/elastic/cloud-on-k8s/issues/2196#issuecomment-1672185523](https://github.com/elastic/cloud-on-k8s/issues/2196#issuecomment-1672185523) however patching may also work: `k patch --subresource=status --type=json crd receivers.notification.toolkit.fluxcd.io -p '[{ "op": "remove", "path": "/status/storedVersions/2" }]'`
> **Note** If you're using the golang script, and it complaions about OIDC, add the following to the imports and rebuild:
>
> ```golang
> _ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
> ```
Within the script, change the list of CRDs to the ones you want to roll back
## I forgot to migrate my resources
You're gonna need to go to `etcd` and this is painful and dangerous. Prefer you don't do it.
If you must, then you need read/write permissions to the database
For each CR you forgot to migrate, run the following example
```bash
CR=<CR_NAME> etcdctl get --print-value-only \
/giantswarm.io/kustomize.toolkit.fluxcd.io/kustomizations/flux-giantswarm/$CR \
| jq '.apiVersion = "kustomize.toolkit.fluxcd.io/v1beta2"' \
| etcdctl put /giantswarm.io/kustomize.toolkit.fluxcd.io/kustomizations/flux-giantswarm/$CR
```