Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD-781: Telefonistka wrongly reports "Error" when deploying from a PR branch with auto-sync on #35

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type DiffResult struct {
HasDiff bool
DiffError error
AppWasTemporarilyCreated bool
AppSyncedFromPRBranch bool
}

// Mostly copied from https://github.com/argoproj/argo-cd/blob/4f6a8dce80f0accef7ed3b5510e178a6b398b331/cmd/argocd/commands/app.go#L1255C6-L1338
Expand Down Expand Up @@ -483,7 +484,9 @@ func generateDiffOfAComponent(ctx context.Context, commentDiff bool, componentPa
componentDiffResult.ArgoCdAppURL = fmt.Sprintf("%s/applications/%s", argoSettings.URL, app.Name)

if app.Spec.Source.TargetRevision == prBranch && app.Spec.SyncPolicy.Automated != nil {
componentDiffResult.DiffError = fmt.Errorf("App %s already has revision %s as Source Target Revision and autosync is on, skipping diff calculation", app.Name, prBranch)
componentDiffResult.DiffError = nil
componentDiffResult.AppSyncedFromPRBranch = true

return componentDiffResult
}

Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ func shouldSyncBranchCheckBoxBeDisplayed(componentPathList []string, allowSyncfr
if !isSyncFromBranchAllowedForThisPath(allowSyncfromBranchPathRegex, componentPath) {
continue
}

// Then we check the relevant app is not new, temporary app.
// We don't support syncing new apps from branches
for _, diffOfChangedComponent := range diffOfChangedComponents {
if diffOfChangedComponent.ComponentPath == componentPath && !diffOfChangedComponent.AppWasTemporarilyCreated {
if diffOfChangedComponent.ComponentPath == componentPath && !diffOfChangedComponent.AppWasTemporarilyCreated && !diffOfChangedComponent.AppSyncedFromPRBranch {
return true
}
}
Expand Down
17 changes: 16 additions & 1 deletion internal/pkg/githubapi/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ func TestShouldSyncBranchCheckBoxBeDisplayed(t *testing.T) {
},
expected: false,
},
"App synced from branch": {
componentPathList: []string{"workspace/app1"},
allowSyncfromBranchPathRegex: `^workspace/.*$`,
diffOfChangedComponents: []argocd.DiffResult{
{
AppSyncedFromPRBranch: true,
ComponentPath: "workspace/app1",
},
},
expected: false,
},
"Existing App": {
componentPathList: []string{"workspace/app1"},
allowSyncfromBranchPathRegex: `^workspace/.*$`,
Expand All @@ -326,7 +337,7 @@ func TestShouldSyncBranchCheckBoxBeDisplayed(t *testing.T) {
expected: true,
},
"Mixed New and Existing Apps": {
componentPathList: []string{"workspace/app1", "workspace/app2"},
componentPathList: []string{"workspace/app1", "workspace/app2", "workspace/app3"},
allowSyncfromBranchPathRegex: `^workspace/.*$`,
diffOfChangedComponents: []argocd.DiffResult{
{
Expand All @@ -337,6 +348,10 @@ func TestShouldSyncBranchCheckBoxBeDisplayed(t *testing.T) {
AppWasTemporarilyCreated: true,
ComponentPath: "workspace/app2",
},
{
AppSyncedFromPRBranch: true,
ComponentPath: "workspace/app3",
},
},
expected: true,
},
Expand Down
6 changes: 6 additions & 0 deletions templates/argoCD-diff-pr-comment-concise.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Diff of ArgoCD applications(⚠️ concise view, full diff didn't fit GH comment

</details>
{{- else }}
{{ if $appDiffResult.AppSyncedFromPRBranch }}
> [!NOTE]
> The app already has this branch set as the source target revision, and autosync is enabled. Diff calculation was skipped.
{{- else }}

No diff 🤷
{{- end}}
{{if $appDiffResult.AppWasTemporarilyCreated }}
Expand All @@ -34,6 +39,7 @@ No diff 🤷
> It will not be present in ArgoCD UI for more than a few seconds.
{{- end}}

{{- end }}
{{- end }}

{{- end }}
Expand Down
6 changes: 6 additions & 0 deletions templates/argoCD-diff-pr-comment.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Please check the App Conditions of <img src="https://argo-cd.readthedocs.io/en/s

</details>
{{- else }}
{{ if $appDiffResult.AppSyncedFromPRBranch }}
> [!NOTE]
> The app already has this branch set as the source target revision, and autosync is enabled. Diff calculation was skipped.
{{- else }}

No diff 🤷
{{- end}}
{{if $appDiffResult.AppWasTemporarilyCreated }}
Expand All @@ -46,6 +51,7 @@ No diff 🤷
> It will not be present in ArgoCD UI for more than a few seconds.
{{- end}}

{{- end }}
{{- end }}

{{- end }}
Expand Down
Loading