// Module included in the following assemblies:
// * edge_computing/image-based-upgrade/ztp-image-based-upgrade.adoc

:_mod-docs-content-type: PROCEDURE
[id="ztp-image-based-upgrade-rollback_{context}"]
= Moving to the Rollback stage of the image-based upgrade with {lcao} and {ztp}

If you encounter an issue after upgrade, you can start a manual rollback.

.Prerequisites

* Ensure that the control plane certificates on the original stateroot are valid. If the certificates expired, see "Recovering from expired control plane certificates".

.Procedure

. Revert the `du-profile` or the corresponding policy-binding label to the original platform version in the `ClusterInstance` CR:
+
[source,yaml]
----
apiVersion: siteconfig.open-cluster-management.io/v1alpha1
kind: ClusterInstance
metadata:
  name: "example-sno"
  namespace: "example-sno"
spec:
  # ...
  extraLabels:
    ManagedCluster:
      du-profile: "4.14.x"
----

. When you are ready to initiate the rollback, add the `Rollback` policy to your existing group `PolicyGenTemplate` CR:
+
[source,yaml]
----
[...]
- fileName: ibu/ImageBasedUpgrade.yaml
  policyName: "rollback-stage-policy"
  spec:
    stage: Rollback
  status:
    conditions:
      - message: Rollback completed
        reason: Completed
        status: "True"
        type: RollbackCompleted
----

. Create a `ClusterGroupUpgrade` CR on target hub cluster that references the `Rollback` policy:
+
[source,yaml]
----
apiVersion: ran.openshift.io/v1alpha1
kind: ClusterGroupUpgrade
metadata:
  name: cgu-ibu-rollback
  namespace: default
spec:
  actions:
    beforeEnable:
      removeClusterAnnotations:
      - import.open-cluster-management.io/disable-auto-import
  clusters: 
  - spoke1
  enable: true
  managedPolicies: 
  - example-group-ibu-rollback-stage-policy
  remediationStrategy: 
    canaries: 
      - spoke1
    maxConcurrency: 1 
    timeout: 240
----

. Apply the `Rollback` policy by running the following command:
+
[source,terminal]
----
$ oc apply -f cgu-ibu-rollback.yml
----

. When you are satisfied with the changes and you are ready to finalize the rollback, create a `ClusterGroupUpgrade` CR on target hub cluster that references the policy that finalizes the rollback:
+
[source,yaml]
----
apiVersion: ran.openshift.io/v1alpha1
kind: ClusterGroupUpgrade
metadata:
  name: cgu-ibu-finalize
  namespace: default
spec:
  actions:
    beforeEnable:
      removeClusterAnnotations:
      - import.open-cluster-management.io/disable-auto-import
  clusters: 
  - spoke1
  enable: true
  managedPolicies: 
  - example-group-ibu-finalize-stage-policy
  remediationStrategy: 
    canaries:
      - spoke1
    maxConcurrency: 1 
    timeout: 240
----

. Apply the policy by running the following command:
+
[source,terminal]
----
$ oc apply -f cgu-ibu-finalize.yml
----