Files
Jiahui 77eda2a732 fix(lifecycle): enable configurable execution timeout for all commands (#6442)
* fix: enable configurable execution timeout for all commands

The ssh.RegisterFlags() function exists to expose execution timeout
configuration, but was never called in the command initialization flow.
This caused all script executions to be subject to a hardcoded 5-minute
timeout that users could not override.

Changes:
- Call ssh.RegisterFlags() in root command initialization
- Make --execution-timeout and --max-retry available as global flags
- Users can now configure timeout via: sealos run --execution-timeout 1h

This fix allows users to run long-running scripts in container images
without hitting the 5-minute timeout limit.

Related to #6441

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* test: add automated tests for execution timeout configuration

This commit adds comprehensive E2E and unit tests to validate the
execution timeout configuration feature (issue #6441).

Changes:
- Add E2E test suite with 6 comprehensive test cases
- Add unit tests for command options (4 test suites)
- Create dedicated GitHub workflow for timeout tests
- Integrate timeout tests into core E2E test matrix

Test Coverage:
- Custom execution timeout for long-running scripts (600s)
- Default timeout behavior verification (300s)
- Unlimited timeout configuration (0)
- Multiple timeout format validation (s, m, h, mixed)
- Apply/Run command integration tests
- Max-retry flag functionality
- SSH + timeout combination scenarios

New Files:
- lifecycle/test/e2e/execution_timeout_test.go
- lifecycle/test/e2e/testhelper/cmd/sealosCmdOpts_timeout_test.go
- .github/workflows/e2e_execution_timeout.yml

Modified Files:
- lifecycle/test/e2e/testhelper/cmd/sealosCmdOpts.go
  - Add ExecutionTimeout and MaxRetry fields to RunOptions
  - Add ExecutionTimeout field to ApplyOptions
  - Update Args() methods to include new flags
- lifecycle/test/e2e/suites/operators/interface.go
  - Add RunWithOpts() and ApplyOpts() to FakeClusterInterface
- lifecycle/test/e2e/suites/operators/cluster.go
  - Implement RunWithOpts() and ApplyOpts() methods
- .github/workflows/e2e_test_core.yml
  - Add E2E_sealos_execution_timeout_test to test matrix

Features:
- Automated CI/CD testing on push/PR
- Manual workflow dispatch support
- Test result artifact uploads
- Timeout flag availability verification

Related to #6441

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: migrate execution timeout from CLI flags to environment variables

Replace command-line flags (--execution-timeout, --max-retry) with global
environment variables (SEALOS_EXECUTION_TIMEOUT, SEALOS_MAX_RETRY) for
consistent configuration management across sealos.

Changes:
- Add EXECUTION_TIMEOUT and MAX_RETRY to sealos env configuration system
- Refactor ssh package to read timeout/retry from system config instead of global vars
- Remove RegisterFlags() function and CLI flag registration from root command
- Update SSH operations (connect, scp) to use GetMaxRetry() and GetExecutionTimeout()
- Support multiple timeout formats: 300s, 5m, 1h, 1h30m, and 0 (unlimited)
- Rewrite E2E tests to use environment variables instead of command flags
- Update GitHub workflow to set environment variables for testing

Usage Changes:
- OLD: sealos run --execution-timeout 1h --max-retry 10 myimage
- NEW: export SEALOS_EXECUTION_TIMEOUT=1h SEALOS_MAX_RETRY=10
       sealos run myimage

This is a breaking change. Users need to migrate from CLI flags to
environment variables. Default values remain unchanged (300s, 5 retries).

Related to #6441

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: correct execution timeout test to use proper cluster images

Replace incorrect container image usage (nginx:alpine) with proper
Sealos cluster images (labring/kubernetes, labring/helm, labring/calico)
in execution timeout tests.

Changes:
- Remove PatchDockerfile and custom image building
- Use standard cluster images directly for timeout testing
- Focus on testing environment variable timeout configuration
- Simplify test cases to validate timeout behavior without complex image setup

Error Fixed:
- "can't apply application type images only since RootFS type image is not applied yet"

The tests now correctly use cluster images that are compatible with Sealos
cluster deployment while validating the SEALOS_EXECUTION_TIMEOUT and
SEALOS_MAX_RETRY environment variable configurations.

Related to #6441

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: separate timeout format validation test to avoid cluster reset failure

Move the timeout format validation test to a separate context that doesn't
require cluster reset. The previous implementation tried to reset a cluster
that was never created, causing AfterEach to fail.

Changes:
- Create separate "timeout format validation" context
- Remove cluster reset from format validation test's AfterEach
- Only clean up environment variables in format validation tests

Error Fixed:
- "failed to reset cluster: exit status 1" in format validation test

This ensures that tests which only validate environment variable formats
don't trigger unnecessary cluster operations.

Related to #6441

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-31 17:00:18 +08:00
..