|
| 1 | +# sig-migrate |
| 2 | + |
| 3 | +Subcommand for migrating Kubernetes resources by adding and removing migration annotations. |
| 4 | + |
| 5 | +## Description |
| 6 | + |
| 7 | +The `sig-migrate` command collects all Kubernetes resources (both namespaced and cluster-wide), adds a `d8-migration=<timestamp>` annotation, and then removes annotations with the `d8-migration-` prefix. This is useful for triggering reconciliation in Deckhouse controllers. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +```shell |
| 12 | +d8 tools sig-migrate [flags] |
| 13 | +``` |
| 14 | + |
| 15 | +## Flags |
| 16 | + |
| 17 | +| Flag | Description | Default | |
| 18 | +| -------------- | ---------------------------------------------------------------------------- | ------------------------------------------- | |
| 19 | +| `--retry` | Retry annotation for objects that failed to be processed in the previous run | `false` | |
| 20 | +| `--as` | Specify a Kubernetes service account for kubectl operations (impersonation) | `system:serviceaccount:d8-system:deckhouse` | |
| 21 | +| `--log-level` | Set the log level (INFO, DEBUG, TRACE) | `DEBUG` | |
| 22 | +| `--kubeconfig` | Path to the kubeconfig file to use for CLI requests | `$HOME/.kube/config` or `$KUBECONFIG` | |
| 23 | +| `--context` | The name of the kubeconfig context to use | `kubernetes-admin@kubernetes` | |
| 24 | + |
| 25 | +## Usage Examples |
| 26 | + |
| 27 | +### Basic Usage |
| 28 | + |
| 29 | +Run migration for all resources in the cluster: |
| 30 | + |
| 31 | +```shell |
| 32 | +d8 tools sig-migrate |
| 33 | +``` |
| 34 | + |
| 35 | +### With kubeconfig and context |
| 36 | + |
| 37 | +```shell |
| 38 | +d8 tools sig-migrate --kubeconfig ~/.kube/config --context my-cluster |
| 39 | +``` |
| 40 | + |
| 41 | +### With a different service account |
| 42 | + |
| 43 | +Use a different service account for operations: |
| 44 | + |
| 45 | +```shell |
| 46 | +d8 tools sig-migrate --as system:serviceaccount:my-namespace:my-serviceaccount |
| 47 | +``` |
| 48 | + |
| 49 | +### Retry for failed objects |
| 50 | + |
| 51 | +Retry annotation for objects that failed to be processed in the previous run: |
| 52 | + |
| 53 | +```shell |
| 54 | +d8 tools sig-migrate --retry |
| 55 | +``` |
| 56 | + |
| 57 | +### With verbose logging |
| 58 | + |
| 59 | +Enable verbose logging (TRACE level): |
| 60 | + |
| 61 | +```shell |
| 62 | +d8 tools sig-migrate --log-level TRACE |
| 63 | +``` |
| 64 | + |
| 65 | +### Combined example |
| 66 | + |
| 67 | +```shell |
| 68 | +d8 tools sig-migrate \ |
| 69 | + --kubeconfig ~/.kube/config \ |
| 70 | + --context production \ |
| 71 | + --as system:serviceaccount:d8-system:deckhouse \ |
| 72 | + --log-level DEBUG |
| 73 | +``` |
| 74 | + |
| 75 | +## How It Works |
| 76 | + |
| 77 | +1. **Resource Collection**: The command uses Kubernetes API discovery to automatically discover all available resources (both namespaced and cluster-wide). |
| 78 | + |
| 79 | +2. **Adding Annotation**: For each resource, an annotation `d8-migration=<timestamp>` is added, where `timestamp` is the current time in Unix timestamp format. |
| 80 | + |
| 81 | +3. **Removing Annotations**: After adding the new annotation, all annotations starting with the `d8-migration-` prefix are removed. |
| 82 | + |
| 83 | +4. **Error Handling**: |
| 84 | + - If a resource does not support annotations (MethodNotAllowed), it is added to the list of unsupported types and skipped in the future. |
| 85 | + - If the operation is forbidden for the current service account, the command automatically attempts to use an alternative service account (`system:serviceaccount:d8-multitenancy-manager:multitenancy-manager`). |
| 86 | + - All failed attempts are recorded in `/tmp/failed_annotations.txt` and `/tmp/failed_errors.txt` files for subsequent retry. |
| 87 | + |
| 88 | +## Retry Files |
| 89 | + |
| 90 | +The command creates two files to track failed operations: |
| 91 | + |
| 92 | +- `/tmp/failed_annotations.txt` - list of objects in `namespace|name|kind` format that failed to be processed |
| 93 | +- `/tmp/failed_errors.txt` - detailed error information in `namespace|name|kind|error_message` format |
| 94 | + |
| 95 | +### Automatic Failure Detection |
| 96 | + |
| 97 | +At the end of execution, if any objects failed to be annotated, the command will automatically display a warning message with: |
| 98 | + |
| 99 | +- The number of failed objects |
| 100 | +- Paths to both error log files |
| 101 | +- Instructions on how to investigate and retry |
| 102 | + |
| 103 | +Example output when failures occur: |
| 104 | + |
| 105 | +``` |
| 106 | +⚠️ Migration completed with 5 failed object(s). |
| 107 | +
|
| 108 | +Some objects could not be annotated. Please check the error details: |
| 109 | + Error log file: /tmp/failed_errors.txt |
| 110 | + Failed objects list: /tmp/failed_annotations.txt |
| 111 | +
|
| 112 | +To investigate the issues: |
| 113 | + 1. Review the error log file to understand why objects failed |
| 114 | + 2. Check permissions and resource availability |
| 115 | + 3. Retry migration for failed objects only using: |
| 116 | + d8 tools sig-migrate --retry |
| 117 | +``` |
| 118 | + |
| 119 | +To retry failed objects, use the `--retry` flag: |
| 120 | + |
| 121 | +```shell |
| 122 | +d8 tools sig-migrate --retry |
| 123 | +``` |
| 124 | + |
| 125 | +## Log Levels |
| 126 | + |
| 127 | +- **INFO**: Minimal output, only important messages |
| 128 | +- **DEBUG**: Detailed output with progress information (default) |
| 129 | +- **TRACE**: Maximum verbose output, including all commands and API responses |
| 130 | + |
| 131 | +## Limitations |
| 132 | + |
| 133 | +- Some resource types may not support annotations (e.g., some CRDs). Such types are automatically detected and skipped. |
| 134 | +- The command requires appropriate access rights to annotate resources in the cluster. |
| 135 | +- For large clusters, execution may take a significant amount of time. |
| 136 | + |
| 137 | +## Notes |
| 138 | + |
| 139 | +- The command uses impersonation to perform operations on behalf of the specified service account. |
| 140 | +- All operations are performed sequentially to ensure stability. |
| 141 | +- Execution progress is displayed in real-time with completion percentage. |
| 142 | + |
| 143 | +## See Also |
| 144 | + |
| 145 | +- [d8 tools](https://github.com/deckhouse/deckhouse-cli) - other tools in the tools category |
| 146 | +- [Deckhouse Documentation](https://deckhouse.io/) - Deckhouse Kubernetes Platform documentation |
0 commit comments