fix(ctp): drop invalid ref fields#1159
fix(ctp): drop invalid ref fields#1159crenshaw-dev wants to merge 13 commits intoargoproj-labs:mainfrom
Conversation
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Bundle ReportBundle size has no change ✅ |
There was a problem hiding this comment.
Pull request overview
This PR prevents ChangeTransferPolicy reconciliation from getting “bricked” when hydrator.metadata contains invalid (non-CRD-validating) reference fields by sanitizing invalid reference values before they are written into status.
Changes:
- Add runtime sanitization for
hydrator.metadatareferences[].commit.{sha,repoURL}ingit.GetShaMetadataFromFile. - Add unit test coverage for reference sanitization in
internal/git/git_test.go. - Extend controller test helpers and add an integration-style controller test covering the invalid-reference scenario.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/git/git.go | Adds reference sanitization logic to avoid CRD validation failures on status patch. |
| internal/git/git_test.go | Adds tests asserting invalid reference fields are cleared while preserving the reference item. |
| internal/controller/suite_test.go | Refactors hydration test helper to allow injecting valid/invalid references into hydrator.metadata. |
| internal/controller/changetransferpolicy_controller_test.go | Adds a controller test ensuring reconciliation succeeds when invalid reference fields exist. |
internal/git/git.go
Outdated
| if c.RepoURL != "" { | ||
| validURL := repoURLValidPattern.MatchString(c.RepoURL) | ||
| if validURL { | ||
| if u, err := url.Parse(c.RepoURL); err != nil || (u.Scheme != "http" && u.Scheme != "https") { | ||
| validURL = false | ||
| } | ||
| } | ||
| if !validURL { | ||
| logger.Info("Discarding invalid RepoURL in hydrator.metadata references", "index", i, "repoURL", c.RepoURL) | ||
| c.RepoURL = "" | ||
| } |
There was a problem hiding this comment.
sanitizeReferences claims to match CommitMetadata CRD validation, but for RepoURL the CRD also has XValidation self == '' || isURL(self) in addition to the regex pattern. The current check (regex + url.Parse + scheme check) is likely less strict than isURL and may allow values that the API will still reject, which would keep the original "status patch fails validation" failure mode. Consider tightening validation to more closely mirror the CRD (e.g., require an absolute URL with non-empty host, and reject URLs that parse but are not considered valid URLs).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1159 +/- ##
==========================================
- Coverage 53.42% 51.08% -2.34%
==========================================
Files 54 54
Lines 6168 6195 +27
==========================================
- Hits 3295 3165 -130
- Misses 2513 2675 +162
+ Partials 360 355 -5 ☔ View full report in Codecov by Sentry. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
If an invalid repoURL or commit sha is in the hydrator.metadata references, it'll fail the status validation and brick reconciliation.
This change drops any invalid values and logs a warning. The user impact is that the data will simply be missing from the UI, which isn't a terrible failure mode for data that's just informative, not functional.