Skip to content

Commit b45740f

Browse files
Merge pull request #45 from segmentio/yolken-fix-globs
Prune clusters with no changes when using wildcards
2 parents bc99e3f + 5344d80 commit b45740f

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,45 @@ 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+
// Cluster 3 is pruned from selection list because it doesn't have any files in the
174+
// git diff.
175+
expectedClustersIDs: []string{
176+
"stage:us-west-2:cluster1",
177+
},
178+
expectedSubpaths: []string{
179+
"subdir1",
180+
},
181+
},
143182
{
144183
diffs: []*github.CommitFile{
145184
{

pkg/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package version
22

33
// Version stores the current kubeapply version.
4-
const Version = "0.0.32"
4+
const Version = "0.0.33"

0 commit comments

Comments
 (0)