Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/tools/sigmigrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ d8 tools sig-migrate \
5. **Error Handling**:
- If a resource does not support annotations (MethodNotAllowed), it is added to the list of unsupported types and skipped in the future.
- 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`).
- Each run writes failed/skipped artifacts to run-scoped files in `/tmp` with a timestamp suffix (for example: `/tmp/failed_annotations_20260414T151625Z.txt`, `/tmp/failed_errors_20260414T151625Z.txt`, `/tmp/skipped_objects_20260414T151625Z.txt`).
- For backward-compatible retry UX, the latest failed annotations are also synced to legacy `/tmp/failed_annotations.txt`, so `--retry` continues to work without extra arguments.
- Each run writes failed/skipped artifacts to run-scoped files in `/tmp` with a timestamp suffix (for example: `/tmp/failed_annotations_20260414T151625Z.log`, `/tmp/failed_errors_20260414T151625Z.log`, `/tmp/skipped_objects_20260414T151625Z.log`).
- For backward-compatible retry UX, the latest failed annotations are also synced to legacy `/tmp/failed_annotations.log`, so `--retry` continues to work without extra arguments.
- A dedicated trace debug log is written to `/tmp/sigmigrate_trace_<timestamp>.log` with detailed execution/error diagnostics.

## Retry Files

The command creates run-scoped files to track failed operations:

- `/tmp/failed_annotations_<timestamp>.txt` - list of objects in `namespace|name|kind|group|version` format that failed to be processed
- `/tmp/failed_errors_<timestamp>.txt` - detailed error information in `namespace|name|kind|error_message` format
- `/tmp/skipped_objects_<timestamp>.txt` - skipped objects with reason/details
- `/tmp/failed_annotations_<timestamp>.log` - list of objects in `namespace|name|kind|group|version` format that failed to be processed
- `/tmp/failed_errors_<timestamp>.log` - detailed error information in `namespace|name|kind|error_message` format
- `/tmp/skipped_objects_<timestamp>.log` - skipped objects with reason/details

For retry compatibility, failed annotations are also mirrored into legacy `/tmp/failed_annotations.txt` and `--retry` reads from that legacy file (supports both old `namespace|name|kind` and new `namespace|name|kind|group|version` lines).
For retry compatibility, failed annotations are also mirrored into legacy `/tmp/failed_annotations.log` and `--retry` reads from that legacy file (supports both old `namespace|name|kind` and new `namespace|name|kind|group|version` lines).

### Automatic Failure Detection

Expand All @@ -128,8 +128,8 @@ Example output when failures occur:
⚠️ Migration completed with 5 failed object(s).

Some objects could not be annotated. Please check the error details:
Error log file: /tmp/failed_errors_<timestamp>.txt
Failed objects list: /tmp/failed_annotations_<timestamp>.txt
Error log file: /tmp/failed_errors_<timestamp>.log
Failed objects list: /tmp/failed_annotations_<timestamp>.log
Trace log file: /tmp/sigmigrate_trace_<timestamp>.log

To investigate the issues:
Expand Down
20 changes: 19 additions & 1 deletion internal/tools/sigmigrate/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import (
"os"

"github.com/spf13/pflag"

"github.com/deckhouse/deckhouse-cli/internal/tools/sigmigrate"
)

const (
defaultKubectlAs = "system:serviceaccount:d8-system:deckhouse"
)
Comment thread
Suselz marked this conversation as resolved.
Comment thread
Suselz marked this conversation as resolved.

func addFlags(flags *pflag.FlagSet) {
Expand All @@ -31,7 +37,7 @@ func addFlags(flags *pflag.FlagSet) {

flags.String(
"as",
"system:serviceaccount:d8-system:deckhouse",
defaultKubectlAs,
"Specify a Kubernetes service account for the kubectl operations (impersonation).",
)

Expand Down Expand Up @@ -63,4 +69,16 @@ func addFlags(flags *pflag.FlagSet) {
"",
"Process objects by identifier in format <namespace>/<name>/<resource_name>. Use 'clusterwide' namespace for cluster-scoped resources. Resource name must match kubectl api-resources output.",
)

flags.Int(
"threads",
sigmigrate.DefaultWorkerCount,
"Number of worker threads for resource discovery and migration. Values <=0 use default.",
)

flags.Bool(
"measure-stages",
false,
"Print execution time for major migration stages.",
)
}
43 changes: 43 additions & 0 deletions internal/tools/sigmigrate/cmd/flags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"testing"

"github.com/deckhouse/deckhouse-cli/internal/tools/sigmigrate"
"github.com/spf13/pflag"
"github.com/stretchr/testify/require"
)

func TestAddFlags_DefaultThreadsMatchesCoreConstant(t *testing.T) {
flags := pflag.NewFlagSet("sig-migrate", pflag.ContinueOnError)
addFlags(flags)

threads, err := flags.GetInt("threads")
require.NoError(t, err)
require.Equal(t, sigmigrate.DefaultWorkerCount, threads)
}

func TestAddFlags_DefaultLogLevel(t *testing.T) {
flags := pflag.NewFlagSet("sig-migrate", pflag.ContinueOnError)
addFlags(flags)

logLevel, err := flags.GetString("log-level")
require.NoError(t, err)
require.Equal(t, "DEBUG", logLevel)
}
Loading
Loading