Skip to content

fix(git): honor explicit yaml file path in GitOps write - #895

Open
Tyagiquamar wants to merge 1 commit into
cyclops-ui:mainfrom
Tyagiquamar:fix/gitops-write-file-path-detection
Open

Tyagiquamar wants to merge 1 commit into
cyclops-ui:mainfrom
Tyagiquamar:fix/gitops-write-file-path-detection

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary

moduleFilePath in 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 .yaml or .yml file 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's path.Ext returns 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 with write-path: teams/platform/config.yaml produced teams/platform/config.yaml/<module>.yaml, which creates a directory named config.yaml and 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.go to read the extension once and compare against ".yaml" and ".yml" with &&. Directory paths still get <moduleName>.yaml appended; explicit YAML file paths are returned unchanged. No other behavior changes.

Added cyclops-ctrl/internal/git/writeclient_test.go with a table-driven test covering directory paths, .yaml and .yml file paths, and a dotted directory name. The .yaml and .yml cases failed before the fix.

Test Plan

Commands run locally with Go 1.27.3 (GOTOOLCHAIN=local to avoid fetching the repo's declared 1.22.5 toolchain):

  • go test ./internal/git/ -run TestModuleFilePath -count=1 -v -> 4 subtests pass. The .yaml and .yml subtests failed before the fix with paths like modules/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.

@Tyagiquamar
Tyagiquamar requested a review from a team as a code owner November 19, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant