argoproj-labs / gitops-promoter

A GitOps Environment Promotion Tool
https://argo-gitops-promoter.readthedocs.io
Apache License 2.0
50 stars 5 forks source link

Gracefully handle empty active branch #99

Open crenshaw-dev opened 2 weeks ago

crenshaw-dev commented 2 weeks ago

If there's no hydrator.metadata in the active branch, the CTP controller currently fails with an error like this:

2024-11-04T15:33:44.793Z        INFO    Branch SHAs     {"controller": "changetransferpolicy", "controllerGroup": "promoter.argoproj.io", "controllerKind": "ChangeTransferPolicy", "ChangeTransferPolicy": {"name":"argocon-demo-environments-development-eadabead","namespace":"promoter-system"}, "namespace": "promoter-system", "name": "argocon-demo-environments-development-eadabead", "reconcileID": "ed437977-f5b0-4c19-8b09-5e277dcf1dfe", "branchShas": {"environments/development":{"Dry":"","Hydrated":"a126b37613c32213e03939a1b1556028ec9097ea"},"environments/development-next":{"Dry":"2ab072a32a4fd923604c40a2c14d986a66b7a359","Hydrated":"53e0a9ef8464fe2b987acd908173666c7a64d2d2"}}}
2024-11-04T15:33:44.794Z        ERROR   could not git show      {"controller": "changetransferpolicy", "controllerGroup": "promoter.argoproj.io", "controllerKind": "ChangeTransferPolicy", "ChangeTransferPolicy": {"name":"argocon-demo-environments-development-eadabead","namespace":"promoter-system"}, "namespace": "promoter-system", "name": "argocon-demo-environments-development-eadabead", "reconcileID": "ed437977-f5b0-4c19-8b09-5e277dcf1dfe", "gitError": "fatal: ambiguous argument '': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n", "error": "exit status 128"}
github.com/argoproj-labs/gitops-promoter/internal/git.(*GitOperations).GetShaTime
        /workspace/internal/git/git.go:180
github.com/argoproj-labs/gitops-promoter/internal/controller.(*ChangeTransferPolicyReconciler).calculateStatus
        /workspace/internal/controller/changetransferpolicy_controller.go:168
github.com/argoproj-labs/gitops-promoter/internal/controller.(*ChangeTransferPolicyReconciler).Reconcile
        /workspace/internal/controller/changetransferpolicy_controller.go:106
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Reconcile
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.0/pkg/internal/controller/controller.go:116
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.0/pkg/internal/controller/controller.go:303
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.0/pkg/internal/controller/controller.go:263
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.19.0/pkg/internal/controller/controller.go:224

Ideally the hydrator should take care of this. But at the least we should print a nicer error.