Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a design-document for the controller #181

Merged
merged 15 commits into from
Dec 17, 2024
Merged

Create a design-document for the controller #181

merged 15 commits into from
Dec 17, 2024

Conversation

lllamnyp
Copy link
Collaborator

@lllamnyp lllamnyp commented Apr 18, 2024

Motivation

I started some "R'n'D" (scare quotes intended) for implementing scale up, scale down, self-healing and so on and quickly realized, that the coding of the member add/member remove and similar steps is the more trivial part of the undertaking. The difficult part is coming up with a working algorithm that can correctly deduce the cluster's state and execute the necessary actions at the right time.

To better reason about the controller's algorithm now, and to better develop it going forward, I feel it is important to have good documentation of the current design and the intended next steps, so I started with trying to document the current state of the code.

Results

This document contains a mermaid flowchart that outlines the reconciliation loop. It is better viewed in rendered form.

Going forward, I envision this document to have at least three purposes:

  • Let the developers spot flaws and prompt them to open issues.
  • Act as a more detailed form of documentation for advanced users.
  • Be a blueprint for implementing anything non-trivial.

Summary by CodeRabbit

  • Documentation
    • Updated the design document for the EtcdCluster custom resources with a detailed flowchart illustrating the reconciliation process and lifecycle management within a Kubernetes environment.

@lllamnyp lllamnyp marked this pull request as draft April 18, 2024 21:53
@github-actions github-actions bot added the documentation Improvements or additions to documentation label May 3, 2024
@lllamnyp lllamnyp marked this pull request as ready for review May 9, 2024 07:24
@lllamnyp lllamnyp changed the title Draft: Create a design-document for the controller Create a design-document for the controller May 9, 2024
@kvaps
Copy link
Member

kvaps commented May 14, 2024

Could you please move to design subdirectory into website

@hiddenmarten
Copy link
Member

hiddenmarten commented May 19, 2024

I am a bit confused with this section of flow:
image

I would suggest a bit updated way to control resources in this case:
sts-flow

@hiddenmarten
Copy link
Member

hiddenmarten commented May 19, 2024

Also, I didn't get the purpose of the steps:

  • "Promote any learners."
  • "Ensure StatefulSet with replicas = max member ordinal + 1"

I mean, could you please list cases that we avoid using these checks?

@kvaps
Copy link
Member

kvaps commented Jul 2, 2024

Let's move it into architecture in docs, and we can merge it after v0.3

lllamnyp added a commit that referenced this pull request Aug 12, 2024
This commit includes all changes for feature #181 that have not been split up into small stacked PRs. It should not be merged and will later be undone and split into smaller logical chunks of work.
kvaps pushed a commit that referenced this pull request Aug 15, 2024
…th check procedure (#252)

This is the first PR in a series of [stacked
PRs](https://www.stacking.dev/), aimed ultimately at implementing the
features described in #181 and #207. The next PR in the stack can be
found at #259.
lllamnyp added a commit that referenced this pull request Sep 10, 2024
This commit includes all changes for feature #181 that have not been split up into small stacked PRs. It should not be merged and will later be undone and split into smaller logical chunks of work.
lllamnyp added a commit that referenced this pull request Sep 17, 2024
This commit includes all changes for feature #181 that have not been split up into small stacked PRs. It should not be merged and will later be undone and split into smaller logical chunks of work.
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request updates the docs/DESIGN.md file to provide a detailed explanation of the interaction between EtcdCluster custom resources and Kubernetes primitives. It includes a flowchart that outlines the reconciliation process, starting with service verification and endpoint checks. The document describes various scenarios for managing cluster health, scaling operations, and corrective actions when members are unreachable, serving as a comprehensive guide for lifecycle management within a Kubernetes environment.

Changes

File Change Summary
docs/DESIGN.md Updated to elaborate on the reconciliation flow for EtcdCluster custom resources, including a flowchart detailing service verification, cluster health checks, member management, and scaling operations.

Sequence Diagram

sequenceDiagram
    participant Operator as EtcdCluster Operator
    participant Cluster as Kubernetes Cluster
    participant Service as Etcd Service
    participant StatefulSet as Etcd StatefulSet

    Operator->>Cluster: Check Service Endpoints
    alt Endpoints Exist
        Operator->>Service: Connect and Fetch Status
        Operator->>Cluster: Validate Cluster ID
        Operator->>Cluster: Check Quorum Status
        Operator->>Cluster: Manage Cluster Members
    else No Endpoints
        Operator->>Cluster: Check StatefulSet Existence
        Operator->>Cluster: Create/Reconcile Configuration
    end
Loading

Poem

🐰 In the cluster where bunnies play,
Etcd dances in a graceful way,
With endpoints checked and members aligned,
Kubernetes magic, perfectly designed!
A hop and a skip, the workflow's bright,
Guiding us through the Kubernetes night! 🌙


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

LGTM

@kvaps kvaps enabled auto-merge (squash) December 17, 2024 15:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
docs/DESIGN.md (4)

1-5: Enhance the document introduction for better context and navigation.

Consider expanding the introduction to include:

  • Brief overview of what EtcdCluster is and its purpose
  • Controller's key responsibilities and objectives
  • Table of contents or document structure
  • Prerequisites or assumptions
 # Design

 This document describes the interaction between `EtcdCluster` custom resources and other Kubernetes
 primitives and gives an overview of the underlying implementation.
+
+## Table of Contents
+- [Overview](#overview)
+- [Prerequisites](#prerequisites)
+- [Reconciliation flowchart](#reconciliation-flowchart)
+
+## Overview
+EtcdCluster is a custom resource that manages etcd clusters in Kubernetes. This controller handles:
+- Cluster state management
+- Scaling operations
+- Self-healing mechanisms
+- Member addition and removal
+
+## Prerequisites
+- Understanding of Kubernetes custom resources
+- Familiarity with etcd cluster operations

6-7: Add context to the flowchart section.

The flowchart would be more accessible with:

  • Brief explanation of its purpose
  • Description of key components and their relationships
  • Legend explaining the symbols and color coding (if any)
 ## Reconciliation flowchart
+
+This flowchart illustrates the controller's reconciliation loop, showing how it:
+- Manages cluster state transitions
+- Handles error conditions
+- Performs scaling operations
+
+### Legend
+- Diamond shapes: Decision points
+- Rectangular boxes: Actions
+- Rounded boxes: Terminal states

50-56: Enhance error detection and recovery for unreachable members.

The current flow for unreachable members could be more robust:

  • No timeout specifications
  • Limited diagnostics
  • No progressive recovery steps

Consider adding more detailed diagnostic steps:

          AAA --> |No members\nreached| AAAB{Is the STS\npresent?}
            AAAB --> |Yes| AAABA{"`
-              Does it have the correct pod spec?
+              Diagnostic checks:
+              1. Pod spec validation
+              2. Network connectivity
+              3. DNS resolution
+              4. Certificate validity
+              5. Resource constraints
             `"}

8-73: Consider adding operational metrics and monitoring points.

The flowchart would benefit from indicating key metrics collection points for operational visibility:

  • Reconciliation loop duration
  • Error rates by type
  • State transition latencies
  • Member health metrics

This would help operators monitor the controller's health and performance effectively. Consider adding annotations in the flowchart to indicate metric collection points or creating a separate section documenting the metrics strategy.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca39d30 and ba4a76f.

⛔ Files ignored due to path filters (1)
  • docs/sts-flow.svg is excluded by !**/*.svg
📒 Files selected for processing (1)
  • docs/DESIGN.md (1 hunks)
🔇 Additional comments (1)
docs/DESIGN.md (1)

16-20: Clarify the "Promote any learners" step and its prerequisites.

As noted in the PR comments, the purpose of the "Promote any learners" step needs clarification:

  • When and why are learners promoted?
  • What conditions must be met before promotion?
  • What happens if promotion fails?

Consider adding comments in the flowchart to explain these operations:

                AAAAAA --> |Yes| AAAAAAA["`
-                  Promote any learners.
+                  Promote learners to voting members when:
+                  - Learner is fully synced
+                  - Cluster has quorum
+                  - No other promotions in progress
                   Ensure configmap with initial cluster matching existing members and cluster state=existing.
                   Ensure StatefulSet with replicas = max member ordinal + 1
                `"]

docs/DESIGN.md Outdated Show resolved Hide resolved
@kvaps kvaps disabled auto-merge December 17, 2024 15:20
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@kvaps kvaps enabled auto-merge (squash) December 17, 2024 15:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
docs/DESIGN.md (1)

36-54: 🛠️ Refactor suggestion

Enhance error handling with automated recovery procedures.

Building upon the previous feedback about quorum loss, consider adding:

  • Automated recovery procedures for common failure scenarios
  • Integration with monitoring systems
  • Clear escalation paths for non-recoverable errors
                     AAAAAAAA --> |No| AAAAAAAAB1[On timeout evict member.]
-                      AAAAAAAAB1 --> AAAAAAAAB2[Delete PVC, ensure ConfigMap with\nmembers + this one and delete pod.]
+                      AAAAAAAAB1 --> AAAAAAAAB0{Is error\nrecoverable?}
+                        AAAAAAAAB0 --> |Yes| AAAAAAAAB2["`
+                          1. Record recovery attempt metrics
+                          2. Execute automated recovery:
+                             - Delete PVC
+                             - Update ConfigMap
+                             - Delete pod
+                          3. Monitor recovery success
+                        `"]
+                        AAAAAAAAB0 --> |No| AAAAAAAAB3["`
+                          1. Raise alerts
+                          2. Record failure metrics
+                          3. Update status with error details
+                          4. Escalate to operators
+                        `"]
🧹 Nitpick comments (2)
docs/DESIGN.md (2)

1-5: Enhance the introduction with more context and structure.

Consider expanding the introduction to include:

  • Background context about etcd and its role in Kubernetes
  • Key concepts and terminology used throughout the document
  • Overview of the document's structure and sections
 # Design

 This document describes the interaction between `EtcdCluster` custom resources and other Kubernetes
-primitives and gives an overview of the underlying implementation.
+primitives and gives an overview of the underlying implementation.
+
+## Overview
+
+Etcd is a distributed key-value store that plays a crucial role in Kubernetes by storing cluster state.
+This document outlines the design of a controller that manages etcd clusters within Kubernetes,
+handling operations such as scaling, self-healing, and state management.
+
+### Key Concepts
+
+- **EtcdCluster**: Custom resource defining the desired state of an etcd cluster
+- **StatefulSet**: Kubernetes primitive used to manage the etcd pods
+- **Quorum**: Minimum number of healthy members required for cluster operations
+
+### Document Structure
+
+1. Reconciliation Flowchart: Detailed process flow for cluster management
+2. State Transitions: Various cluster states and their handling
+3. Error Scenarios: Recovery procedures and failure handling

1-81: Consider adding supplementary documentation sections.

To make the design document more comprehensive, consider adding:

  1. High-level architecture overview
  2. Sequence diagrams for key operations (scaling, recovery)
  3. Examples of common scenarios and their handling
  4. Operational guidelines for administrators

Would you like assistance in generating these additional sections?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba4a76f and 8a17155.

📒 Files selected for processing (1)
  • docs/DESIGN.md (1 hunks)

docs/DESIGN.md Show resolved Hide resolved
docs/DESIGN.md Show resolved Hide resolved
docs/DESIGN.md Show resolved Hide resolved
@kvaps kvaps merged commit bfcf533 into main Dec 17, 2024
9 checks passed
@kvaps kvaps deleted the docs/design branch December 17, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants