Skip to content

Commit

Permalink
Code cleanliness
Browse files Browse the repository at this point in the history
- Provider services now starts with an empty list to prevent
  unwanted services binding to the provider endpoint (cleanliness)
- Removed redundant code (cleanliness)
- run script with set -e
- Don't suppress errors whilst deleting the cluster
  • Loading branch information
mproffitt committed Apr 26, 2024
1 parent c9a3db6 commit fdfca84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
22 changes: 6 additions & 16 deletions localstack-kind.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -o pipefail
set -e -o pipefail

DEFAULT_PROVIDERS=(
"dynamodb"
Expand All @@ -21,11 +21,6 @@ if [ ! -z $LOCALSTACK_AUTH_TOKEN ]; then
)
fi

TOKEN_HEADER=""
if [ -n $GITHUB_TOKEN ]; then
TOKEN_HEADER=""
fi

function get_latest_version () {
local repo=$1
if [ -z $GITHUB_TOKEN ]; then
Expand Down Expand Up @@ -76,11 +71,14 @@ echo "Creating localstack cluster with the following crossplane providers:"
echo " ${DEFAULT_PROVIDERS[*]}"
echo

# Reset the providerconfig services list to empty
yq -ie '.spec.endpoint.services = []' providerconfig.yaml
for provider in "${DEFAULT_PROVIDERS[@]}"; do
if ! contains "function" $provider; then
yq -ie "with(.spec.endpoint.services; select(all_c(. != \"$provider\")) | . += [\"$provider\"])" providerconfig.yaml
fi
done

readonly timeout=90

function print_logs () {
Expand Down Expand Up @@ -221,20 +219,12 @@ export PATH=$PATH:$(pwd)/bin
cd ..
}

# I think this is a bit dangerous as it encompases altering system files, not
# owned by the current user. Probably better left out for now and have the user
# explicitly add it manually if they need to.
#
# if ! grep -q "localhost.localstack.cloud" /etc/hosts; then
# echo "Adding 'localhost.localstack.cloud' to /etc/hosts..."
# echo "$(ip route get 1.2.3.4 | awk '{print $7}') localhost.localstack.cloud" | sudo tee -a /etc/hosts
# fi

# Setup the kind cluster
header "Setting up kind cluster 'localstack'..."
{
if kind get clusters | grep -q localstack; then
echo "[kind] Deleting existing kind cluster 'localstack'..."
kind delete cluster -n localstack 2>/dev/null
kind delete cluster -n localstack 2>&1 | print_logs kind
fi
kind create cluster -n localstack --config kind.yaml
echo
Expand Down
8 changes: 3 additions & 5 deletions providerconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ metadata:
spec:
endpoint:
services:
- ec2
- s3
- rds
- dynamodb
- iam
- kms
- kinesis
- dynamodb
- lambda
- sqs
- sns
- rds
- eks
- kinesis
# Within localstack, all services are available behind localhost.localstack.cloud
# and this is the only name exposed via ingress
hostnameImmutable: true
Expand Down

0 comments on commit fdfca84

Please sign in to comment.