The idea here is to automate applying software patches/update OS packages on VMs and bare-metal hosts, while taking care of:
- Requests/Approvals.
- Gracefully stopping/draining workloads.
- Notifications.
- Pilot updates on a limited number of hosts.
SystemPatchWorkflow
targetClusters: List of Strings (e.g.,["cluster-a", "cluster-b"])pilotHostCount: Integer (number of pilot hosts)approverEmails: List of Strings (e.g.,["foo@example.com", "bar@example.com"])requesterEmail: String (e.g., "baz@example.com")vaultAddress: String (e.g., "https://vault.example.com:8200")vaultToken: String (Vault access token)secretPathPrefix: String (e.g., "patch-deploy")updateCommand: String (e.g., "apt-get update && apt-get upgrade -y")serviceList: List of strings (example:["postgresql", "nginx"])
-
SendApprovalRequestActivity:- Input:
targetClusters,approverEmails,requesterEmail. - Logic: Sends an approval request notification.
- Return:
Boolean(true if approved).
- Input:
-
GetClusterHostsActivity:- Input:
targetCluster. - Logic: Retrieves the list of hosts belonging to a cluster.
- Return:
Listof Strings (hostnames).
- Input:
-
CheckHostPreconditionsActivity:- Input:
hostname. - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Checks host health.
- Verifies maintenance mode status.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if preconditions met),String(SSH private key).
- Input:
-
SendStartNotificationActivity:- Input:
hostname,requesterEmail. - Logic: Sends a notification that the update is starting.
- Return:
Boolean(true if notification sent).
- Input:
-
RunPreDowntimeScriptsActivity:- Input:
hostname - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Executes pre-downtime scripts (if applicable).
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
SetMaintenanceModeActivity:- Input:
hostname - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Puts the host into maintenance mode.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
StopServicesActivity:- Input:
hostname,serviceList - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Stops specified services on the host.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
WaitForWorkloadDrainActivity:- Input:
hostname - Logic: Waits for workloads to drain.
- Return:
Boolean(true if drain successful).
- Input:
-
RunPreUpdateScriptsActivity (optional):- Input:
hostname,preUpdateScripts - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Executes pre-update scripts (if applicable).
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
PerformUpdateActivity:- Input:
hostname,updateCommand - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Executes the update command.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
StartServicesActivity:- Input:
hostname,serviceList - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Starts specified services.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
RunPostUpdateScriptsActivity (optional):- Input:
hostname,postUpdateScripts - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Executes post-update scripts (if applicable).
- Retrieves SSH key from Vault using
- Return:
Boolean(true if successful).
- Input:
-
CheckServiceHealthActivity:- Input:
hostname,serviceList - Logic:
- Retrieves SSH key from Vault using
VaultClient. - Checks if services have become healthy (with timeout).
- If timeout reached, bail out.
- Retrieves SSH key from Vault using
- Return:
Boolean(true if healthy).
- Input:
-
SendSuccessNotificationActivity:- Input:
hostname,requesterEmail. - Logic: Sends a success notification.
- Return:
Boolean(true if notification sent).
- Input:
-
SendFailureAlertActivity:- Input:
hostname,failureDetails,requesterEmail. - Logic: Sends a failure alert.
- Return:
Boolean(true if alert sent).
- Input:
-
Start workflow and receive input.
-
Execute
SendApprovalRequestActivity. If not approved, terminate. -
Execute
VaultClientActivity. -
For each
targetCluster:-
Get cluster hosts using
GetClusterHostsActivity. -
Process pilot hosts:
- For each pilot host (up to
pilotHostCount):- Execute
CheckHostPreconditionsActivity. If false, executeSendFailureAlertActivityand terminate. - If any patching activity fails, execute
SendFailureAlertActivityand terminate. - Execute
SendSuccessNotificationActivity.
- Execute
- For each pilot host (up to
-
Process remaining hosts:
- For each remaining host:
- Execute
CheckHostPreconditionsActivity. If false, executeSendFailureAlertActivityand terminate. - Execute host patching activities, passing the retrieved SSH key.
- If any patching activity fails, execute
SendFailureAlertActivityand terminate. - Execute
SendSuccessNotificationActivity.
- Execute
- For each remaining host:
-
-
Send a final success notification.
-
Complete the workflow.
- Each activity has retry policies.
SendFailureAlertActivitystops the rollout on any host failure.- Vault cleanup is attempted during failures, though this might be limited in scope.
- Temporal cancellation scopes are used where applicable.
- Local activities are used where applicable.