feat(ui): add drift detection for Crossplane managed resources#262
Open
claudiocosta wants to merge 2 commits into
Open
feat(ui): add drift detection for Crossplane managed resources#262claudiocosta wants to merge 2 commits into
claudiocosta wants to merge 2 commits into
Conversation
Collaborator
|
Hi @claudiocosta thanks for the great contribution to Crossview.This already means a lot for us. There are some tiny issues that need to be fixed before I can merge the changes.
Suggestion: Replace the custom renderer in Something like this import CodeMirror from '@uiw/react-codemirror';
import { yaml } from '@codemirror/lang-yaml';
import { crossviewMirrorTheme } from '../../utils/crossviewMirrorTheme.js';
<CodeMirror
value={yamlContent}
extensions={[yaml()]}
theme={colorMode === 'dark' ? crossviewMirrorTheme : undefined}
readOnly
style={{ fontSize: '0.75rem', lineHeight: '1.5' }}
/>This keeps the UI consistent and avoids maintaining two separate code/YAML rendering paths.
|
Adds a Drift tab to the resource detail panel for Crossplane managed resources that have both spec.forProvider (desired state) and status.atProvider (observed state). The tab shows a plan-style unified YAML diff: - Red lines: current state in the provider (atProvider) that differs - Blue lines: desired state declared in the spec (forProvider) - Gray lines: fields only present in atProvider (e.g. arn, id, tagsAll) The diff uses LCS-based line comparison with context collapse (2 lines around each change) and supports expand-all and copy-to-clipboard. Provider-only fields are filtered from the diff to avoid false positives. Signed-off-by: claudiocosta <claudio_costaa@hotmail.com>
9efc7dd to
2f9503b
Compare
Replace the custom LCS plan view in ResourceDrift with a side-by-side split diff using the @codemirror/merge package, which is part of the official CodeMirror 6 ecosystem already used in ResourceYAML. Changes: - Use MergeView from @codemirror/merge for character-level diff highlight - Apply filterToSchema() to atProvider before diffing to exclude provider-only fields (arn, id, tagsAll) and avoid false positives - Apply sortKeys() to both sides to eliminate key-ordering false positives - Enable EditorView.lineWrapping to handle long lines (>300 chars) - collapseUnchanged to fold identical sections automatically - Centered panel headers for atProvider/forProvider labels - Add @codemirror/merge to package.json dependencies Signed-off-by: claudiocosta <claudio_costaa@hotmail.com>
Author
|
Hi @MoeidHeidari, thanks for the detailed review! All three points have been addressed:
A few additional improvements were included to ensure correctness:
Full details of the changes are in the updated PR description. Let me know if there is anything else to adjust! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary
Adds a Drift tab to the resource detail panel for Crossplane managed resources, showing a side-by-side split diff between
spec.forProvider(desired state) andstatus.atProvider(observed state in the provider). The diff uses@codemirror/merge— the official CodeMirror 6 diff package — reusing the same YAML editor already present in the app.Motivation
When Crossplane manages cloud resources, the provider state can drift from the desired configuration due to out-of-band changes (manual edits in AWS/GCP/Azure console, policy enforcement, etc.). Previously, users had to open both the
specandstatustabs and mentally compare the YAML. This feature surfaces that comparison automatically.Changes
New files
src/presentation/utils/driftUtils.js— recursive deep-diff betweenforProviderandatProvider(computeDrift), and helpershasDrift/getDriftEntriessrc/presentation/components/common/ResourceDrift.jsx— Drift tab UI using@codemirror/mergeMergeViewModified files
src/presentation/components/common/ResourceTabs.jsx— adds the Drift tab button (only shown when bothspec.forProviderandstatus.atProviderare present)src/presentation/components/common/ResourceDetails.jsx— wires up drift computation and passes props to tabs and contentpackage.json/package-lock.json— adds@codemirror/mergedependencyHow it works
spec.forProviderandstatus.atProvider). XR composites and non-managed resources are unaffected.@codemirror/merge, consistent with the YAML editor already used inResourceYAML.jsx:status.atProvider(current state in the provider)spec.forProvider(desired state)arn,id,tagsAll, etc.) are filtered fromatProviderbefore diffing to avoid false positivesTesting
go test ./...✅go vet ./...passes with no issues ✅Screenshots
Related