Add drift detection infrastructure #1041
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements the foundational infrastructure for drift detection as outlined in #1037. Drift detection allows users to monitor when cloud resources diverge from their desired state defined in Stack CRs, with optional automatic remediation.
Changes
API/CRD Enhancements
DriftDetectionSpecto configure drift detection schedules with cron expressionsDriftDetectionStatusto track last drift check timestampDriftDetectedcondition to Stack status withChangesandNoChangesreasonspreviewOnlyfield to Update CRD for non-destructive refresh operationsProtocol Buffer Updates
preview_onlyfield toRefreshRequestmessageAgent Implementation
Refresh()method to handlepreview_onlyflagRunProgram(false)as a workaroundStack.PreviewRefresh()insteadNote on Automation API: The Pulumi Automation API already has
Stack.PreviewRefresh()which provides the exact functionality we need for non-destructive drift detection. The current implementation usesoptrefresh.RunProgram(false)as a workaround, but should be updated to use the properPreviewRefresh()method which:PreviewResultwithChangeSummaryinstead ofUpdateSummarypulumi refresh --preview-onlyController Logic
newDriftDetection()helper to generate drift detection Update CRsmarkStackSucceeded()to detect and handle drift detection resultsDriftDetectedcondition based on resultsStackDriftDetectedKubernetes eventsCode Generation
deploy/crds/anddeploy/helm/docs/Example Usage
Once scheduling is implemented, users will be able to configure drift detection like this:
Current Limitations
This PR provides foundational infrastructure. The following items are not yet implemented:
RunProgram(false)workaround with properStack.PreviewRefresh()callautoRemediate: true, should automatically create anupUpdateTesting
Next Steps
Before this PR is ready for review:
Stack.PreviewRefresh()instead ofRunProgram(false)Related
Note: This is a draft PR to demonstrate the implementation approach. Feedback welcome on the API design and implementation direction before completing the remaining work.
🤖 Generated with Claude Code