Files
sealos/.github/workflows/e2e_execution_timeout.yml
T
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

116 lines
3.7 KiB
YAML

name: E2E Execution Timeout Test
on:
workflow_dispatch:
push:
branches: ["**"]
paths:
- ".github/workflows/e2e_execution_timeout.yml"
- "lifecycle/cmd/sealos/cmd/**"
- "lifecycle/pkg/ssh/**"
- "lifecycle/pkg/exec/**"
- "lifecycle/pkg/guest/**"
- "lifecycle/test/e2e/**"
pull_request:
branches: ["*"]
paths:
- ".github/workflows/e2e_execution_timeout.yml"
- "lifecycle/cmd/sealos/cmd/**"
- "lifecycle/pkg/ssh/**"
- "lifecycle/pkg/exec/**"
- "lifecycle/pkg/guest/**"
- "lifecycle/test/e2e/**"
# Avoid using ${{ github.workflow }} - when called via workflow_call, it inherits the caller's name causing conflicts
concurrency:
group: e2e-execution-timeout-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
call_ci_workflow:
uses: ./.github/workflows/import-patch-image.yml
with:
arch: amd64
e2e: true
image: false
e2e-execution-timeout-test:
needs: [call_ci_workflow]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
unit: [
E2E_sealos_execution_timeout_test,
]
steps:
- name: Download image-cri-shim
uses: actions/download-artifact@v4
with:
name: image-cri-shim-amd64
path: /tmp/
- name: Download sealctl
uses: actions/download-artifact@v4
with:
name: sealctl-amd64
path: /tmp/
- name: Download sealos
uses: actions/download-artifact@v4
with:
name: sealos-amd64
path: /tmp/
- name: Download e2e test
uses: actions/download-artifact@v4
with:
name: e2e.test
path: /tmp/
- name: Verify sealos
run: |
sudo chmod a+x /tmp/{sealos,image-cri-shim,sealctl}
sudo mv /tmp/sealos /usr/bin/
sudo sealos version
- name: Remove containerd & docker
uses: labring/sealos-action@v0.0.7
with:
type: prune
- name: Run execution timeout E2E tests with environment variables
env:
UNIT: ${{ matrix.unit }}
SEALOS_EXECUTION_TIMEOUT: 600s
SEALOS_MAX_RETRY: 10
run: |
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo apt-get remove -y moby-engine moby-cli moby-buildx moby-compose
sudo rm -rf /var/run/docker.sock
sudo rm -rf /run/containerd/containerd.sock
sudo chmod a+x /tmp/e2e.test
sudo /tmp/e2e.test --ginkgo.v --ginkgo.focus="$UNIT"
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.unit }}
path: |
/tmp/*.log
/tmp/test-results/
retention-days: 7
- name: Verify environment variable configuration
if: always()
run: |
echo "Verifying timeout configuration via environment variables..."
echo "Testing SEALOS_EXECUTION_TIMEOUT environment variable..."
SEALOS_EXECUTION_TIMEOUT=600s SEALOS_MAX_RETRY=10 sudo sealos env | grep -i "EXECUTION_TIMEOUT" && echo "✓ EXECUTION_TIMEOUT env var is configured" || echo "✗ EXECUTION_TIMEOUT env var not found"
SEALOS_EXECUTION_TIMEOUT=600s SEALOS_MAX_RETRY=10 sudo sealos env | grep -i "MAX_RETRY" && echo "✓ MAX_RETRY env var is configured" || echo "✗ MAX_RETRY env var not found"
echo ""
echo "Environment variables are now used for timeout configuration instead of command-line flags."
echo "Set SEALOS_EXECUTION_TIMEOUT and SEALOS_MAX_RETRY to control execution behavior."