Repository navigation
fix(git): honor explicit yaml file path in GitOps write - #895
Open
Tyagiquamar wants to merge 1 commit into
Open
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
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
moduleFilePathin the GitOps write client decides whether the configured write path is a directory (append<module>.yaml) or an explicit YAML file (use as is). The extension check was always true, so an explicit.yamlor.ymlfile path was treated as a directory and the module was written to<path>/<module>.yaml. This fixes the extension check so explicit file paths are honored.Root Cause & Problem
The helper compared
path.Ext(path)against"yaml"and"yml"without the leading dot, while Go'spath.Extreturns the dot (for example.yaml). On top of that, the two comparisons were joined with||, a condition that can never be false for a single string. The branch that appends the module file therefore always ran. A module configured withwrite-path: teams/platform/config.yamlproducedteams/platform/config.yaml/<module>.yaml, which creates a directory namedconfig.yamland writes the module to the wrong location. The delete path uses the same helper, so removing such a module failed to target the original file.Technical Solution
Changed
cyclops-ctrl/internal/git/writeclient.goto read the extension once and compare against".yaml"and".yml"with&&. Directory paths still get<moduleName>.yamlappended; explicit YAML file paths are returned unchanged. No other behavior changes.Added
cyclops-ctrl/internal/git/writeclient_test.gowith a table-driven test covering directory paths,.yamland.ymlfile paths, and a dotted directory name. The.yamland.ymlcases failed before the fix.Test Plan
Commands run locally with Go 1.27.3 (
GOTOOLCHAIN=localto avoid fetching the repo's declared 1.22.5 toolchain):go test ./internal/git/ -run TestModuleFilePath -count=1 -v-> 4 subtests pass. The.yamland.ymlsubtests failed before the fix with paths likemodules/prod/my-module.yaml/my-module.yaml.go fmt ./internal/git/-> exit 0, no formatting changes outstanding.go vet ./internal/git/-> exit 0, no findings.