Skip to content

Commit 5661689

Browse files
authored
CB-32728 AWS Region Exclude
1 parent cab6eec commit 5661689

40 files changed

Lines changed: 34752 additions & 4 deletions

aws/aws.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,15 @@ func getCFStacks(cloudType types.CloudType, cfClients map[string]cfClient) ([]*t
18391839
log.Debugf("[AWS] Processing stacks (%d) in region: %s: [%s]", len(stackResult.Stacks), region, stackResult.Stacks)
18401840
for _, s := range stackResult.Stacks {
18411841
stack := newStack(cloudType, s, region)
1842-
cfChan <- stack
1842+
if ctx.WorkaroundAwsIgnoreStack {
1843+
if !strings.HasPrefix(stack.Name, "StackSet-") {
1844+
cfChan <- stack
1845+
} else {
1846+
log.Infof("Ignoring stackset %s", stack.Name)
1847+
}
1848+
} else {
1849+
cfChan <- stack
1850+
}
18431851
}
18441852
if stackResult.NextToken != nil {
18451853
nextToken = *stackResult.NextToken
@@ -2508,7 +2516,7 @@ func getRegions(ec2Client ec2Client) ([]string, error) {
25082516
regions := make([]string, 0)
25092517
for _, region := range regionResult.Regions {
25102518
// CB-32728 Remove the me-south-1 region
2511-
if strings.EqualFold(*region.RegionName, "me-south-1") {
2519+
if ctx.AwsExcludedRegions[strings.ToLower(*region.RegionName)] {
25122520
log.Infof("[AWS] Skipping CloudFormation fetch from region: %s", *region.RegionName)
25132521
continue
25142522
}

context/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ var IgnoreLabelDisabled = false
4444
// ExactMatchOwner is a global flag for 'exact match' or 'starts with' matching of owner
4545
var ExactMatchOwner = false
4646

47+
var WorkaroundAwsIgnoreStack = false
48+
49+
var AwsExcludedRegions = make(map[string]bool)
50+
4751
// Operations contains all the available operations
4852
var Operations = make(map[types.OpType]types.Operation)
4953

main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"os"
66
"sort"
7+
"strings"
78

89
"github.com/hortonworks/cloud-haunter/utils"
910

@@ -38,9 +39,13 @@ func main() {
3839
verbose := flag.Bool("v", false, "verbose")
3940
ignoreLabelDisabled := flag.Bool("i", false, "disable ignore label")
4041
exactMatchOwner := flag.Bool("e", false, "exact match owner")
42+
workaroundAWsIgnoreStack := flag.Bool("awsignore", false, "AWS stack ignore workaround")
43+
excludedAwsRegions := flag.String("excludeAwsRegion", "", "comma separated list of AWS regions to exclude")
4144

4245
flag.Parse()
4346

47+
parseRegionsStr(*excludedAwsRegions)
48+
4449
if *help {
4550
printHelp()
4651
os.Exit(0)
@@ -53,6 +58,7 @@ func main() {
5358
}
5459
ctx.IgnoreLabelDisabled = *ignoreLabelDisabled
5560
ctx.ExactMatchOwner = *exactMatchOwner
61+
ctx.WorkaroundAwsIgnoreStack = *workaroundAWsIgnoreStack
5662

5763
if filterConfigLoc != nil && len(*filterConfigLoc) != 0 {
5864
var err error
@@ -119,6 +125,7 @@ func main() {
119125
items = filter.Execute(items)
120126
}
121127
action.Execute(*op, filterNames, items)
128+
println("All operations completed.")
122129
}
123130

124131
// should be kept in sync with README.md
@@ -182,3 +189,10 @@ func getSortedActions() []string {
182189
sort.Strings(actions)
183190
return actions
184191
}
192+
193+
func parseRegionsStr(regionsStr string) {
194+
regionList := strings.Split(regionsStr, ",")
195+
for _, item := range regionList {
196+
ctx.AwsExcludedRegions[strings.ToLower(item)] = true
197+
}
198+
}

release.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD)
88
rm -rf release
99
mkdir release
1010

11+
TAR=tar
12+
GREP=grep
13+
# On OS X refer to the gnu utils, they can be installed using brew
14+
if [[ $OSTYPE =~ "darwin" ]]; then
15+
TAR=gtar
16+
GREP=ggrep
17+
fi
18+
1119
declare -a Platforms=("Linux" "Darwin")
1220
for platform in ${Platforms[@]}; do
1321
if [ -d "./build/$platform" ]; then
1422
echo "Compressing the ${platform} relevant binary ..."
15-
tar -zcf "release/${NAME}_${VERSION}_${platform}_${ARCH}.tgz" -C build/$platform $BINARY
23+
$TAR -zcf "release/${NAME}_${VERSION}_${platform}_${ARCH}.tgz" -C build/$platform $BINARY
1624
fi
1725
done
1826

1927
echo "Creating release v${VERSION} from branch $BRANCH ..."
2028

21-
output=$(gh release list | grep ${VERSION})
29+
output=$(gh release list | $GREP ${VERSION})
2230
if [ -z "$output" ]; then
2331
gh release create "v${VERSION}" "./release/${NAME}_${VERSION}_Linux_${ARCH}.tgz" "./release/${NAME}_${VERSION}_Darwin_${ARCH}.tgz" -t ${VERSION} -n ""
2432
else

vendor/github.com/aws/aws-sdk-go/aws/arn/arn.go

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/aws/aws-sdk-go/internal/s3err/error.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)