Skip to content

Instantly share code, notes, and snippets.

@hexfusion
Last active September 24, 2024 20:04
Show Gist options
  • Save hexfusion/29f76f59d051bfa6dae41b2435e2e625 to your computer and use it in GitHub Desktop.
Save hexfusion/29f76f59d051bfa6dae41b2435e2e625 to your computer and use it in GitHub Desktop.
flightctl agent update flow
flowchart TD
    %% Define Vars
    MANAGEMENT_API[Query Mgt API]
    WRITE_DESIRED[Write to desired.json]
    RECONCILE_LOOP[Reconcile Loop]
    UPDATE_CURRENT[Desired -> Current Spec]
    RECONCILE_NEW[New --> Desired Spec]

    PRECHECK1[Ensure Dependencies Met]
    PRECHECK2[Before Update Hooks]
    PRECHECK3[Prefetch Images]
    PRECHECK4[Ensure Resources]
    PRECHECK5[Validate Applications]

    POSTACTION1[After Update Hooks]
    POSTACTION2[Start/Stop Applications]

    RECONCILE_SPEC[Reconcile Desired Spec]

    STATUS_ERROR[Report Error Status]
    STATUS_DEGRADED[Report Degraded Status]
    STATUS_SUCCESS[Report Success Status]

    CONTROLLER_OS[OS Controller]
    CONTROLLER_RESOURCES[Resource Controller]
    CONTROLLER_HOOKS[Hooks Controller]
    CONTROLLER_APPS[Application Controller]

    ROLLBACK[Rollback Current -> Desired]
    MARK_FAILED[Mark Version Failed]
    REBOOT[Reboot]

    %% Evals
    EVAL_NEW_VERSION{New Version Available?}
    EVAL_NEW_VERSION_FAILED{New Version Failed?}
    EVAL_PRECHECK{PreCheck Successful?}
    EVAL_PRECHECK_RETRY{Retryable?}
    EVAL_RETRY_COUNT{Retry Count Exceeded?}
    EVAL_RECONCILE{Reconciliation Successful?}
    EVAL_POSTACTION{Post Hook Successful?}
    EVAL_OS{Has OS Update}
    

    %%%% Begin Flow

    MANAGEMENT_API --> EVAL_NEW_VERSION

    %% New Desired Spec?
    EVAL_NEW_VERSION -- Yes --> EVAL_NEW_VERSION_FAILED 
    EVAL_NEW_VERSION -- No --> RECONCILE_LOOP

    %% New Version is failed?
    EVAL_NEW_VERSION_FAILED -- Yes --> RECONCILE_NEW
    EVAL_NEW_VERSION_FAILED -- No --> WRITE_DESIRED

    RECONCILE_NEW --> RECONCILE_LOOP
    WRITE_DESIRED ---> RECONCILE_LOOP
    RECONCILE_LOOP --> PRECHECK1
    
    %% Pre Checks
    subgraph PreCheck
        subgraph NonRetryable
            PRECHECK1 --> PRECHECK2
        end
        subgraph Retryable
            PRECHECK2 --> PRECHECK3
            PRECHECK3 --> PRECHECK4
            PRECHECK4 -->PRECHECK5
        end
    end        
    
    PRECHECK5 --> EVAL_PRECHECK
    
    %% PreCheck Success
    EVAL_PRECHECK -- Yes --> RECONCILE_SPEC
    EVAL_PRECHECK -- No --> EVAL_PRECHECK_RETRY
    
    %% PreCheck Retry
    EVAL_PRECHECK_RETRY -- Yes --> EVAL_RETRY_COUNT
    EVAL_PRECHECK_RETRY -- No --> STATUS_ERROR

    RECONCILE_SPEC --> CONTROLLER_OS

    %% Reconciliation
    subgraph Controller Reconciliation
        CONTROLLER_OS --> CONTROLLER_RESOURCES
        CONTROLLER_RESOURCES --> CONTROLLER_HOOKS
        CONTROLLER_HOOKS --> CONTROLLER_APPS
    end

    CONTROLLER_APPS --> EVAL_RECONCILE

    %% Reconcile Success
    EVAL_RECONCILE -- Yes --> POSTACTION1
    EVAL_RECONCILE -- No --> ROLLBACK

    ROLLBACK --> EVAL_RETRY_COUNT

    %% Retry Count Reached?
    EVAL_RETRY_COUNT -- Yes --> STATUS_ERROR
    EVAL_RETRY_COUNT -- No --> STATUS_DEGRADED

    STATUS_DEGRADED --> RECONCILE_LOOP

    %% Can Rollback?
    %%EVAL_ROLLBACK -- Yes --> ROLLBACK
    %%EVAL_ROLLBACK -- No --> RECONCILE_LOOP
    
    %%ROLLBACK --> RECONCILE_SPEC

    %% PostUpdate Hooks
    subgraph PostAction
        POSTACTION1 --> POSTACTION2
    end
    
    POSTACTION2 --> EVAL_POSTACTION

    %% PostAction Success
    EVAL_POSTACTION -- Yes --> EVAL_OS
    EVAL_POSTACTION -- No -->STATUS_ERROR

    %% OS    
    EVAL_OS -- Yes --> REBOOT
    EVAL_OS -- No --> UPDATE_CURRENT

    UPDATE_CURRENT --> STATUS_SUCCESS

    STATUS_ERROR --> MARK_FAILED
    MARK_FAILED --> MANAGEMENT_API
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment