Skip to content

Commit

Permalink
feat: added debug2 pod in default and modified echo to print for MacOs
Browse files Browse the repository at this point in the history
  • Loading branch information
vicenteherrera committed May 31, 2024
1 parent 3bc975c commit 2d3ad33
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions exercises/calico/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
## Test Calico GlobalNetworkPolicies and Kubernetes Network Policies
## ----------------------------------------------------------------------

all: reset create_ns install_web install_shell_pod ## Creates test namespace, redis and debug pod
all: reset create_ns install_web install_shell_pod install_shell_pod_default ## Creates test namespace, redis and debug pod
@$(MAKE) -s POD_LABEL="app=web" wait_pod_ready

help: ## Show this help.
@sed -ne '/@sed/!s/:.*##//p' $(MAKEFILE_LIST) | column -tl 2
@sed -ne '/@sed/!s/:.*##//p' $(MAKEFILE_LIST) | column -x 2

check_calico: ## Checks what Calico client and server version is running
calicoctl version
Expand All @@ -19,19 +19,28 @@ install_web: ## Deploys web server on current namespace
kubectl apply -f ./web.yaml

install_shell_pod: ## Deploy debug curl pod on current namespace
kubectl run debug --image=curlimages/curl --restart=Never --labels="app=web" -- sh -c 'while true; do nslookup web-service.test-net.svc.cluster.local ; i=0 ; while ! nc -zv web-service.test-net.svc.cluster.local 80 -w 1 && [ $$i -lt 7 ] ; do echo -n "." ; i=$$((i+1)) ; done ; done'
kubectl run debug --image=curlimages/curl --restart=Never --labels="app=web" -- sh -c \
'while true; do nslookup web-service.test-net.svc.cluster.local ; i=0 ; while ! nc -zv web-service.test-net.svc.cluster.local 80 -w 1 && [ $$i -lt 7 ] ; do printf "%s" "." ; i=$$((i+1)) ; done ; done'

install_shell_pod_default: ## Deploy debug curl pod on default namespace
kubectl run debug2 -n default --image=curlimages/curl --restart=Never --labels="app=web" -- sh -c \
'while true; do nslookup web-service.test-net.svc.cluster.local ; i=0 ; while ! nc -zv web-service.test-net.svc.cluster.local 80 -w 1 && [ $$i -lt 7 ] ; do printf "%s" "." ; i=$$((i+1)) ; done ; done'

# Test targets:

test_web:
@kubectl exec debug -it -- sh -c 'nslookup web-service.test-net.svc.cluster.local ; i=0 ; while ! nc -zv web-service.test-net.svc.cluster.local 80 -w 1 && [ $$i -lt 7 ] ; do echo -n "." ; i=$$((i+1)) ; done'
@kubectl exec debug -it -- sh -c \
'nslookup web-service.test-net.svc.cluster.local ; i=0 ; while ! nc -zv web-service.test-net.svc.cluster.local 80 -w 1 && [ $$i -lt 7 ] ; do printf "%s" "." ; i=$$((i+1)) ; done'

test_web2: ## Test connection from debug pod to web server
kubectl exec debug -it -- curl http://web-service.test-net.svc --insecure -s -o /dev/null -v --connect-timeout 5 --retry 5 --retry-max-time 120

test_kube_api: ## Test connection from debug pod to Kubernetes API
kubectl exec debug -it -- curl https://kubernetes.default.svc --insecure --connect-timeout 5

test_ingress_from_default:
kubectl

# Network policies

calico_install_ingress: ## Install Calico network policies from ingress/calico/
Expand Down Expand Up @@ -80,13 +89,14 @@ remove_label_ns: ## Removes label allow-egress from test namespace

reset: np_delete_all ## Reset the test, deleting the test namespace
kubens default
kubectl delete pod debug2 ||:
kubectl delete namespace test-net ||:

# Utils

wait_pod_ready:
@echo "Waiting pods with label ${POD_LABEL} to be running"
@while test "$$(kubectl get pods -l ${POD_LABEL} --field-selector=status.phase!=Running -oname)" != "" ; \
do echo -n "." && sleep 1; \
do printf "%s" "." && sleep 1; \
done; \
echo ""

0 comments on commit 2d3ad33

Please sign in to comment.