@@ -9,6 +9,24 @@ metadata:
99spec :
1010 namespace : " lb-created-with-new-nb-id"
1111 steps :
12+ - name : Create dummy service
13+ try :
14+ - apply :
15+ file : dummy-service.yaml
16+ catch :
17+ - describe :
18+ apiVersion : v1
19+ kind : Service
20+ - name : Check that loadbalancer ip is assigned
21+ try :
22+ - assert :
23+ resource :
24+ apiVersion : v1
25+ kind : Service
26+ metadata :
27+ name : svc-dummy
28+ status :
29+ (loadBalancer.ingress[0].ip != null) : true
1230 - name : Create nodebalancer and create resources
1331 try :
1432 - script :
@@ -21,12 +39,28 @@ spec:
2139 re='^[0-9]+$'
2240 LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
2341
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+ "https://api.linode.com/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
57+
2458 nbid=$(curl -s --request POST \
2559 -H "Authorization: Bearer $LINODE_TOKEN" \
2660 -H "Content-Type: application/json" \
2761 -H "accept: application/json" \
28- "https://api.linode.com/v4 /nodebalancers" \
29- --data "{\"label\": \"$LABEL\", \"region\": \"$REGION\"} " | jq .id)
62+ "https://api.linode.com/v4beta /nodebalancers" \
63+ --data "$data " | jq .id)
3064
3165 if ! [[ $nbid =~ $re ]]; then
3266 echo "Nodebalancer id [$nbid] is incorrect, failed to create nodebalancer"
@@ -82,30 +116,46 @@ spec:
82116
83117 LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)"
84118
119+ # Get VPC config if it exists
120+ vpcconfig=$(curl -s \
121+ -H "Authorization: Bearer $LINODE_TOKEN" \
122+ -H "Content-Type: application/json" \
123+ "https://api.linode.com/v4beta/nodebalancers/$old_nbid/vpcs")
124+
125+ echo "Old Nodebalancer ID: $old_nbid"
126+ echo "VPC config: $vpcconfig"
127+
128+ SUBNET_ID=$(echo $vpcconfig | jq -r ".data[] | select(.nodebalancer_id == $old_nbid) | .subnet_id")
129+ echo "Subnet ID: $SUBNET_ID"
130+
131+ data="{\"label\": \"$LABEL\", \"region\": \"$REGION\", \"vpcs\": [{\"subnet_id\": $SUBNET_ID}]}"
132+ if [[ -z $SUBNET_ID ]]; then
133+ data="{\"label\": \"$LABEL\", \"region\": \"$REGION\"}"
134+ fi
135+
85136 nbid=$(curl -s --request POST \
86137 -H "Authorization: Bearer $LINODE_TOKEN" \
87138 -H "Content-Type: application/json" \
88139 -H "accept: application/json" \
89- "https://api.linode.com/v4 /nodebalancers" \
90- --data "{\"label\": \"$LABEL\", \"region\": \"$REGION\"} " | jq .id)
140+ "https://api.linode.com/v4beta /nodebalancers" \
141+ --data "$data " | jq .id)
91142
92143 if ! [[ $nbid =~ $re ]]; then
93144 echo "Nodebalancer id [$nbid] is incorrect, failed to create nodebalancer"
94- exit 1
145+ else
146+ kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid
147+
148+ for i in {1..10}; do
149+ nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
150+
151+ if [[ $nbid == $nbid2 ]]; then
152+ echo "Condition met"
153+ break
154+ fi
155+ sleep 5
156+ done
95157 fi
96158
97- kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid
98-
99- for i in {1..10}; do
100- nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
101-
102- if [[ $nbid == $nbid2 ]]; then
103- echo "Condition met"
104- break
105- fi
106- sleep 5
107- done
108-
109159 old_nb_resp=$(curl --write-out "%{http_code}\n" \
110160 --silent --output /dev/null \
111161 -H "Authorization: Bearer $LINODE_TOKEN" \
0 commit comments