Skip to content

enhancement: implement automated instance lifecycle management and rotation #71

@senomorf

Description

@senomorf

Problem Statement

Oracle Cloud free tier users often reach instance limits (E2: 2/2 instances, A1: 4/4 OCPUs) and need manual intervention to free capacity for new deployments. This creates operational overhead and reduces automation effectiveness.

Proposed Solution

Implement optional automated instance lifecycle management with intelligent rotation capabilities, building upon Issue #64's limit-aware automation.

Key Features

1. Automated Instance Rotation

  • Configurable via environment variable: AUTO_ROTATE_INSTANCES=true/false
  • Age-based rotation: Terminate oldest instances when limits reached
  • Safety checks: Verify instance health and uptime before termination
  • Configurable minimum age: Prevent rotation of recently created instances

2. Instance Lifecycle Management

  • Health monitoring: Check instance status and resource utilization
  • Smart selection: Choose optimal instances for termination based on criteria:
    • Instance age (oldest first)
    • Resource utilization (lowest utilization first)
    • Instance type priority (configurable preferences)
  • Graceful shutdown: Proper instance termination with cleanup

3. Enhanced Configuration Options

# Instance Lifecycle Management
AUTO_ROTATE_INSTANCES=true                    # Enable automatic rotation
INSTANCE_MIN_AGE_HOURS=24                     # Minimum age before rotation eligible
ROTATION_STRATEGY="oldest_first"              # "oldest_first", "least_utilized"
HEALTH_CHECK_ENABLED=true                     # Verify instance health before rotation

Implementation Approach

Phase 1: Core Lifecycle Management

Phase 2: Smart Selection Algorithms

  • Implement multiple rotation strategies (age-based, utilization-based)
  • Add instance health scoring and selection optimization
  • Configurable rotation policies with user preferences
  • Enhanced logging and audit trail for rotation decisions

Phase 3: Advanced Features

  • Backup and snapshot creation before rotation
  • Instance replacement scheduling (create new before terminating old)
  • Multi-region rotation support
  • Integration with external monitoring systems

Benefits

  • Reduced manual intervention: Automatic capacity management
  • Improved automation reliability: Continuous operation without user input
  • Resource optimization: Intelligent instance selection for rotation
  • Operational visibility: Detailed logging and notification of lifecycle events
  • Safety-first approach: Multiple verification steps before any destructive operations

Safety Considerations

  • Opt-in only: Feature disabled by default, requires explicit enablement
  • Comprehensive logging: All rotation decisions and actions logged
  • Rollback capabilities: Ability to recover from rotation issues
  • User notifications: Telegram alerts for all lifecycle management actions
  • Minimum age protection: Prevent accidental rotation of recently created instances

Files to Create/Modify

  • New: scripts/instance-lifecycle.sh - Core lifecycle management functionality
  • Modify: scripts/launch-parallel.sh - Integration with rotation logic
  • Modify: scripts/utils.sh - Additional helper functions for instance management
  • Modify: scripts/notify.sh - Lifecycle management notifications

Success Metrics

  • Automated capacity recovery when limits reached
  • Zero manual intervention required for standard operations
  • Proper instance selection based on configured strategy
  • 100% safety record with no unintended terminations
  • Clear operational visibility through logs and notifications

This enhancement transforms the Oracle Instance Creator from intelligent limit detection to full autonomous lifecycle management, providing a complete hands-off experience for Oracle free tier automation.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions