diff --git a/Makefile b/Makefile index 1c3fc4d4..e87af348 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ e2e-test: KUBECONFIG=$(KUBECONFIG_PATH) \ REGION=$(LINODE_REGION) \ LINODE_TOKEN=$(LINODE_TOKEN) \ - chainsaw test e2e/test + chainsaw test e2e/test --parallel 2 ##################################################################### # OS / ARCH diff --git a/e2e/test/fw-use-specified-nb/chainsaw-test.yaml b/e2e/test/fw-use-specified-nb/chainsaw-test.yaml new file mode 100644 index 00000000..9b1668a4 --- /dev/null +++ b/e2e/test/fw-use-specified-nb/chainsaw-test.yaml @@ -0,0 +1,123 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: fw-use-specified-nb +spec: + bindings: + - name: fwname + value: (join('-', ['ccm-fwtest', env('CLUSTER_NAME')])) + namespace: "fw-use-specified-nb" + steps: + - name: Check if CCM is deployed + try: + - assert: + file: ../assert-ccm-resources.yaml + - name: Create firewall, Create pods and services + try: + - script: + env: + - name: FWLABEL + value: ($fwname) + content: | + set -e + + create_fw=$(curl -s --write-out "%{http_code}\n" --output /dev/null --request POST \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + -H "accept: application/json" \ + "https://api.linode.com/v4/networking/firewalls" \ + --data " + { + \"label\": \"$FWLABEL\", + \"rules\": { + \"inbound\": [{ + \"action\": \"ACCEPT\", + \"label\": \"inbound-rule123\", + \"description\": \"inbound rule123\", + \"ports\": \"4321\", + \"protocol\": \"TCP\", + \"addresses\": { + \"ipv4\": [\"0.0.0.0/0\"] + } + }], + \"inbound_policy\": \"ACCEPT\", + \"outbound_policy\": \"ACCEPT\" + } + } + " + ) + + if [[ $create_fw == "200" ]]; then + echo "fw created" + fi + check: + ($error == null): true + (contains($stdout, 'fw created')): true + - apply: + file: create-pods-services.yaml + catch: + - describe: + apiVersion: v1 + kind: Pod + - describe: + apiVersion: v1 + kind: Service + - name: Check that loadbalancer ip is assigned + try: + - assert: + resource: + apiVersion: v1 + kind: Service + metadata: + name: svc-test + status: + (loadBalancer.ingress[0].ip != null): true + - name: Annotate service with nodebalancer id + try: + - script: + env: + - name: FWLABEL + value: ($fwname) + content: | + set -e + re='^[0-9]+$' + + fwid=$(curl -s \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + -H "X-Filter: {\"label\": \"$FWLABEL\"}" \ + "https://api.linode.com/v4/networking/firewalls" | jq .data[].id) + + if ! [[ $fwid =~ $re ]]; then + echo "Firewall id [$fwid] is incorrect, failed to fetch firewall" + exit 1 + fi + + kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-firewall-id=$fwid + sleep 5 + + for i in {1..10}; do + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) + + fwconfig=$(curl -s \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + "https://api.linode.com/v4/networking/firewalls/$fwid") + + fw_attached_to_nb=$(echo $fwconfig | jq ".entities[] | select(.id == $nbid) | .id == $nbid") + + if [[ $fw_attached_to_nb == "true" ]]; then + echo "Conditions met" + break + fi + + sleep 10 + done + + curl -s -X DELETE \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + "https://api.linode.com/v4/networking/firewalls/$fwid" + check: + (contains($stdout, 'Conditions met')): true diff --git a/e2e/test/fw-use-specified-nb/create-pods-services.yaml b/e2e/test/fw-use-specified-nb/create-pods-services.yaml new file mode 100644 index 00000000..00113a2f --- /dev/null +++ b/e2e/test/fw-use-specified-nb/create-pods-services.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: fw-use-specified-nb + name: test +spec: + replicas: 1 + selector: + matchLabels: + app: fw-use-specified-nb + template: + metadata: + labels: + app: fw-use-specified-nb + spec: + containers: + - image: appscode/test-server:2.3 + name: test + ports: + - name: http-1 + containerPort: 8080 + protocol: TCP + env: + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + name: svc-test + labels: + app: fw-use-specified-nb +spec: + type: LoadBalancer + selector: + app: fw-use-specified-nb + ports: + - name: http-1 + protocol: TCP + port: 80 + targetPort: 8080 + sessionAffinity: None diff --git a/e2e/test/lb-created-with-new-nb-id/chainsaw-test.yaml b/e2e/test/lb-created-with-new-nb-id/chainsaw-test.yaml index 198de73c..d3b48f83 100644 --- a/e2e/test/lb-created-with-new-nb-id/chainsaw-test.yaml +++ b/e2e/test/lb-created-with-new-nb-id/chainsaw-test.yaml @@ -62,21 +62,8 @@ spec: content: | set -e - re='^[0-9]+$' - expectedId=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .metadata.annotations[]) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $expectedId ]]; then echo "Condition met" @@ -110,18 +97,7 @@ spec: kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid for i in {1..10}; do - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid2=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid2 =~ $re ]]; then - echo "Nodebalancer id [$nbid2] is incorrect, failed to fetch nodebalancer" - exit 1 - fi + nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $nbid2 ]]; then echo "Condition met" diff --git a/e2e/test/lb-created-with-specified-nb-id/chainsaw-test.yaml b/e2e/test/lb-created-with-specified-nb-id/chainsaw-test.yaml index 732152e5..0958cc8b 100644 --- a/e2e/test/lb-created-with-specified-nb-id/chainsaw-test.yaml +++ b/e2e/test/lb-created-with-specified-nb-id/chainsaw-test.yaml @@ -62,21 +62,8 @@ spec: content: | set -e - re='^[0-9]+$' - expectedId=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .metadata.annotations[]) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $expectedId ]]; then echo "Condition met" diff --git a/e2e/test/lb-delete-svc-no-nb/chainsaw-test.yaml b/e2e/test/lb-delete-svc-no-nb/chainsaw-test.yaml index 11ef0358..f8ca55c4 100644 --- a/e2e/test/lb-delete-svc-no-nb/chainsaw-test.yaml +++ b/e2e/test/lb-delete-svc-no-nb/chainsaw-test.yaml @@ -62,21 +62,8 @@ spec: content: | set -e - re='^[0-9]+$' - expectedId=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .metadata.annotations[]) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $expectedId ]]; then echo "Condition met" @@ -119,7 +106,7 @@ spec: fi # Delete service and make sure its deleted - kubectl delete svc svc-test -n $NAMESPACE --timeout=60s + kubectl --timeout=60s delete svc svc-test -n $NAMESPACE for i in {1..10}; do if kubectl get svc svc-test -n $NAMESPACE > /dev/null 2>&1; then diff --git a/e2e/test/lb-delete-svc-use-new-nbid/chainsaw-test.yaml b/e2e/test/lb-delete-svc-use-new-nbid/chainsaw-test.yaml index f5a17c56..f9b21e3d 100644 --- a/e2e/test/lb-delete-svc-use-new-nbid/chainsaw-test.yaml +++ b/e2e/test/lb-delete-svc-use-new-nbid/chainsaw-test.yaml @@ -62,21 +62,8 @@ spec: content: | set -e - re='^[0-9]+$' - expectedId=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .metadata.annotations[]) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $expectedId ]]; then echo "Condition met" @@ -110,18 +97,7 @@ spec: kubectl annotate --overwrite svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid for i in {1..10}; do - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid2=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid2 =~ $re ]]; then - echo "Nodebalancer id [$nbid2] is incorrect, failed to fetch nodebalancer" - exit 1 - fi + nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $nbid2 ]]; then echo "Condition met" diff --git a/e2e/test/lb-delete-svc-use-specified-nb/chainsaw-test.yaml b/e2e/test/lb-delete-svc-use-specified-nb/chainsaw-test.yaml index 8c5480f3..cdcb3fc6 100644 --- a/e2e/test/lb-delete-svc-use-specified-nb/chainsaw-test.yaml +++ b/e2e/test/lb-delete-svc-use-specified-nb/chainsaw-test.yaml @@ -62,21 +62,8 @@ spec: content: | set -e - re='^[0-9]+$' - expectedId=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .metadata.annotations[]) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $expectedId ]]; then echo "Condition met" diff --git a/e2e/test/lb-http-body-health-check/chainsaw-test.yaml b/e2e/test/lb-http-body-health-check/chainsaw-test.yaml index 23b42af1..25a6e883 100644 --- a/e2e/test/lb-http-body-health-check/chainsaw-test.yaml +++ b/e2e/test/lb-http-body-health-check/chainsaw-test.yaml @@ -37,20 +37,7 @@ spec: content: | set -e - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect, doesn't meet regex requirements" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ diff --git a/e2e/test/lb-http-status-health-check/chainsaw-test.yaml b/e2e/test/lb-http-status-health-check/chainsaw-test.yaml index 58a5dff4..24b85471 100644 --- a/e2e/test/lb-http-status-health-check/chainsaw-test.yaml +++ b/e2e/test/lb-http-status-health-check/chainsaw-test.yaml @@ -37,20 +37,7 @@ spec: content: | set -e - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect, doesn't meet regex requirements" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ diff --git a/e2e/test/lb-passive-health-check/chainsaw-test.yaml b/e2e/test/lb-passive-health-check/chainsaw-test.yaml index dfd1438a..6bd87031 100644 --- a/e2e/test/lb-passive-health-check/chainsaw-test.yaml +++ b/e2e/test/lb-passive-health-check/chainsaw-test.yaml @@ -37,20 +37,7 @@ spec: content: | set -e - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect, doesn't meet regex requirements" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ diff --git a/e2e/test/lb-preserve-annotation-new-nb-specified/chainsaw-test.yaml b/e2e/test/lb-preserve-annotation-new-nb-specified/chainsaw-test.yaml index 3ed2ecb1..d7f2661d 100644 --- a/e2e/test/lb-preserve-annotation-new-nb-specified/chainsaw-test.yaml +++ b/e2e/test/lb-preserve-annotation-new-nb-specified/chainsaw-test.yaml @@ -40,18 +40,7 @@ spec: re='^[0-9]+$' # Get existing nodebalancer id - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - old_nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $old_nbid =~ $re ]]; then - echo "Nodebalancer id [$old_nbid] is incorrect" - exit 1 - fi + old_nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) # Create new nodebalancer and use it LABEL="ccm-$(head /dev/urandom | tr -dc 'a-z0-9' | head -c 5)" @@ -71,18 +60,7 @@ spec: kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid for i in {1..10}; do - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid2=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid2 =~ $re ]]; then - echo "Nodebalancer id [$nbid2] is incorrect, failed to fetch nodebalancer" - exit 1 - fi + nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) if [[ $nbid == $nbid2 ]]; then echo "updated nodebalancer used" @@ -97,8 +75,6 @@ spec: -H "Authorization: Bearer $LINODE_TOKEN" \ "https://api.linode.com/v4/nodebalancers/$old_nbid") - echo $old_nbid - echo $old_nb_resp if [[ $old_nb_resp == "200" ]]; then echo "old nodebalancer found" fi diff --git a/e2e/test/lb-preserve-annotation-svc-delete/chainsaw-test.yaml b/e2e/test/lb-preserve-annotation-svc-delete/chainsaw-test.yaml index e90da8fc..978860ec 100644 --- a/e2e/test/lb-preserve-annotation-svc-delete/chainsaw-test.yaml +++ b/e2e/test/lb-preserve-annotation-svc-delete/chainsaw-test.yaml @@ -37,23 +37,11 @@ spec: content: | set -e - re='^[0-9]+$' + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi - - kubectl -n $NAMESPACE delete deploy test --timeout=60s - kubectl -n $NAMESPACE delete svc svc-test --timeout=60s + kubectl --timeout=60s -n $NAMESPACE delete deploy test + kubectl --timeout=60s -n $NAMESPACE delete svc svc-test + sleep 20 get_resp=$(curl --write-out "%{http_code}\n" \ --silent --output /dev/null \ diff --git a/e2e/test/lb-tcp-connection-health-check/chainsaw-test.yaml b/e2e/test/lb-tcp-connection-health-check/chainsaw-test.yaml index 32822bc1..d2e2b855 100644 --- a/e2e/test/lb-tcp-connection-health-check/chainsaw-test.yaml +++ b/e2e/test/lb-tcp-connection-health-check/chainsaw-test.yaml @@ -37,20 +37,7 @@ spec: content: | set -e - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect, doesn't meet regex requirements" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ diff --git a/e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml b/e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml index bd129310..0350e20d 100644 --- a/e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml +++ b/e2e/test/lb-updated-with-nb-id/chainsaw-test.yaml @@ -48,28 +48,21 @@ spec: --data "{\"label\": \"$LABEL\", \"region\": \"$REGION\"}" | jq .id) if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect, failed to create nodebalancer" + echo "Nodebalancer id [$nbid] for label [$lABEL] is incorrect, failed to create nodebalancer" exit 1 fi kubectl annotate svc svc-test -n $NAMESPACE service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id=$nbid - sleep 30 + sleep 5 - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid2=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid2 =~ $re ]]; then - echo "Nodebalancer id [$nbid2] is incorrect, failed to fetch nodebalancer" - exit 1 - fi + for i in {1..10}; do + nbid2=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) - if [[ $nbid == $nbid2 ]]; then - echo "Condition met" - fi + if [[ $nbid == $nbid2 ]]; then + echo "Condition met" + break + fi + sleep 10 + done check: (contains($stdout, 'Condition met')): true diff --git a/e2e/test/lb-with-node-addition/chainsaw-test.yaml b/e2e/test/lb-with-node-addition/chainsaw-test.yaml index f6acdd3a..52c847e2 100644 --- a/e2e/test/lb-with-node-addition/chainsaw-test.yaml +++ b/e2e/test/lb-with-node-addition/chainsaw-test.yaml @@ -37,26 +37,13 @@ spec: content: | set -e - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ -H "Authorization: Bearer $LINODE_TOKEN" \ -H "Content-Type: application/json" \ - "https://api.linode.com/v4/nodebalancers/$nbid/configs" | jq '.data[] | select(.port == 80)') + "https://api.linode.com/v4/nodebalancers/$nbid/configs" | jq '.data[]? | select(.port == 80)') if [[ -z $nbconfig ]]; then echo "Failed fetching nodebalancer config for port 80" @@ -84,26 +71,13 @@ spec: sleep 180 - re='^[0-9]+$' - - hostname=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) - ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') - nbid=$(curl -s \ - -H "Authorization: Bearer $LINODE_TOKEN" \ - -H "Content-Type: application/json" \ - -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) - - if ! [[ $nbid =~ $re ]]; then - echo "Nodebalancer id [$nbid] is incorrect" - exit 1 - fi + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) for i in {1..10}; do nbconfig=$(curl -s \ -H "Authorization: Bearer $LINODE_TOKEN" \ -H "Content-Type: application/json" \ - "https://api.linode.com/v4/nodebalancers/$nbid/configs" | jq '.data[] | select(.port == 80)') + "https://api.linode.com/v4/nodebalancers/$nbid/configs" | jq '.data[]? | select(.port == 80)') if [[ -z $nbconfig ]]; then echo "Failed fetching nodebalancer config for port 80" @@ -122,4 +96,3 @@ spec: check: ($error == null): true (contains($stdout, 'all nodes up')): true - diff --git a/e2e/test/lb-with-proxyprotocol-override/chainsaw-test.yaml b/e2e/test/lb-with-proxyprotocol-override/chainsaw-test.yaml index 51848d4a..54600a49 100644 --- a/e2e/test/lb-with-proxyprotocol-override/chainsaw-test.yaml +++ b/e2e/test/lb-with-proxyprotocol-override/chainsaw-test.yaml @@ -53,7 +53,7 @@ spec: -H "Authorization: Bearer $LINODE_TOKEN" \ -H "Content-Type: application/json" \ -H "X-Filter: {\"ipv4\": \"$ip\"}" \ - "https://api.linode.com/v4/nodebalancers" | jq .data[].id) + "https://api.linode.com/v4/nodebalancers" | jq .data[].id) if ! [[ $nbid =~ $re ]]; then echo "Nodebalancer id [$nbid] is incorrect, doesn't meet regex requirements" diff --git a/e2e/test/scripts/get-nb-id.sh b/e2e/test/scripts/get-nb-id.sh new file mode 100755 index 00000000..a10632c9 --- /dev/null +++ b/e2e/test/scripts/get-nb-id.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +re='^[0-9]+$' + +hostname=$(kubectl --timeout=60s get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].hostname) +ip=$(echo $hostname | awk -F'.' '{gsub("-", ".", $1); print $1}') +nbid=$(curl -s \ + -H "Authorization: Bearer $LINODE_TOKEN" \ + -H "Content-Type: application/json" \ + -H "X-Filter: {\"ipv4\": \"$ip\"}" \ + "https://api.linode.com/v4/nodebalancers" | jq .data[].id) + +if ! [[ $nbid =~ $re ]]; then + echo "Nodebalancer id [$nbid] is incorrect" + exit 1 +fi + +echo $nbid