Skip to content

Commit cfda081

Browse files
Prune clusters with no changes when using wildcards
1 parent bc99e3f commit cfda081

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

pkg/pullreq/diffs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ func GetCoveredClusters(
175175
}
176176
}
177177

178+
// In case where someone has used a wildcard, prune clusters that have no changes
179+
// to avoid unexpected applies.
180+
hasWildcards := false
181+
182+
for _, globStr := range selectedClusterGlobStrs {
183+
if strings.Contains(globStr, "*") {
184+
hasWildcards = true
185+
break
186+
}
187+
}
188+
189+
if hasWildcards {
190+
for cluster, paths := range changedClusterPaths {
191+
if len(paths) == 0 {
192+
log.Infof("Removing cluster %s because it has no changes", cluster)
193+
delete(changedClusterPaths, cluster)
194+
}
195+
}
196+
}
197+
178198
log.Infof("Changed cluster paths: %+v", changedClusterPaths)
179199

180200
changedClusters := []*config.ClusterConfig{}

pkg/pullreq/diffs_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,43 @@ func TestGetCoveredClusters(t *testing.T) {
140140
".",
141141
},
142142
},
143+
{
144+
diffs: []*github.CommitFile{
145+
{
146+
Filename: aws.String("clusters/clustertype/expanded/cluster1/subdir1/file3.yaml"),
147+
},
148+
{
149+
Filename: aws.String("clusters/clustertype/expanded/cluster3/file1.yaml"),
150+
},
151+
},
152+
selectedClusterGlobStrs: []string{
153+
"stage:*",
154+
},
155+
expectedClustersIDs: []string{
156+
"stage:us-west-2:cluster1",
157+
"stage:us-west-2:cluster3",
158+
},
159+
expectedSubpaths: []string{
160+
"subdir1",
161+
".",
162+
},
163+
},
164+
{
165+
diffs: []*github.CommitFile{
166+
{
167+
Filename: aws.String("clusters/clustertype/expanded/cluster1/subdir1/file3.yaml"),
168+
},
169+
},
170+
selectedClusterGlobStrs: []string{
171+
"stage:*",
172+
},
173+
expectedClustersIDs: []string{
174+
"stage:us-west-2:cluster1",
175+
},
176+
expectedSubpaths: []string{
177+
"subdir1",
178+
},
179+
},
143180
{
144181
diffs: []*github.CommitFile{
145182
{

0 commit comments

Comments
 (0)