Skip to content

Commit

Permalink
fix: webhook don't refresh apps pointing to HEAD (#4717)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev committed Oct 30, 2020
1 parent 42ebb22 commit 97003ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 1 addition & 3 deletions util/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ func ensureAbsPath(input string) string {
func appRevisionHasChanged(app *v1alpha1.Application, revision string, touchedHead bool) bool {
targetRev := app.Spec.Source.TargetRevision
if targetRev == "HEAD" || targetRev == "" { // revision is head
if !touchedHead { // and head has not updated
return false // revision has not changed
}
return touchedHead
}

return targetRev == revision
Expand Down
22 changes: 22 additions & 0 deletions util/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ func Test_getAppRefreshPrefix(t *testing.T) {
})
}
}

func TestAppRevisionHasChanged(t *testing.T) {
assert.True(t, appRevisionHasChanged(&v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{
Source: v1alpha1.ApplicationSource{},
}}, "master", true))

assert.False(t, appRevisionHasChanged(&v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{
Source: v1alpha1.ApplicationSource{},
}}, "master", false))

assert.False(t, appRevisionHasChanged(&v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{
Source: v1alpha1.ApplicationSource{
TargetRevision: "dev",
},
}}, "master", true))

assert.True(t, appRevisionHasChanged(&v1alpha1.Application{Spec: v1alpha1.ApplicationSpec{
Source: v1alpha1.ApplicationSource{
TargetRevision: "dev",
},
}}, "dev", false))
}

0 comments on commit 97003ca

Please sign in to comment.