cmd/flux: search for kind within the YAML document instead of line+1#5860
Open
SAY-5 wants to merge 1 commit into
Open
cmd/flux: search for kind within the YAML document instead of line+1#5860SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
detectFileUpgrades hard-coded the kind: lookup at apiVersion line+1, so manifests with any other field (metadata:, comments, annotations) or reversed field order silently returned "no migration needed" even when apiVersion was deprecated (fluxcd#5839). Search within the current YAML document boundaries: scan backwards to the previous '---' separator or start-of-file, then forwards to the next '---' separator. First kind: line wins. The order is backwards-then-forwards so that for a conventional apiVersion/kind ordering we only scan the single line + the document boundary; the forward fallback covers the reversed-order case. Adds a regression fixture with three documents covering: - apiVersion first, kind after metadata: - kind first, apiVersion after metadata: - kind first, apiVersion last Fixes fluxcd#5839 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
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
Fixes #5839.
cmd/flux/migrate.go'sdetectFileUpgradesassumedkind:always lives on the line immediately followingapiVersion:. In practice YAML fields can be ordered arbitrarily, so a manifest withmetadata:between the two fields (or withapiVersion:last) produced a silentno custom resources found that require migrationeven when the apiVersion was deprecated.Fix
Search within the current YAML document (delimited by
---separators) rather than hard-codingline+1: scan backwards to the previous separator / start-of-file, then forwards to the next separator. The first matchingkind:line wins. The order (backwards first) keeps the happy-path scan tight for the conventionalapiVersion:thenkind:layout; the forward fallback covers reversed-order documents.Tests
Adds a regression fixture
testdata/migrate/file-system/non-adjacent-kind.yamlexercising three shapes in one file:apiVersion:first,kind:aftermetadata:kind:first,apiVersion:aftermetadata:kind:first,apiVersion:lastAll three migrate to
v1as expected. The matching.golden+.output.goldenfixtures pin the behaviour.go test -run TestFileSystemMigrator ./cmd/flux/...green;go vet ./cmd/flux/...clean.