Skip to content

Enhanced Sleep Scheduling – Enable/Disable, StatefulSets, CronJobs, and On-Demand Support#1

Open
to4kin wants to merge 62 commits into
col:mainfrom
chirpwireless:feature/sts_jobs
Open

Enhanced Sleep Scheduling – Enable/Disable, StatefulSets, CronJobs, and On-Demand Support#1
to4kin wants to merge 62 commits into
col:mainfrom
chirpwireless:feature/sts_jobs

Conversation

@to4kin
Copy link
Copy Markdown

@to4kin to4kin commented May 8, 2025

This PR significantly extends the sleep scheduling capabilities of Drowzee. It introduces robust enable/disable toggling, adds full support for statefulsets and cronjobs, and allows for "on-demand" schedules where only sleepTime is set (no wakeTime), suitable for permanent or manual wake scenarios.

Key Features & Changes

  1. CRD Schema Improvements
  • Added enabled as a boolean to the CRD schema, ensuring type safety and proper persistence in Kubernetes.
  • Updated documentation and printer columns to reflect the new field.
  • Now supports schedules with only sleepTime (no wakeTime), enabling permanent scale-down for on-demand instances.
  1. StatefulSets & CronJobs Support
  • Sleep schedules now manage not just Deployments, but also StatefulSets and CronJobs.
  • When a schedule triggers, all listed Deployments, StatefulSets, and CronJobs are handled according to the schedule state (sleep/wake).
  • Includes logic for suspending/resuming cronjobs and scaling statefulsets up/down.
  1. Enable/Disable Functionality
  • Users can enable or disable individual sleep schedules from the UI.
  • The enabled state is persisted in the CRD as a boolean and respected by the controller logic.
  • Robust error handling and feedback in both the backend and UI.
  1. On-Demand Sleep Schedules
  • It is now possible to create a sleep schedule with only a sleepTime (no wakeTime), causing resources to remain scaled down until manually woken.
  • Useful for non-prod or on-demand environments that should remain off by default.
  1. UI and UX Improvements
  • The LiveView UI displays and allows toggling of the enabled state.
  • Schedules with no wakeTime are clearly indicated as "permanent down" or on-demand.
  1. Controller and Backend Enhancements
  • Controller logic updated to handle the new fields and resource types.
  • Improved event handling, error reporting, and resource version management.
  1. CI/CD and Helm Chart Updates
  • Chart versioning logic improved for branch-based builds.
  • CRD and chart files updated to reflect new schema and capabilities.
  • CI workflows and templates improved for maintainability.
  1. Optimize performance of the Drowzee Web UI
  • Lazy Loading of Resource Status:

    • The status for Deployments, StatefulSets, and CronJobs is now fetched only when a user navigates to an individual schedule detail page.
    • On the main page and namespace overview, only the configured resource names are shown, significantly reducing unnecessary API calls and page load times.
  • UI Adjustments:

    • Status indicators (e.g., running/sleeping icons) for resources are only displayed on the schedule detail page.
    • The list pages remain fast and responsive, even with a large number of schedules.
  • Code Structure:

    • The backend logic in index.ex and frontend rendering in index.html.heex have been updated to support this behavior.
    • Assigns for resource statuses are only populated when needed, reducing memory and compute overhead.
  1. Enhance Navigation with Cloud-Shaped Table of Contents
  • Innovative UI Design:

    • Created a new cloud-shaped floating Table of Contents from scratch to improve navigation between sleep schedules.
    • Positioned the ToC on the left side with the main content centered for better visual balance and focus.
    • Added cloud-like visual elements using rounded white circles with opacity for a softer, more modern appearance.
  • Enhanced User Experience:

    • Implemented black/gray link colors for better visual harmony with the overall design aesthetic.
    • Made the ToC sticky on desktop so it stays visible while scrolling through multiple schedule entries.
    • Added subtle hover effects and scale transitions for better interactivity and visual feedback.
  • Responsive Implementation:

    • Improved mobile experience with a toggle button that shows/hides the ToC without taking up permanent screen space.
    • Ensured proper responsiveness across all device sizes with tailored layouts for desktop and mobile views.
    • Implemented auto-closing behavior for mobile after selection to maximize content viewing area.

Bug Fixes

  1. Fix Namespace Handling for Cluster-Wide Mode
  • Issue Resolution:

    • Fixed critical error when using BONNY_POD_NAMESPACE="__ALL__" for cluster-wide monitoring.
    • Resolved function clause error in String.split(:all, ",", []) that occurred because Bonny.Config.namespace() returns the atom :all instead of a string.
    • Implemented proper type handling to ensure compatibility with both atom and string namespace formats.

Migration & Compatibility

CRD Upgrade Required

After merging, run:

kubectl apply -f chart/crds/sleepschedule.yaml

to ensure the cluster uses the new schema.

Testing

Manual and automated tests confirm correct behavior for:

  • Enabling/disabling schedules
  • Managing deployments, statefulsets, and cronjobs
  • On-demand (sleep-only) schedules
  • UI tested for correct state reflection and error feedback.

Reviewer Notes

Please review the CRD changes, controller logic, and UI for any edge cases.
Special attention to on-demand schedule handling and resource type coverage (deployments, statefulsets, cronjobs).

@col
Copy link
Copy Markdown
Owner

col commented May 8, 2025

Hey @to4kin - Thanks for the contribution! Look like you've added some really great features!
The PR is pretty big so it'll take me some time to review it properly. I'm traveling next week so it may not be until the following week.

@to4kin
Copy link
Copy Markdown
Author

to4kin commented May 8, 2025

Hi @col No problem. We actually spent a couple of days to find a good tool to scale our dp/sts/cj on non-prod clusters. And your tool is closer to our needs. So we decided to fork it and add some cool features :) I also updated workflow to be able to try a new version, so if you want to keep yours, that's fine with me.

PR is in draft because we are still testing and will probably add some more improvements :)

@col
Copy link
Copy Markdown
Owner

col commented May 8, 2025

If you're still adding features it would be great if you could split them into different branches / PRs. It's pretty hard to manage such a large PR with multiple features particularly if I decide not to merge everything you've done.

@col col requested a review from Copilot May 9, 2025 02:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request significantly extends the sleep scheduling capabilities of Drowzee by introducing an enable/disable toggle, on-demand schedules, and support for additional resource types (StatefulSets and CronJobs) along with various UI/UX and backend improvements.

  • CRD schema improvements including a new boolean field for enabling schedules and support for sleep-only schedules
  • Added functionality to manage StatefulSets and CronJobs in addition to Deployments
  • Enhanced controller logic, logging, and CI/CD improvements for better reliability and performance

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/drowzee/k8s/statefuleset.ex Introduces StatefulSet support (note file naming may be inconsistent)
lib/drowzee/k8s/sleep_schedule.ex Adds functions to handle StatefulSets and CronJobs for sleep schedules
lib/drowzee/k8s/deployment.ex Refactors deployment handling with improved logging and replica management
lib/drowzee/k8s/cronjob.ex Implements CronJob suspension/resumption functionality
lib/drowzee/k8s.ex Adds helper functions to fetch StatefulSets and CronJobs
lib/drowzee/controllers/sleep_schedule_controller.ex Updates controller logic to account for the enabled state and new resource types
lib/drowzee/config.ex Improves namespace handling for cluster-wide configurations
config/config.exs Updates logging metadata for clearer observability
chart/* Updates CRD schema and Helm chart configuration for new features
.github/* Adds CI/CD workflows, pull request template, and dependency configurations for improved project maintenance
Comments suppressed due to low confidence (2)

lib/drowzee/k8s/statefuleset.ex:1

  • The file name 'statefuleset.ex' appears to have a typo; consider renaming it to 'statefulset.ex' to align with the module name and maintain consistency.
defmodule Drowzee.K8s.StatefulSet do

chart/Chart.yaml:24

  • The appVersion has been decreased from '0.1.8' to '0.1.0', which may be unintended and could lead to versioning confusion; please verify the correct version number.
appVersion: "0.1.0"

@to4kin
Copy link
Copy Markdown
Author

to4kin commented May 9, 2025

Got it. We're actually done for now. We will continue testing and will probably only add bug fixes. New features will be added with the new PR

@to4kin to4kin marked this pull request as ready for review May 9, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants