|
| 1 | +# Migrating from Versioned to Unversioned Workers |
| 2 | + |
| 3 | +This guide walks you through reverting from versioned workers to unversioned workers. It assumes you have enabled worker versioning and currently have (or previously had) versioned workers polling the Temporal Server. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Important Note |
| 8 | + |
| 9 | +This guide uses specific terminology that is defined in the [Concepts](concepts.md) document. Please review the concepts document first to understand key terms like **Temporal Worker Deployment**, **`TemporalWorkerDeployment` CRD**, and **Kubernetes `Deployment`**, as well as the relationship between them. |
| 10 | + |
| 11 | +## Table of Contents |
| 12 | + |
| 13 | +- [Prerequisites](#prerequisites) |
| 14 | +- [Migration Steps](#migration-steps) |
| 15 | + - [Step 1: Update Worker Code](#step-1-update-worker-code) |
| 16 | + - [Step 2: Deploy the Unversioned Worker](#step-2-deploy-the-unversioned-worker) |
| 17 | + - [Step 3: Set Current Version to Unversioned](#step-3-set-current-version-to-unversioned) |
| 18 | +- [Monitoring the Migration](#monitoring-the-migration) |
| 19 | +- [Cleanup and Garbage Collection](#cleanup-and-garbage-collection) |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +Before starting the migration, ensure you have: |
| 26 | + |
| 27 | +- ✅ **Temporal CLI** version >= 1.5.0 |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Migration Steps |
| 32 | + |
| 33 | +### Step 1: Update Worker Code |
| 34 | + |
| 35 | +Update your worker initialization code to remove versioning configuration. |
| 36 | + |
| 37 | +**Before (Versioned):** |
| 38 | + |
| 39 | +```go |
| 40 | +// Worker must use the build ID and deployment name from environment variables. |
| 41 | +// These are set on the deployment by the controller. |
| 42 | +buildID := os.Getenv("TEMPORAL_WORKER_BUILD_ID") |
| 43 | +deploymentName := os.Getenv("TEMPORAL_DEPLOYMENT_NAME") |
| 44 | +if buildID == "" || deploymentName == "" { |
| 45 | + // exit with an error |
| 46 | +} |
| 47 | + |
| 48 | +workerOptions := worker.Options{ |
| 49 | + DeploymentOptions: worker.DeploymentOptions{ |
| 50 | + UseVersioning: true, |
| 51 | + Version: worker.WorkerDeploymentVersion{ |
| 52 | + DeploymentName: deploymentName, |
| 53 | + BuildID: buildID, |
| 54 | + }, |
| 55 | + }, |
| 56 | +} |
| 57 | +worker := worker.New(client, "my-task-queue", workerOptions) |
| 58 | +``` |
| 59 | + |
| 60 | +**After (Unversioned):** |
| 61 | + |
| 62 | +```go |
| 63 | +// Worker connects without versioning |
| 64 | +worker := worker.New(client, "my-task-queue", worker.Options{}) |
| 65 | +``` |
| 66 | + |
| 67 | +### Step 2: Deploy the Unversioned Worker |
| 68 | + |
| 69 | +Deploy your unversioned workers as you would without the Worker Controller (ie. as their own `Deployments` not connected to a `TemporalWorkerDeployment` resource) and ensure they are polling all of the Task Queues in your Worker Deployment. This can be done by verifying their presence on the Task Queues page (https://cloud.temporal.io/namespaces/<your-namespace>/task-queues/<your-task-queue>) |
| 70 | + |
| 71 | +### Step 3: Set Current Version to Unversioned |
| 72 | + |
| 73 | +Run the following Temporal CLI command to set the current version of the Worker Deployment to *unversioned*: |
| 74 | + |
| 75 | +```bash |
| 76 | +temporal worker deployment set-current-version \ |
| 77 | + --deployment-name <your-deployment-name> \ |
| 78 | + --build-id "" |
| 79 | +``` |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Monitoring the Migration |
| 84 | + |
| 85 | +After completing the migration steps: |
| 86 | + |
| 87 | +1. **Verify in the Temporal UI** that traffic is shifting from versioned workers to unversioned workers. |
| 88 | +2. **AutoUpgrade workflows** will eventually move onto the unversioned worker(s). |
| 89 | +3. **Pinned workflows** that were started on versioned workers will continue and complete execution on those pinned workers. |
| 90 | +4. **New executions** of workflows on Task Queues in your now-unversioned Worker Deployment will start on the unversioned workers, regardless of them being *Pinned* or *AutoUpgrade* |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Cleaning up of Temporal Resources |
| 95 | + |
| 96 | +**NOTE**: The cleanup steps below are optional as it is not required to clean up the Worker Versions or Worker Deployment resources from the Temporal Server while migrating to unversioned workers. |
| 97 | + |
| 98 | +### Deleting Kubernetes Deployments created with the Worker-Controller: |
| 99 | + |
| 100 | +The Worker Controller will delete Kubernetes Deployments, which represent versioned workers, based on your configured Sunset Strategy. Specifically, the Controller deletes Kubernetes Deployments for a version once the time since it became drained exceeds the combined `Scaledown` and `Delete` delay. Deleting these deployments stops the workers from polling the Temporal Server, which is a pre-requisite for deleting a Worker Version. |
| 101 | + |
| 102 | +### Deleting Worker Versions |
| 103 | + |
| 104 | +A Worker Version can be deleted once it has been drained and has no active pollers. |
| 105 | +Once it's drained and is without active pollers, delete the Worker Version using: |
| 106 | + |
| 107 | +```bash |
| 108 | +temporal worker deployment delete-version \ |
| 109 | + --deployment-name <your-deployment-name> \ |
| 110 | + --build-id <your-build-id> |
| 111 | +``` |
| 112 | + |
| 113 | +### Deleting the Worker Deployment |
| 114 | + |
| 115 | +To delete a Worker Deployment: |
| 116 | + |
| 117 | +1. First, ensure all its Worker Versions have been deleted. |
| 118 | +2. Then run: |
| 119 | + |
| 120 | +```bash |
| 121 | +temporal worker deployment delete --name <your-deployment-name> |
| 122 | +``` |
0 commit comments