Skip to content

Commit

Permalink
Create the temp app pointing to the main branch and skip validation.
Browse files Browse the repository at this point in the history
This feels safer
  • Loading branch information
Oded-B committed Jul 16, 2024
1 parent f46c4e5 commit bd659cc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
newAppObject.Name = tempAppName
// We need to remove the automated sync policy, we just want to create a temporary app object, run a diff and remove it.
newAppObject.Spec.SyncPolicy.Automated = nil
// If this app doesn't exist as object it probably doesn't exist on the main branch(this PR will add it), so we set the source ref to the PR branch
newAppObject.Spec.Source.TargetRevision = prBranch
// We don't mutate .Spec.Source.TargetRevision, we want it pointing to main branch, this ensures nobody syncs before merging the PR.
// We are OK with creating a "failing" app

unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(newAppObject)
if err != nil {
Expand All @@ -440,10 +440,14 @@ func generateDiffOfAComponent(ctx context.Context, componentPath string, prBranc
}
log.Println(appYaml)

validateTempApp := false
appCreateRequest := application.ApplicationCreateRequest{
Application: newAppObject,
Validate: &validateTempApp, // We create the objects pointing the non-existing(yet) dir in the main branch - validation will fail, its also a waste of time - wi'll run a diff shortly
}
// Create the temporary app object
app, err = ac.app.Create(ctx, &application.ApplicationCreateRequest{Application: newAppObject})
// TODO Should use "Validate: false" here? and avoid the "newAppObject.Spec.Source.TargetRevision = prBranch" above?
// It would be safer to keep the object pointing to the main branch...
app, err = ac.app.Create(ctx, &appCreateRequest)

if err != nil {
log.Errorf("Error creating temporary app object: %v", err)
componentDiffResult.DiffError = err
Expand Down

0 comments on commit bd659cc

Please sign in to comment.