Skip to content

Instantly share code, notes, and snippets.

@hexfusion
Last active September 22, 2024 14:26
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
    NEW_SPEC[New RenderedDeviceSpec]
    WRITE_DESIRED[Write to desired.json]
    RECONCILE_LOOP[Reconcile Loop]
    UPDATE_CURRENT[Desired -> Current Spec]

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

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

    RECONCILE_SPEC[Reconcile Desired Spec]

    STATUS_ERROR[Report Error Status]
    STATUS_DEGRADED1[Report Degraded Status]
    STATUS_DEGRADED2[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 Previous Version]
    REBOOT[Reboot]

    %% Evals
    EVAL_PRECHECK{PreCheck Successful?}
    EVAL_PRECHECK_RETRY{Retryable?}
    EVAL_PRECHECK_RETRY_COUNT{Retry Count Exceeded?}
    EVAL_RECONCILE{Reconciliation Successful?}
    EVAL_RECONCILE_RETRY_COUNT{Retry Count Exceeded?}
    EVAL_POSTACTION{Post Hook Successful?}
    EVAL_OS{Has OS Update}
    

    %%%% Begin Flow

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

    %% PreCheck Retry Count Exceeded
    EVAL_PRECHECK_RETRY_COUNT -- Yes --> STATUS_ERROR
    EVAL_PRECHECK_RETRY_COUNT -- No --> STATUS_DEGRADED1

    STATUS_DEGRADED1 --> RECONCILE_LOOP
    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 --> EVAL_RECONCILE_RETRY_COUNT


    %% Reconcile Retry
    EVAL_RECONCILE_RETRY_COUNT -- No --> STATUS_DEGRADED2
    EVAL_RECONCILE_RETRY_COUNT -- Yes --> STATUS_ERROR

    STATUS_DEGRADED2 --> ROLLBACK
    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 --> NEW_SPEC


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