Skip to content

feat(cozystack-api): Implement hot reload for ApplicationDefinition changes #1960

Open

Description

@kvaps

Summary

Currently, when ApplicationDefinition resources change, cozystack-controller triggers a full restart of the cozystack-api pod by patching the pod template annotation. This causes:

  1. Race condition at startup — if CRD doesn't exist yet, apiserver waits up to 30 minutes
  2. Downtime — full process restart on every CRD change
  3. External dependency — relies on controller to manage apiserver lifecycle

Proposal

Implement hot reload inside apiserver following the pattern from apiextensions-apiserver:

  • apiserver watches ApplicationDefinition directly via controller-runtime informer
  • On changes, atomically updates REST handlers using atomic.Value
  • Updates OpenAPI schema dynamically via OpenAPIVersionedService.UpdateSpec()
  • No process restart required

Implementation outline

  1. Create DynamicResourceHandler with atomic storage for REST handlers
  2. Create HotReloadController that watches CRD and computes diffs
  3. Remove blocking retry loop in Complete() — start with empty config
  4. Remove restart logic from cozystackresource_controller.go

Benefits

  • Zero downtime on CRD changes
  • Faster startup (no waiting for CRD)
  • Simpler architecture (no external restart trigger)
  • Better resilience

Activity

  1. added
    kind/featureCategorizes issue or PR as related to a new feature
    on Feb 2, 2026
  2. github-actions commented on May 2, 2026

    @github-actions

    This issue has had no activity for 60 days and was marked lifecycle/stale.
    It will be closed in 14 days unless commented or labelled lifecycle/frozen.

  3. added
    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale
    on May 2, 2026
  4. dosubot commented on Aug 1, 2026

    @dosubot

    Hi, Andrei Kvapil (@kvaps). I'm Dosu, and I'm helping the cozystack team manage their backlog and am marking this issue as stale.

    Issue Summary

    • You proposed adding hot reload support to cozystack-api so ApplicationDefinition changes can update REST handlers and OpenAPI specs dynamically.
    • The goal is to avoid pod restarts, startup races, and downtime during CRD changes.
    • You also want to reduce dependence on cozystack-controller for managing the API server lifecycle.
    • The only recent activity has been a github-actions stale notice after 60 days of inactivity.

    Next Steps

    • If this is still relevant on the latest version of the cozystack repository, please comment to keep the discussion open.
    • Otherwise, this issue will be automatically closed in 7 days.

    Thanks for your understanding and contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/featureCategorizes issue or PR as related to a new featurelifecycle/staleDenotes an issue or PR has remained open with no activity and has become staletriage/acceptedIndicates an issue is ready to be actively worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions