Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
added check for cluster-local or not
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien committed Jun 24, 2020
1 parent 70ed35a commit f7b9549
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions plugins/kn-curl/kn-curl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ Examples:
# Need at least the service name
if [ -z "$1" ]; then
echo "$USAGE"
exit 1
exit 0
fi

# If -h or --help is first argument
if [ "$1" == "-h" ] | [ "$1" == "--help" ]; then
echo "$USAGE"
exit 1
exit 0
fi

# Flags
Expand All @@ -48,13 +48,31 @@ NS="default"

# Parse arguments for -n or --namespace and namespace value
if [ "$N" == "$2" ] | [ "$NAMESPACE" == "$2" ]; then
NS="$3"
NS="$3"
fi

# Get INGRESS assuming Istio
# Get kubectl path
KUBECTL=`which kubectl`
if [ -z "$KUBECTL" ]; then
echo "$USAGE"
echo "kubectl must also be in your PATH"
exit 0
fi

# Get INGRESS assuming Istio
INGRESS=$($KUBECTL get svc istio-ingressgateway --namespace istio-system | awk '{print $4}' | tail +2)

# Perform curl of service
set -x
curl '-sS' '-H' 'Host: '"$1"'.'"$NS"'.example.com' 'http://'"$INGRESS"''
# Check if the servcice's cluster-local is on
CLUSTER_LOCAL=$($KUBECTL get ksvc $1 -o=jsonpath='{@.metadata.labels.serving\.knative\.dev\/visibility}')

# Get URL for the service
URL=$($KUBECTL get ksvc $1 --output=custom-columns=:.status.url)

# Perform curl of service either with CLUSTER_LOCAL or URL
if [ -z "$CLUSTER_LOCAL" ]; then
set -x
curl '-sS' $URL
else
set -x
curl '-sS' '-H' 'Host: '"$1"'.'"$NS"'.'svc.cluster.local 'http://'"$INGRESS"''
fi

0 comments on commit f7b9549

Please sign in to comment.