Skip to content

Commit dcb5950

Browse files
author
Rahul Sharma
committed
move repeated code to separate script
1 parent be69ff5 commit dcb5950

File tree

8 files changed

+55
-94
lines changed

8 files changed

+55
-94
lines changed

e2e/test/lb-created-with-new-nb-id/chainsaw-test.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ spec:
3939
re='^[0-9]+$'
4040
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4141
42-
# Get existing dummy nodebalancer id to get VPC config
43-
dummy_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh svc-dummy)
44-
45-
# Get VPC config if it exists
46-
vpcconfig=$(curl -s \
47-
-H "Authorization: Bearer $LINODE_TOKEN" \
48-
-H "Content-Type: application/json" \
49-
"$LINODE_URL/v4beta/nodebalancers/$dummy_nbid/vpcs")
50-
51-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $dummy_nbid) | .subnet_id")
52-
53-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
54-
if [[ -z $SUBNET_ID ]]; then
55-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
56-
fi
42+
# Get data to use for new nodebalancer
43+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-dummy)
5744
5845
nbid=$(curl -s --request POST \
5946
-H "Authorization: Bearer $LINODE_TOKEN" \

e2e/test/lb-created-with-specified-nb-id/chainsaw-test.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ spec:
3939
re='^[0-9]+$'
4040
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4141
42-
# Get existing dummy nodebalancer id to get VPC config
43-
dummy_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh svc-dummy)
44-
45-
# Get VPC config if it exists
46-
vpcconfig=$(curl -s \
47-
-H "Authorization: Bearer $LINODE_TOKEN" \
48-
-H "Content-Type: application/json" \
49-
"$LINODE_URL/v4beta/nodebalancers/$dummy_nbid/vpcs")
50-
51-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $dummy_nbid) | .subnet_id")
52-
53-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
54-
if [[ -z $SUBNET_ID ]]; then
55-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
56-
fi
42+
# Get data to use for new nodebalancer
43+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-dummy)
5744
5845
nbid=$(curl -s --request POST \
5946
-H "Authorization: Bearer $LINODE_TOKEN" \

e2e/test/lb-delete-svc-no-nb/chainsaw-test.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ spec:
3939
re='^[0-9]+$'
4040
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4141
42-
# Get existing dummy nodebalancer id to get VPC config
43-
dummy_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh svc-dummy)
44-
45-
# Get VPC config if it exists
46-
vpcconfig=$(curl -s \
47-
-H "Authorization: Bearer $LINODE_TOKEN" \
48-
-H "Content-Type: application/json" \
49-
"$LINODE_URL/v4beta/nodebalancers/$dummy_nbid/vpcs")
50-
51-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $dummy_nbid) | .subnet_id")
52-
53-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
54-
if [[ -z $SUBNET_ID ]]; then
55-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
56-
fi
42+
# Get data to use for new nodebalancer
43+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-dummy)
5744
5845
nbid=$(curl -s --request POST \
5946
-H "Authorization: Bearer $LINODE_TOKEN" \

e2e/test/lb-delete-svc-use-new-nbid/chainsaw-test.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ spec:
3939
re='^[0-9]+$'
4040
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4141
42-
# Get existing dummy nodebalancer id to get VPC config
43-
dummy_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh svc-dummy)
44-
45-
# Get VPC config if it exists
46-
vpcconfig=$(curl -s \
47-
-H "Authorization: Bearer $LINODE_TOKEN" \
48-
-H "Content-Type: application/json" \
49-
"$LINODE_URL/v4beta/nodebalancers/$dummy_nbid/vpcs")
50-
51-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $dummy_nbid) | .subnet_id")
52-
53-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
54-
if [[ -z $SUBNET_ID ]]; then
55-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
56-
fi
42+
# Get data to use for new nodebalancer
43+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-dummy)
5744
5845
nbid=$(curl -s --request POST \
5946
-H "Authorization: Bearer $LINODE_TOKEN" \

e2e/test/lb-delete-svc-use-specified-nb/chainsaw-test.yaml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,8 @@ spec:
3939
re='^[0-9]+$'
4040
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4141
42-
# Get existing dummy nodebalancer id to get VPC config
43-
dummy_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh svc-dummy)
44-
45-
# Get VPC config if it exists
46-
vpcconfig=$(curl -s \
47-
-H "Authorization: Bearer $LINODE_TOKEN" \
48-
-H "Content-Type: application/json" \
49-
"$LINODE_URL/v4beta/nodebalancers/$dummy_nbid/vpcs")
50-
51-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $dummy_nbid) | .subnet_id")
52-
53-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
54-
if [[ -z $SUBNET_ID ]]; then
55-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
56-
fi
42+
# Get data to use for new nodebalancer
43+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-dummy)
5744
5845
nbid=$(curl -s --request POST \
5946
-H "Authorization: Bearer $LINODE_TOKEN" \

e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,8 @@ spec:
4040
re='^[0-9]+$'
4141
LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
4242
43-
# Get existing nodebalancer id
44-
old_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
45-
46-
# Get VPC config for the old nodebalancer if it exists
47-
vpcconfig=$(curl -s \
48-
-H "Authorization: Bearer $LINODE_TOKEN" \
49-
-H "Content-Type: application/json" \
50-
"$LINODE_URL/v4beta/nodebalancers/$old_nbid/vpcs")
51-
52-
echo "Nodebalancer ID: $old_nbid"
53-
echo "VPC config: $vpcconfig"
54-
55-
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $old_nbid) | .subnet_id")
56-
echo "Subnet ID: $SUBNET_ID"
57-
58-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
59-
if [[ -z $SUBNET_ID ]]; then
60-
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
61-
fi
43+
# Get data to use for new nodebalancer
44+
data=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN LABEL=$LABEL REGION=$REGION ../scripts/get-nb-create-data.sh svc-test)
6245
6346
nbid=$(curl -s --request POST \
6447
-H "Authorization: Bearer $LINODE_TOKEN" \
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR=$(dirname "$0")
6+
7+
svcname="svc-test"
8+
if [[ -n "$1" ]]; then
9+
svcname="$1"
10+
fi
11+
12+
# Get existing service's subnet id
13+
SUBNET_ID=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN $SCRIPT_DIR/get-nb-subnet-id.sh $svcname)
14+
15+
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
16+
if [[ -z $SUBNET_ID ]]; then
17+
data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
18+
fi
19+
20+
echo $data
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR=$(dirname "$0")
6+
7+
svcname="svc-test"
8+
if [[ -n "$1" ]]; then
9+
svcname="$1"
10+
fi
11+
12+
# Get existing dummy nodebalancer id to get VPC config
13+
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN $SCRIPT_DIR/get-nb-id.sh $svcname)
14+
15+
# Get VPC config if it exists
16+
vpcconfig=$(curl -s \
17+
-H "Authorization: Bearer $LINODE_TOKEN" \
18+
-H "Content-Type: application/json" \
19+
"$LINODE_URL/v4beta/nodebalancers/$nbid/vpcs")
20+
21+
SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $nbid) | .subnet_id")
22+
23+
echo $SUBNET_ID

0 commit comments

Comments
 (0)