Skip to content

Commit e17621c

Browse files
authored
remove application set revision check. (#271)
applicationsets was checking the manifest was targeting main, however there are cases where targetRevision may be using template e.g. `{{ .values.target }}` This causes the check to fail and does not perform applicationset checks. This PR removes the check as this check is only required on the applications not applicationsets.
1 parent ebf376b commit e17621c

File tree

3 files changed

+4
-38
lines changed

3 files changed

+4
-38
lines changed

pkg/affected_apps/argocd_matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (a *ArgocdMatcher) AffectedApps(_ context.Context, changeList []string, tar
7777
}
7878

7979
appsSlice := a.appsDirectory.FindAppsBasedOnChangeList(changeList, targetBranch)
80-
appSetsSlice := a.appSetsDirectory.FindAppsBasedOnChangeList(changeList, targetBranch, repo)
80+
appSetsSlice := a.appSetsDirectory.FindAppsBasedOnChangeList(changeList, repo)
8181

8282
// and return both apps and appSets
8383
return AffectedItems{

pkg/appdir/appset_directory.go

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (d *AppSetDirectory) ProcessApp(app v1alpha1.ApplicationSet) {
6868
// e.g. changeList = ["/appset/httpdump/httpdump.yaml", "/app/testapp/values.yaml"]
6969
// if the changed file is application set file, return it.
7070

71-
func (d *AppSetDirectory) FindAppsBasedOnChangeList(changeList []string, targetBranch string, repo *git.Repo) []v1alpha1.ApplicationSet {
71+
func (d *AppSetDirectory) FindAppsBasedOnChangeList(changeList []string, repo *git.Repo) []v1alpha1.ApplicationSet {
7272
log.Debug().Str("type", "applicationsets").Msgf("checking %d changes", len(changeList))
7373

7474
appsSet := make(map[string]struct{})
@@ -97,53 +97,21 @@ func (d *AppSetDirectory) FindAppsBasedOnChangeList(changeList []string, targetB
9797
continue
9898
}
9999

100-
if !appSetShouldInclude(appSet, targetBranch) {
101-
log.Debug().Msgf("target revision of %s is %s and does not match '%s'", appSet, appSetGetTargetRevision(appSet), targetBranch)
102-
continue
103-
}
104-
105100
// Store the unique ApplicationSet
106101
if _, exists := appsSet[appSet.Name]; !exists {
107102
appsSet[appSet.Name] = struct{}{}
108103
appSets = append(appSets, *appSet)
109104
}
110105
}
111106

112-
log.Debug().Str("source", "appset_directory").Msgf("matched %d files into %d appset", len(changeList), len(appsSet))
107+
log.Debug().Str("source", "appset_directory").Msgf("matched %d files into %d appset", len(changeList), len(appSets))
113108
return appSets
114109
}
115110

116-
func appSetGetTargetRevision(app *v1alpha1.ApplicationSet) string {
117-
return app.Spec.Template.Spec.GetSource().TargetRevision
118-
}
119-
120111
func appSetGetSourcePath(app *v1alpha1.ApplicationSet) string {
121112
return app.Spec.Template.Spec.GetSource().Path
122113
}
123114

124-
func appSetShouldInclude(app *v1alpha1.ApplicationSet, targetBranch string) bool {
125-
targetRevision := appSetGetTargetRevision(app)
126-
if targetRevision == "" {
127-
return true
128-
}
129-
130-
if targetRevision == targetBranch {
131-
return true
132-
}
133-
134-
if targetRevision == "HEAD" {
135-
if targetBranch == "main" {
136-
return true
137-
}
138-
139-
if targetBranch == "master" {
140-
return true
141-
}
142-
}
143-
144-
return false
145-
}
146-
147115
func (d *AppSetDirectory) GetAppSets(filter func(stub v1alpha1.ApplicationSet) bool) []v1alpha1.ApplicationSet {
148116
var result []v1alpha1.ApplicationSet
149117
for _, value := range d.appSetsMap {

pkg/appdir/appset_directory_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func TestAppSetDirectory_FindAppsBasedOnChangeList(t *testing.T) {
8282
changeList: []string{
8383
"appsets/httpdump/valid-appset.yaml",
8484
},
85-
targetBranch: "main",
8685
mockFiles: map[string]string{
8786
"appsets/httpdump/valid-appset.yaml": `
8887
apiVersion: argoproj.io/v1alpha1
@@ -180,7 +179,6 @@ spec:
180179
changeList: []string{
181180
"invalid-appset.yaml",
182181
},
183-
targetBranch: "main",
184182
mockFiles: map[string]string{
185183
"appsets/httpdump/invalid-appset.yaml": "invalid yaml content",
186184
},
@@ -214,7 +212,7 @@ spec:
214212
t.Fatalf("failed to create tmp folder %s", fatalErr)
215213
}
216214
d := &AppSetDirectory{}
217-
result := d.FindAppsBasedOnChangeList(tt.changeList, tt.targetBranch, &git.Repo{Directory: tempDir})
215+
result := d.FindAppsBasedOnChangeList(tt.changeList, &git.Repo{Directory: tempDir})
218216
assert.Equal(t, tt.expected, result)
219217
})
220218
}

0 commit comments

Comments
 (0)