77 "sort"
88 "strings"
99
10+ "github.com/gobwas/glob"
1011 "github.com/google/go-github/v30/github"
1112 "github.com/segmentio/kubeapply/pkg/config"
1213 log "github.com/sirupsen/logrus"
@@ -25,21 +26,26 @@ import (
2526// subpaths.
2627//
2728// There are a few overrides that adjust this behavior:
28- // 1. selectedClusterIDs : If set, then clusters in this slice are never dropped, even if they
29+ // 1. selectedClusterGlobStrs : If set, then clusters in this slice are never dropped, even if they
2930// don't have have any diffs in them.
3031// 2. subpathOverride: If set, then this is used for the cluster subpaths instead of the procedure
3132// in step 6 above.
3233func GetCoveredClusters (
3334 repoRoot string ,
3435 diffs []* github.CommitFile ,
3536 env string ,
36- selectedClusterIDs []string ,
37+ selectedClusterGlobStrs []string ,
3738 subpathOverride string ,
3839 multiSubpaths bool ,
3940) ([]* config.ClusterConfig , error ) {
40- selectedClusterIDsMap := map [string ]struct {}{}
41- for _ , selectedClusterID := range selectedClusterIDs {
42- selectedClusterIDsMap [selectedClusterID ] = struct {}{}
41+ selectedClusterGlobs := []glob.Glob {}
42+
43+ for _ , globStr := range selectedClusterGlobStrs {
44+ globObj , err := glob .Compile (globStr )
45+ if err != nil {
46+ return nil , err
47+ }
48+ selectedClusterGlobs = append (selectedClusterGlobs , globObj )
4349 }
4450
4551 changedClusterPaths := map [string ][]string {}
@@ -80,8 +86,17 @@ func GetCoveredClusters(
8086
8187 log .Infof ("Found cluster config: %s" , path )
8288
83- if len (selectedClusterIDsMap ) > 0 {
84- if _ , ok := selectedClusterIDsMap [configObj .DescriptiveName ()]; ! ok {
89+ if len (selectedClusterGlobs ) > 0 {
90+ var matches bool
91+
92+ for _ , globObj := range selectedClusterGlobs {
93+ if globObj .Match (configObj .DescriptiveName ()) {
94+ matches = true
95+ break
96+ }
97+ }
98+
99+ if ! matches {
85100 log .Infof (
86101 "Ignoring cluster %s because selectedClusters is set and cluster is not in set" ,
87102 configObj .DescriptiveName (),
@@ -118,7 +133,7 @@ func GetCoveredClusters(
118133 return err
119134 }
120135
121- if len (selectedClusterIDsMap ) > 0 {
136+ if len (selectedClusterGlobs ) > 0 {
122137 changedClusterPaths [relPath ] = []string {}
123138 }
124139
0 commit comments