Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Dockerfile.lambda
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
192 changes: 115 additions & 77 deletions data/data.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pullreq/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
31 changes: 23 additions & 8 deletions pkg/pullreq/diffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,21 +26,26 @@ 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.
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{}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -118,7 +133,7 @@ func GetCoveredClusters(
return err
}

if len(selectedClusterIDsMap) > 0 {
if len(selectedClusterGlobs) > 0 {
changedClusterPaths[relPath] = []string{}
}

Expand Down
40 changes: 31 additions & 9 deletions pkg/pullreq/diffs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand All @@ -148,7 +170,7 @@ func TestGetCoveredClusters(t *testing.T) {
"testdata/repo",
testCase.diffs,
"stage",
testCase.selectedClusterIDs,
testCase.selectedClusterGlobStrs,
testCase.subpathOverride,
testCase.multiSubpaths,
)
Expand Down
26 changes: 20 additions & 6 deletions pkg/pullreq/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/gobwas/glob"
"github.com/segmentio/kubeapply/pkg/config"
)

Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/pullreq/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// Version stores the current kubeapply version.
const Version = "0.0.28"
const Version = "0.0.29"