From a3b0bcd6d465a7fbd46a3d8d6a3392cdb3e0cfa0 Mon Sep 17 00:00:00 2001 From: Benjamin Yolken Date: Fri, 19 Mar 2021 14:26:04 -0700 Subject: [PATCH 1/3] Support globs --- data/data.go | 192 +++++++++++++++++++++-------------- go.mod | 1 + go.sum | 1 + pkg/events/handler.go | 4 +- pkg/pullreq/client.go | 2 +- pkg/pullreq/diffs.go | 31 ++++-- pkg/pullreq/diffs_test.go | 40 ++++++-- pkg/pullreq/fake_client.go | 26 +++-- pkg/pullreq/github_client.go | 4 +- 9 files changed, 196 insertions(+), 105 deletions(-) diff --git a/data/data.go b/data/data.go index fd47410..8c4588b 100644 --- a/data/data.go +++ b/data/data.go @@ -1,24 +1,25 @@ -// Code generated by go-bindata. (@generated) DO NOT EDIT. - -// Package data generated by go-bindata.// sources: -// pkg/pullreq/templates/apply_comment.gotpl -// pkg/pullreq/templates/diff_comment.gotpl -// pkg/pullreq/templates/error_comment.gotpl -// pkg/pullreq/templates/help_comment.gotpl -// pkg/pullreq/templates/status_comment.gotpl -// scripts/cluster-summary/__init__.py -// scripts/cluster-summary/cluster_summary.py -// scripts/cluster-summary/tabulate.py -// scripts/create-lambda-bundle.sh -// scripts/kdiff-wrapper.sh -// scripts/kindctl.sh -// scripts/pull-deps.sh -// scripts/raw-diff.sh +// Code generated by go-bindata. DO NOT EDIT. +// sources: +// pkg/pullreq/templates/apply_comment.gotpl (1.052kB) +// pkg/pullreq/templates/diff_comment.gotpl (1.228kB) +// pkg/pullreq/templates/error_comment.gotpl (172B) +// pkg/pullreq/templates/help_comment.gotpl (1.025kB) +// pkg/pullreq/templates/status_comment.gotpl (355B) +// scripts/cluster-summary/__init__.py (0) +// scripts/cluster-summary/cluster_summary.py (4.488kB) +// scripts/cluster-summary/tabulate.py (57.091kB) +// scripts/create-lambda-bundle.sh (819B) +// scripts/kdiff-wrapper.sh (247B) +// scripts/kindctl.sh (1.76kB) +// scripts/pull-deps.sh (2.203kB) +// scripts/raw-diff.sh (143B) + package data import ( "bytes" "compress/gzip" + "crypto/sha256" "fmt" "io" "io/ioutil" @@ -49,8 +50,9 @@ func bindataRead(data []byte, name string) ([]byte, error) { } type asset struct { - bytes []byte - info os.FileInfo + bytes []byte + info os.FileInfo + digest [sha256.Size]byte } type bindataFileInfo struct { @@ -60,32 +62,21 @@ type bindataFileInfo struct { modTime time.Time } -// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } - -// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } - -// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } - -// ModTime return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } - -// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 + return false } - -// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -105,8 +96,8 @@ func pkgPullreqTemplatesApply_commentGotpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "pkg/pullreq/templates/apply_comment.gotpl", size: 1052, mode: os.FileMode(420), modTime: time.Unix(1612551594, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "pkg/pullreq/templates/apply_comment.gotpl", size: 1052, mode: os.FileMode(0644), modTime: time.Unix(1612551594, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x39, 0x98, 0xb8, 0x81, 0x9e, 0xbb, 0x97, 0xdd, 0x58, 0x91, 0x82, 0x55, 0x99, 0xef, 0x6c, 0xc3, 0x49, 0xe7, 0xe0, 0x9d, 0x4, 0x30, 0x35, 0x16, 0xb9, 0xa3, 0x44, 0x34, 0x84, 0x2e, 0x0, 0x1b}} return a, nil } @@ -125,8 +116,8 @@ func pkgPullreqTemplatesDiff_commentGotpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "pkg/pullreq/templates/diff_comment.gotpl", size: 1228, mode: os.FileMode(420), modTime: time.Unix(1611616180, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "pkg/pullreq/templates/diff_comment.gotpl", size: 1228, mode: os.FileMode(0644), modTime: time.Unix(1611616180, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xee, 0x25, 0x58, 0x45, 0x7c, 0xdc, 0xb1, 0x76, 0x21, 0x29, 0x8e, 0x84, 0x5d, 0xb3, 0x29, 0xcf, 0x2e, 0x6e, 0xac, 0x9c, 0xd7, 0x94, 0xb5, 0xab, 0x64, 0xe6, 0x5b, 0xc3, 0x31, 0x9e, 0x7b, 0xcc}} return a, nil } @@ -145,8 +136,8 @@ func pkgPullreqTemplatesError_commentGotpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "pkg/pullreq/templates/error_comment.gotpl", size: 172, mode: os.FileMode(420), modTime: time.Unix(1611616180, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "pkg/pullreq/templates/error_comment.gotpl", size: 172, mode: os.FileMode(0644), modTime: time.Unix(1611616180, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x66, 0x91, 0x41, 0xaa, 0x31, 0xec, 0xcc, 0xde, 0x38, 0xc3, 0x60, 0xd2, 0xa0, 0x3c, 0x7f, 0xb1, 0xbe, 0x9e, 0x85, 0x37, 0x3, 0x9e, 0xd0, 0xc9, 0x9c, 0xab, 0x18, 0x16, 0xdf, 0x86, 0xf0, 0x79}} return a, nil } @@ -165,8 +156,8 @@ func pkgPullreqTemplatesHelp_commentGotpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "pkg/pullreq/templates/help_comment.gotpl", size: 1025, mode: os.FileMode(420), modTime: time.Unix(1611616180, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "pkg/pullreq/templates/help_comment.gotpl", size: 1025, mode: os.FileMode(0644), modTime: time.Unix(1611616180, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2d, 0xd5, 0xd5, 0x14, 0xf7, 0xf3, 0x98, 0xc4, 0x7e, 0x8e, 0x37, 0x4c, 0x3a, 0x9a, 0x21, 0x20, 0xe2, 0xe, 0x6a, 0x1b, 0x92, 0x5e, 0x3a, 0x45, 0x4e, 0x7, 0x60, 0xe8, 0x65, 0x94, 0x37, 0xab}} return a, nil } @@ -185,8 +176,8 @@ func pkgPullreqTemplatesStatus_commentGotpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "pkg/pullreq/templates/status_comment.gotpl", size: 355, mode: os.FileMode(420), modTime: time.Unix(1591836439, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "pkg/pullreq/templates/status_comment.gotpl", size: 355, mode: os.FileMode(0644), modTime: time.Unix(1591836439, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x2c, 0xf0, 0xcb, 0x4, 0x35, 0xaa, 0xf4, 0xf7, 0x74, 0x5d, 0xee, 0xae, 0x74, 0xe2, 0xec, 0xd7, 0x59, 0x9, 0x86, 0xca, 0x60, 0x36, 0x29, 0x25, 0xfb, 0x74, 0x50, 0x8d, 0xbd, 0xe8, 0x9c, 0x70}} return a, nil } @@ -205,8 +196,8 @@ func scriptsClusterSummary__init__Py() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/cluster-summary/__init__.py", size: 0, mode: os.FileMode(420), modTime: time.Unix(1586803753, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/cluster-summary/__init__.py", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1586803753, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}} return a, nil } @@ -225,8 +216,8 @@ func scriptsClusterSummaryCluster_summaryPy() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/cluster-summary/cluster_summary.py", size: 4488, mode: os.FileMode(493), modTime: time.Unix(1593205176, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/cluster-summary/cluster_summary.py", size: 4488, mode: os.FileMode(0755), modTime: time.Unix(1593205176, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xb2, 0xfd, 0xc1, 0xd0, 0x9d, 0x3e, 0x14, 0x51, 0x1a, 0x84, 0x85, 0x49, 0x4a, 0x63, 0x5c, 0x4d, 0x3a, 0x6c, 0x28, 0x48, 0x9, 0xd0, 0x64, 0x2f, 0x7b, 0x5b, 0xa8, 0xe8, 0x1, 0xa, 0xa9, 0x99}} return a, nil } @@ -245,8 +236,8 @@ func scriptsClusterSummaryTabulatePy() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/cluster-summary/tabulate.py", size: 57091, mode: os.FileMode(420), modTime: time.Unix(1586803753, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/cluster-summary/tabulate.py", size: 57091, mode: os.FileMode(0644), modTime: time.Unix(1586803753, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe9, 0x68, 0x8, 0x2c, 0x92, 0x99, 0x98, 0x23, 0x29, 0xba, 0x60, 0xc3, 0xa4, 0x16, 0x4, 0xe3, 0x2, 0xdd, 0x43, 0xdd, 0x2d, 0x2d, 0x51, 0x1e, 0xa9, 0x2, 0xe9, 0x71, 0x54, 0xef, 0x3c, 0x1c}} return a, nil } @@ -265,8 +256,8 @@ func scriptsCreateLambdaBundleSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/create-lambda-bundle.sh", size: 819, mode: os.FileMode(493), modTime: time.Unix(1611633754, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/create-lambda-bundle.sh", size: 819, mode: os.FileMode(0755), modTime: time.Unix(1611633754, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x53, 0x3c, 0xc6, 0xbf, 0x2d, 0x5c, 0xb1, 0x3b, 0x37, 0x5, 0xa4, 0x16, 0x52, 0x5a, 0xd4, 0x49, 0xbb, 0xf8, 0x4, 0x83, 0x3c, 0xbf, 0x10, 0x39, 0xcf, 0x18, 0xbf, 0x52, 0x35, 0xee, 0xca, 0x3}} return a, nil } @@ -285,8 +276,8 @@ func scriptsKdiffWrapperSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/kdiff-wrapper.sh", size: 247, mode: os.FileMode(493), modTime: time.Unix(1611616180, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/kdiff-wrapper.sh", size: 247, mode: os.FileMode(0755), modTime: time.Unix(1611616180, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1c, 0x65, 0xd, 0x2, 0xe5, 0x67, 0x2e, 0xc4, 0x79, 0xc0, 0x40, 0x6, 0x5c, 0x67, 0x6b, 0xbf, 0x64, 0x8, 0x19, 0x33, 0x6c, 0xa0, 0x14, 0x2f, 0x62, 0x59, 0xfc, 0x7e, 0x5d, 0x1b, 0xc9, 0x27}} return a, nil } @@ -305,8 +296,8 @@ func scriptsKindctlSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/kindctl.sh", size: 1760, mode: os.FileMode(493), modTime: time.Unix(1611963885, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/kindctl.sh", size: 1760, mode: os.FileMode(0755), modTime: time.Unix(1611963885, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xfc, 0x3e, 0x4a, 0xe1, 0xf9, 0x6d, 0x9, 0xf1, 0x17, 0xd1, 0xfe, 0xa0, 0x7e, 0xa7, 0x7a, 0xbb, 0x4c, 0xe, 0x1, 0x63, 0x7f, 0x15, 0x0, 0x16, 0x56, 0x48, 0x95, 0xc5, 0xb0, 0xf0, 0x20, 0xca}} return a, nil } @@ -325,8 +316,8 @@ func scriptsPullDepsSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/pull-deps.sh", size: 2203, mode: os.FileMode(493), modTime: time.Unix(1611616180, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/pull-deps.sh", size: 2203, mode: os.FileMode(0755), modTime: time.Unix(1611616180, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x82, 0x78, 0xdc, 0x27, 0x89, 0x9f, 0x3, 0x59, 0x10, 0xa2, 0xed, 0x2, 0x99, 0x9b, 0xa0, 0x37, 0x1a, 0xe0, 0x48, 0xde, 0x41, 0x99, 0xbf, 0x73, 0xf6, 0x7f, 0x94, 0xd8, 0xf8, 0xc, 0xad, 0xc0}} return a, nil } @@ -345,8 +336,8 @@ func scriptsRawDiffSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "scripts/raw-diff.sh", size: 143, mode: os.FileMode(420), modTime: time.Unix(1612551594, 0)} - a := &asset{bytes: bytes, info: info} + info := bindataFileInfo{name: "scripts/raw-diff.sh", size: 143, mode: os.FileMode(0644), modTime: time.Unix(1612551594, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x9, 0x22, 0xae, 0xe8, 0xa3, 0x7b, 0xc9, 0xd1, 0x2a, 0x95, 0x3, 0x39, 0x38, 0x73, 0xa5, 0x4a, 0x8b, 0x2f, 0x10, 0x38, 0x1e, 0xc0, 0x41, 0x56, 0x9a, 0xde, 0x58, 0x2, 0xc9, 0x90, 0xa, 0x11}} return a, nil } @@ -365,6 +356,12 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %s not found", name) } +// AssetString returns the asset contents as a string (instead of a []byte). +func AssetString(name string) (string, error) { + data, err := Asset(name) + return string(data), err +} + // MustAsset is like Asset but panics when Asset would return an error. // It simplifies safe initialization of global variables. func MustAsset(name string) []byte { @@ -376,6 +373,12 @@ func MustAsset(name string) []byte { return a } +// MustAssetString is like AssetString but panics when Asset would return an +// error. It simplifies safe initialization of global variables. +func MustAssetString(name string) string { + return string(MustAsset(name)) +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded. @@ -391,6 +394,33 @@ func AssetInfo(name string) (os.FileInfo, error) { return nil, fmt.Errorf("AssetInfo %s not found", name) } +// AssetDigest returns the digest of the file with the given name. It returns an +// error if the asset could not be found or the digest could not be loaded. +func AssetDigest(name string) ([sha256.Size]byte, error) { + canonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[canonicalName]; ok { + a, err := f() + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s can't read by error: %v", name, err) + } + return a.digest, nil + } + return [sha256.Size]byte{}, fmt.Errorf("AssetDigest %s not found", name) +} + +// Digests returns a map of all known files and their checksums. +func Digests() (map[string][sha256.Size]byte, error) { + mp := make(map[string][sha256.Size]byte, len(_bindata)) + for name := range _bindata { + a, err := _bindata[name]() + if err != nil { + return nil, err + } + mp[name] = a.digest + } + return mp, nil +} + // AssetNames returns the names of the assets. func AssetNames() []string { names := make([]string, 0, len(_bindata)) @@ -402,19 +432,31 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ - "pkg/pullreq/templates/apply_comment.gotpl": pkgPullreqTemplatesApply_commentGotpl, - "pkg/pullreq/templates/diff_comment.gotpl": pkgPullreqTemplatesDiff_commentGotpl, - "pkg/pullreq/templates/error_comment.gotpl": pkgPullreqTemplatesError_commentGotpl, - "pkg/pullreq/templates/help_comment.gotpl": pkgPullreqTemplatesHelp_commentGotpl, + "pkg/pullreq/templates/apply_comment.gotpl": pkgPullreqTemplatesApply_commentGotpl, + + "pkg/pullreq/templates/diff_comment.gotpl": pkgPullreqTemplatesDiff_commentGotpl, + + "pkg/pullreq/templates/error_comment.gotpl": pkgPullreqTemplatesError_commentGotpl, + + "pkg/pullreq/templates/help_comment.gotpl": pkgPullreqTemplatesHelp_commentGotpl, + "pkg/pullreq/templates/status_comment.gotpl": pkgPullreqTemplatesStatus_commentGotpl, - "scripts/cluster-summary/__init__.py": scriptsClusterSummary__init__Py, + + "scripts/cluster-summary/__init__.py": scriptsClusterSummary__init__Py, + "scripts/cluster-summary/cluster_summary.py": scriptsClusterSummaryCluster_summaryPy, - "scripts/cluster-summary/tabulate.py": scriptsClusterSummaryTabulatePy, - "scripts/create-lambda-bundle.sh": scriptsCreateLambdaBundleSh, - "scripts/kdiff-wrapper.sh": scriptsKdiffWrapperSh, - "scripts/kindctl.sh": scriptsKindctlSh, - "scripts/pull-deps.sh": scriptsPullDepsSh, - "scripts/raw-diff.sh": scriptsRawDiffSh, + + "scripts/cluster-summary/tabulate.py": scriptsClusterSummaryTabulatePy, + + "scripts/create-lambda-bundle.sh": scriptsCreateLambdaBundleSh, + + "scripts/kdiff-wrapper.sh": scriptsKdiffWrapperSh, + + "scripts/kindctl.sh": scriptsKindctlSh, + + "scripts/pull-deps.sh": scriptsPullDepsSh, + + "scripts/raw-diff.sh": scriptsRawDiffSh, } // AssetDir returns the file names below a certain @@ -426,9 +468,9 @@ var _bindata = map[string]func() (*asset, error){ // img/ // a.png // b.png -// then AssetDir("data") would return []string{"foo.txt", "img"} -// AssetDir("data/img") would return []string{"a.png", "b.png"} -// AssetDir("foo.txt") and AssetDir("nonexistent") would return an error +// then AssetDir("data") would return []string{"foo.txt", "img"}, +// AssetDir("data/img") would return []string{"a.png", "b.png"}, +// AssetDir("foo.txt") and AssetDir("notexist") would return an error, and // AssetDir("") will return []string{"data"}. func AssetDir(name string) ([]string, error) { node := _bintree @@ -483,7 +525,7 @@ var _bintree = &bintree{nil, map[string]*bintree{ }}, }} -// RestoreAsset restores an asset under the given directory +// RestoreAsset restores an asset under the given directory. func RestoreAsset(dir, name string) error { data, err := Asset(name) if err != nil { @@ -501,14 +543,10 @@ func RestoreAsset(dir, name string) error { if err != nil { return err } - err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) - if err != nil { - return err - } - return nil + return os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) } -// RestoreAssets restores an asset under the given directory recursively +// RestoreAssets restores an asset under the given directory recursively. func RestoreAssets(dir, name string) error { children, err := AssetDir(name) // File diff --git a/go.mod b/go.mod index 900c8e2..423f05c 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fatih/color v1.7.0 github.com/ghodss/yaml v1.0.0 + github.com/gobwas/glob v0.2.3 github.com/gogo/protobuf v1.3.1 github.com/google/go-github/v30 v30.0.0 github.com/gorilla/mux v1.7.4 diff --git a/go.sum b/go.sum index 00ec9c8..669ff47 100644 --- a/go.sum +++ b/go.sum @@ -145,6 +145,7 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= diff --git a/pkg/events/handler.go b/pkg/events/handler.go index 27acb61..6ad82f6 100644 --- a/pkg/events/handler.go +++ b/pkg/events/handler.go @@ -319,14 +319,14 @@ func (whh *WebhookHandler) handleApplyResultCommentEvent( func (whh *WebhookHandler) getClusterClients( ctx context.Context, client pullreq.PullRequestClient, - clusterIDs []string, + selectedClusterGlobStrs []string, flags map[string]string, ) ([]cluster.ClusterClient, error) { clusterClients := []cluster.ClusterClient{} coveredClusters, err := client.GetCoveredClusters( whh.settings.Env, - clusterIDs, + selectedClusterGlobStrs, flags["subpath"], ) if err != nil { diff --git a/pkg/pullreq/client.go b/pkg/pullreq/client.go index e55c202..e748d5b 100644 --- a/pkg/pullreq/client.go +++ b/pkg/pullreq/client.go @@ -15,7 +15,7 @@ type PullRequestClient interface { // GetCoveredClusters gets the configs for all clusters "covered" by a pull request. GetCoveredClusters( env string, - selectedClusterIDs []string, + selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error) diff --git a/pkg/pullreq/diffs.go b/pkg/pullreq/diffs.go index a4a54b5..2ed64ab 100644 --- a/pkg/pullreq/diffs.go +++ b/pkg/pullreq/diffs.go @@ -7,6 +7,7 @@ import ( "sort" "strings" + "github.com/gobwas/glob" "github.com/google/go-github/v30/github" "github.com/segmentio/kubeapply/pkg/config" log "github.com/sirupsen/logrus" @@ -25,7 +26,7 @@ import ( // subpaths. // // There are a few overrides that adjust this behavior: -// 1. selectedClusterIDs: If set, then clusters in this slice are never dropped, even if they +// 1. selectedClusterGlobStrs: If set, then clusters in this slice are never dropped, even if they // don't have have any diffs in them. // 2. subpathOverride: If set, then this is used for the cluster subpaths instead of the procedure // in step 6 above. @@ -33,13 +34,18 @@ func GetCoveredClusters( repoRoot string, diffs []*github.CommitFile, env string, - selectedClusterIDs []string, + selectedClusterGlobStrs []string, subpathOverride string, multiSubpaths bool, ) ([]*config.ClusterConfig, error) { - selectedClusterIDsMap := map[string]struct{}{} - for _, selectedClusterID := range selectedClusterIDs { - selectedClusterIDsMap[selectedClusterID] = struct{}{} + selectedClusterGlobs := []glob.Glob{} + + for _, globStr := range selectedClusterGlobStrs { + globObj, err := glob.Compile(globStr) + if err != nil { + return nil, err + } + selectedClusterGlobs = append(selectedClusterGlobs, globObj) } changedClusterPaths := map[string][]string{} @@ -80,8 +86,17 @@ func GetCoveredClusters( log.Infof("Found cluster config: %s", path) - if len(selectedClusterIDsMap) > 0 { - if _, ok := selectedClusterIDsMap[configObj.DescriptiveName()]; !ok { + if len(selectedClusterGlobs) > 0 { + var matches bool + + for _, globObj := range selectedClusterGlobs { + if globObj.Match(configObj.DescriptiveName()) { + matches = true + break + } + } + + if !matches { log.Infof( "Ignoring cluster %s because selectedClusters is set and cluster is not in set", configObj.DescriptiveName(), @@ -118,7 +133,7 @@ func GetCoveredClusters( return err } - if len(selectedClusterIDsMap) > 0 { + if len(selectedClusterGlobs) > 0 { changedClusterPaths[relPath] = []string{} } diff --git a/pkg/pullreq/diffs_test.go b/pkg/pullreq/diffs_test.go index a3f64cc..33c6f86 100644 --- a/pkg/pullreq/diffs_test.go +++ b/pkg/pullreq/diffs_test.go @@ -11,12 +11,12 @@ import ( func TestGetCoveredClusters(t *testing.T) { type clusterTestCase struct { - diffs []*github.CommitFile - selectedClusterIDs []string - subpathOverride string - multiSubpaths bool - expectedClustersIDs []string - expectedSubpaths []string + diffs []*github.CommitFile + selectedClusterGlobStrs []string + subpathOverride string + multiSubpaths bool + expectedClustersIDs []string + expectedSubpaths []string } testCases := []clusterTestCase{ @@ -104,7 +104,7 @@ func TestGetCoveredClusters(t *testing.T) { Filename: aws.String("clusters/clustertype/expanded/cluster2/file2.yaml"), }, }, - selectedClusterIDs: []string{ + selectedClusterGlobStrs: []string{ "stage:us-west-2:cluster1", "production:us-west-2:cluster2", "stage:us-west-2:cluster3", @@ -130,7 +130,29 @@ func TestGetCoveredClusters(t *testing.T) { Filename: aws.String("clusters/clustertype/expanded/cluster2/file2.yaml"), }, }, - selectedClusterIDs: []string{ + selectedClusterGlobStrs: []string{ + "stage:*1", + }, + expectedClustersIDs: []string{ + "stage:us-west-2:cluster1", + }, + expectedSubpaths: []string{ + ".", + }, + }, + { + diffs: []*github.CommitFile{ + { + Filename: aws.String("clusters/clustertype/expanded/cluster1/file1.yaml"), + }, + { + Filename: aws.String("clusters/clustertype/expanded/cluster1/subdir1/file3.yaml"), + }, + { + Filename: aws.String("clusters/clustertype/expanded/cluster2/file2.yaml"), + }, + }, + selectedClusterGlobStrs: []string{ "stage:us-west-2:cluster3", }, expectedClustersIDs: []string{ @@ -148,7 +170,7 @@ func TestGetCoveredClusters(t *testing.T) { "testdata/repo", testCase.diffs, "stage", - testCase.selectedClusterIDs, + testCase.selectedClusterGlobStrs, testCase.subpathOverride, testCase.multiSubpaths, ) diff --git a/pkg/pullreq/fake_client.go b/pkg/pullreq/fake_client.go index 7eedcd4..049e19f 100644 --- a/pkg/pullreq/fake_client.go +++ b/pkg/pullreq/fake_client.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/gobwas/glob" "github.com/segmentio/kubeapply/pkg/config" ) @@ -31,19 +32,32 @@ func (prc *FakePullRequestClient) Init(ctx context.Context) error { // this pull request. func (prc *FakePullRequestClient) GetCoveredClusters( env string, - selectedClusterIDs []string, + selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error) { - selectedClusterIDsMap := map[string]struct{}{} - for _, selectedClusterID := range selectedClusterIDs { - selectedClusterIDsMap[selectedClusterID] = struct{}{} + globObjs := []glob.Glob{} + + for _, globStr := range selectedClusterGlobStrs { + globObj, err := glob.Compile(globStr) + if err != nil { + return nil, err + } + globObjs = append(globObjs, globObj) } coveredClusters := []*config.ClusterConfig{} for _, clusterConfig := range prc.ClusterConfigs { - if len(selectedClusterIDsMap) > 0 { - if _, ok := selectedClusterIDsMap[clusterConfig.DescriptiveName()]; !ok { + if len(globObjs) > 0 { + var matches bool + for _, globObj := range globObjs { + if globObj.Match(clusterConfig.DescriptiveName()) { + matches = true + break + } + } + + if !matches { continue } } diff --git a/pkg/pullreq/github_client.go b/pkg/pullreq/github_client.go index f9cfa33..9f37ab1 100644 --- a/pkg/pullreq/github_client.go +++ b/pkg/pullreq/github_client.go @@ -232,14 +232,14 @@ func (prc *GHPullRequestClient) Init(ctx context.Context) error { // this pull request. func (prc *GHPullRequestClient) GetCoveredClusters( env string, - selectedClusterIDs []string, + selectedClusterGlobStrs []string, subpathOverride string, ) ([]*config.ClusterConfig, error) { return GetCoveredClusters( prc.clonePath, prc.files, env, - selectedClusterIDs, + selectedClusterGlobStrs, subpathOverride, true, ) From 8042e796133a045184186056453142a50c10d3a2 Mon Sep 17 00:00:00 2001 From: Benjamin Yolken Date: Fri, 19 Mar 2021 14:27:22 -0700 Subject: [PATCH 2/3] Update Dockerfile.lambda --- Dockerfile.lambda | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile.lambda b/Dockerfile.lambda index 99c55b8..c82dc94 100644 --- a/Dockerfile.lambda +++ b/Dockerfile.lambda @@ -31,11 +31,14 @@ RUN yum install -y git RUN curl -O https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py RUN pip3 install awscli -COPY --from=builder /usr/local/bin/aws-iam-authenticator /usr/local/bin/aws-iam-authenticator -COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm -COPY --from=builder /usr/local/bin/kubeval /usr/local/bin/kubeval -COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl -COPY --from=builder /usr/local/bin/kubeapply /usr/local/bin/kubeapply +COPY --from=builder \ + /usr/local/bin/aws-iam-authenticator \ + /usr/local/bin/helm \ + /usr/local/bin/kubeval \ + /usr/local/bin/kubectl \ + /usr/local/bin/kubeapply \ + /usr/local/bin/ + COPY --from=builder /usr/local/bin/kubeapply-lambda /var/task/kubeapply-lambda CMD [ "kubeapply-lambda" ] From a58ccca4dc4dda51059386403d9543736dc4a6e3 Mon Sep 17 00:00:00 2001 From: Benjamin Yolken Date: Fri, 19 Mar 2021 15:22:38 -0700 Subject: [PATCH 3/3] Bump version --- pkg/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/version/version.go b/pkg/version/version.go index af9a452..b44ff56 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ package version // Version stores the current kubeapply version. -const Version = "0.0.28" +const Version = "0.0.29"