13 KiB
Upgrade Path Enforcement
Summary
Currently, Longhorn does not enforce the upgrade path, even though we claim Longhorn only supports upgrading from the previous stable release, for example, upgrading to 1.5.x is only supported from 1.4.x or 1.5.0.
Without upgrade enforcement, we will allow users to upgrade from any previous version. This will cause extra testing efforts to cover all upgrade paths. Additionally, the goal of this enhancement is to support rollback after upgrade failure and prevent downgrades.
Related Issues
https://github.com/longhorn/longhorn/issues/5131
Motivation
Goals
- Enforce an upgrade path to prevent users from upgrading from any unsupported version. After rejecting the user's upgrade attempt, the user's Longhorn setup should remain intact without any impacts.
- Upgrade Longhorn from the authorized versions to a major release version.
- Support rollback the failed upgrade to the previous version.
- Prevent unexpected downgrade.
Non-goals
- Automatic rollback if the upgrade failed.
Proposal
- When upgrading with
kubectl
, it will check the upgrade path at entry point of the pods forlonghorn-manager
,longhorn-admission-webhook
,longhorn-conversion-webhook
andlonghorn-recovery-backend
. - When upgrading with
Helm
or as aRancher App Marketplace
, it will check the upgrade path by apre-upgrade
job ofHelm hook
User Stories
- As the admin, I want to upgrade Longhorn from x.y.* or x.(y+1).0 to x.(y+1).* by
kubectl
,Helm
orRancher App Marketplace
, so that the upgrade should succeed. - As the admin, I want to upgrade Longhorn from the previous authorized versions to a new major/minor version by
kubectl
,Helm
, orRancher App Marketplace
, so that the upgrade should succeed. - As the admin, I want to upgrade Longhorn from x.(y-1).* to x.(y+1).* by 'kubectl', 'Helm' or 'Rancher App Marketplace', so that the upgrade should be prevented and the system with the current version continues running w/o any interruptions.
- As the admin, I want to roll back Longhorn from the failed upgrade to the previous install by
kubectl
,Helm
, orRancher App Marketplace
, so that the rollback should succeed. - As the admin, I want to downgrade Longhorn to any lower version by
kubectl
,Helm
, orRancher App Marketplace
, so that the downgrade should be prevented and the system with the current version continues running w/o any interruptions.
User Experience In Detail
Upgrade Longhorn From x.y.* or x.(y+1).0 To x.(y+1).*
Upgrade With kubectl
-
Install Longhorn on any Kubernetes cluster by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.y.*/deploy/longhorn.yaml
or
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.(y+1).0/deploy/longhorn.yaml
-
After Longhorn works normally, upgrade Longhorn by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.(y+1).*/deploy/longhorn.yaml
-
It will be allowed and Longhorn will be upgraded successfully.
Upgrade With Helm
Or Rancher App Marketplace
- Install Longhorn x.y.* or x.(y+1).0 with Helm as Longhorn Install with Helm document or install Longhorn x.y.* or x.(y+1).0 with a Rancher Apps as Longhorn Install as a Rancher Apps & Marketplace document
- Upgrade to Longhorn x.(y+1).* with Helm as Longhorn Upgrade with Helm document or upgrade to Longhorn x.(y+1).* with a Rancher Catalog App as Longhorn Upgrade as a Rancher Apps & Marketplace document
- It will be allowed and Longhorn will be upgraded successfully.
Upgrade Longhorn From The Authorized Versions To A Major Release Version
Upgrade With kubectl
-
Install Longhorn on any Kubernetes cluster by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.y.*/deploy/longhorn.yaml
-
After Longhorn works normally, upgrade Longhorn by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v(x+1).0.*/deploy/longhorn.yaml
-
It will be allowed and Longhorn will be upgraded successfully.
Upgrade With Helm
Or Rancher App Marketplace
- Install Longhorn x.y.* with Helm such as Longhorn Install with Helm document or install Longhorn x.y.* with a Rancher Apps as Longhorn Install as a Rancher Apps & Marketplace document
- Upgrade to Longhorn (x+1).0.* with Helm as Longhorn Upgrade with Helm document or upgrade to Longhorn (x+1).0.* with a Rancher Catalog App as Longhorn Upgrade as a Rancher Apps & Marketplace document
- It will be allowed and Longhorn will be upgraded successfully.
Upgrade Longhorn From x.(y-1).* To x.(y+1).*
Upgrade With kubectl
-
Install Longhorn on any Kubernetes cluster by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.(y-1).*/deploy/longhorn.yaml
-
After Longhorn works normally, upgrade Longhorn by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.(y+1).*/deploy/longhorn.yaml
-
It will be not allowed and Longhorn will block the upgrade for
longhorn-manager
,longhorn-admission-webhook
,longhorn-conversion-webhook
andlonghorn-recovery-backend
. -
Users need to roll back Longhorn manually to restart
longhorn-manager
pods.
Upgrade With Helm
Or Rancher App Marketplace
- Install Longhorn x.(y-1).* with Helm as Longhorn Install with Helm document or install Longhorn x.(y-1).* with a Rancher Apps as Longhorn Install as a Rancher Apps & Marketplace document
- Upgrade to Longhorn x.(y+1).* with Helm as Longhorn Upgrade with Helm document or upgrade to Longhorn x.(y+1).* with a Rancher Catalog App as Longhorn Upgrade as a Rancher Apps & Marketplace document
- It will not be allowed and a
pre-upgrade
job ofHelm hook
failed makes the whole helm upgrading process failed. - Longhorn is intact and continues serving.
Roll Back Longhorn From The Failed Upgrade To The Previous Install
Roll Back With kubectl
-
Users need to recover Longhorn by using this command again:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/[previous installed version]/deploy/longhorn.yaml
-
Longhorn will be rolled back successfully.
-
And users might need to delete new components introduced by new version Longhorn manually.
Roll Back With Helm
Or Rancher App Marketplace
-
Users need to recover Longhorn with
Helm
by using commands:helm history longhorn # to get previous installed Longhorn REVISION helm rollback longhorn [REVISION]
or
helm upgrade longhorn longhorn/longhorn --namespace longhorn-system --version [previous installed version]
-
Users need to recover Longhorn with
Rancher Catalog Apps
by upgrading the previous installed Longhorn version atRancher App Marketplace
again. -
Longhorn will be rolled back successfully.
Manually Cleanup Example
When users try to upgrade Longhorn from v1.3.x to v1.5.x, a new deployment longhorn-recovery-backend
will be introduced and the upgrade will fail.
Users need to delete the deployment longhorn-recovery-backend
manually after rolling back Longhorn
Downgrade Longhorn To Any Lower Version
Downgrade With kubectl
-
Install Longhorn on any Kubernetes cluster by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.y.*/deploy/longhorn.yaml
-
After Longhorn works normally, upgrade Longhorn by using this command:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/vx.(y-z).*/deploy/longhorn.yaml
-
It will be not allowed and Longhorn will block the downgrade for
longhorn-manager
. [orlonghorn-admission-webhook
,longhorn-conversion-webhook
andlonghorn-recovery-backend
if downgrading version had these components] -
Users need to roll back Longhorn manually to restart
longhorn-manager
pods.
Downgrade With Helm
Or Rancher App Marketplace
- Install Longhorn x.y.* with Helm as Longhorn Install with Helm document or install Longhorn x.y.* with a Rancher Apps as Longhorn Install as a Rancher Apps & Marketplace document
- Downgrade to Longhorn (x-z).y.* or x.(y-z).* with Helm as Longhorn Upgrade with Helm document or downgrade to Longhorn (x-z).y.* or x.(y-z).* with a Rancher Catalog App as Longhorn Upgrade as a Rancher Apps & Marketplace document
- It will not be allowed and a
pre-upgrade
job ofHelm hook
failed makes the whole helm downgrading process failed. - Longhorn is intact and continues serving.
API changes
None
Design
Implementation Overview
Blocking Upgrade With kubectl
Check the upgrade path is supported or not at entry point of the longhorn-manager
, longhorn-admission-webhook
, longhorn-conversion-webhook
and longhorn-recovery-backend
- Get Longhorn current version
currentVersion
by the functionGetCurrentLonghornVersion
- Get Longhorn upgrading version
upgradeVersion
frommeta.Version
- Compare currentVersion and upgradeVersion, only allow authorized version upgrade (e.g., 1.3.x to 1.5.x is not allowed) as following table.
currentVersion | upgradeVersion | Allow |
---|---|---|
x.y.* | x.(y+1).* | ✓ |
x.y.0 | x.y.* | ✓ |
x.y.* | (x+1).y.* | ✓ |
x.(y-1).* | x.(y+1).* | X |
x.(y-2).* | x.(y+1).* | X |
x.y.* | x.(y-1).* | X |
x.y.* | x.y.(*-1) | X |
- Downgrade is not allowed.
- When the upgrade path is not supported, new created pods of the
longhorn-manager
,longhorn-admission-webhook
,longhorn-conversion-webhook
andlonghorn-recovery-backend
will show logs and broadcast events for the upgrade path is not supported and return errors. - Previous installed Longhorn will work normally still.
Blocking Upgrade With Helm
Or Rancher App Marketplace
- Add a new job for pre-upgrade hook of
Helm
as thepost-upgrade
job.
apiVersion: batch/v1
kind: Job
metadata:
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
name: longhorn-pre-upgrade
...
spec:
...
template:
metadata:
name: longhorn-pre-upgrade
...
spec:
containers:
- name: longhorn-post-upgrade
...
command:
- longhorn-manager
- pre-upgrade
env:
...
- When upgrading starts, the
pre-upgrade
job will start to run firstly and it will be failed if the upgrade path is not supported thenHelm
upgrading process will be failed.
Test plan
Test Supported Upgrade Path
- Install Longhorn v1.4.x.
- Wait for all pods ready.
- Create a Volume and write some data.
- Upgrade to Longhorn v1.5.0.
- Wait for all pods upgraded successfully.
- Check if data is not corrupted.
Test Unsupported Upgrade Path
- Install Longhorn v1.3.x.
- Wait for all pods ready.
- Create a Volume and write some data.
- Upgrade to Longhorn v1.5.0.
- Upgrading process will be stuck or failed.
- Check if data is not corrupted.
- Rollback to Longhorn v1.3.x with the same setting.
- Longhorn v1.3.x will work normally.
Upgrade strategy
None
Note
None