File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff 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 {}
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 11package version
22
33// Version stores the current kubeapply version.
4- const Version = "0.0.32 "
4+ const Version = "0.0.33 "
You can’t perform that action at this time.
0 commit comments