# Packages
No description provided by the author
# README
Selenium Grid Cleaner
A Go utility for automatically cleaning up long-running Selenium Grid sessions in Kubernetes clusters. This tool helps maintain cluster resources by identifying and terminating Selenium Grid pods that have exceeded a specified lifetime.
Features
- Automatic detection and cleanup of long-running Selenium Grid sessions
- Kubernetes integration with support for both in-cluster and external access
- Configurable session lifetime threshold
- Parallel processing of cleanup operations
- Port forwarding support for accessing Selenium Grid
- Detailed logging and error reporting
Prerequisites
- Go 1.19 or later
- Access to a Kubernetes cluster
kubectl
installed and configured- Selenium Grid running in your Kubernetes cluster
Installation
Clone the repository:
git clone https://github.com/maxkulish/selenium-grid-cleaner.git
cd selenium-grid-cleaner
Build the binary:
make build
Configuration
The cleaner can be configured using command-line flags:
Flag | Description | Default Value |
---|---|---|
-context | Kubernetes context to use | Current context |
-port | Selenium Grid port | 4444 |
-namespace | Selenium Grid namespace | selenium |
-service | Selenium Grid service name | selenium-router |
-lifetime | Pod lifetime in hours | 2.0 |
Usage Examples
- Basic usage with default settings:
./bin/selenium-cleaner
- Specify a different namespace and pod lifetime:
./bin/selenium-cleaner -namespace testing -lifetime 1.5
- Use a specific Kubernetes context and custom port:
./bin/selenium-cleaner -context prod-cluster -port 4445
- Full configuration example:
./bin/selenium-cleaner \
-context my-cluster \
-namespace selenium-test \
-service selenium-hub \
-port 4446 \
-lifetime 3.5
You can also use environment variables to configure the application:
export GRID_HOST=selenium-hub.example.com
export GRID_PORT=4444
export NAMESPACE=selenium
export MAX_AGE=7200
make run
Development
Project Structure
├── cmd/
│ └── selenium-cleaner/
│ └── main.go
├── internal/
│ ├── cleaner/
│ ├── downloader/
│ ├── kubernetes/
│ └── portforwarder/
├── Makefile
└── README.md
Available Make Commands
make build
- Build the applicationmake run
- Build and run with default configurationmake test
- Run testsmake coverage
- Generate test coverage reportmake clean
- Clean build artifactsmake deps
- Install dependenciesmake lint
- Run lintermake port-forward
- Set up port forwarding to Selenium Gridmake port-forward-bg
- Set up port forwarding in background
How It Works
- The tool establishes a connection to your Kubernetes cluster
- Sets up port forwarding to access the Selenium Grid service
- Downloads and analyzes the current Grid status
- Identifies sessions that have exceeded the configured lifetime
- Terminates the corresponding pods in parallel
- Waits for confirmation of pod deletion
Error Handling
The cleaner implements comprehensive error handling:
- Validates all configuration parameters
- Implements timeouts for operations
- Provides detailed error messages
- Ensures clean shutdown on interruption
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.