Skip to content

Commit

Permalink
[backport 2.1] Change order of searching ingress gateway for traffic …
Browse files Browse the repository at this point in the history
…generator (#7994)
  • Loading branch information
mkralik3 authored Dec 12, 2024
1 parent 16da2f0 commit 3feaf81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
19 changes: 11 additions & 8 deletions hack/istio/install-bookinfo-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,22 @@ if [ "${TRAFFIC_GENERATOR_ENABLED}" == "true" ]; then
echo "Installing Traffic Generator"
if [ "${IS_OPENSHIFT}" == "true" ]; then
echo "Determining the route to send traffic to, trying istio-ingressgateway route in ${INGRESS_NAMESPACE} namespace"
# first, try istio-ingressgateway in istio-system, wait for a while the host is populated

# first, try route for gateway in bookinfo namespace created by gateway-api
# make sure you have latest kubectl/oc which support JSONPath condition without value
${CLIENT_EXE} wait --for=jsonpath='{.status.ingress[].host}' --timeout=10s route istio-ingressgateway -n ${INGRESS_NAMESPACE}
INGRESS_ROUTE=$(${CLIENT_EXE} get route istio-ingressgateway -o jsonpath='{.spec.host}{"\n"}' -n ${INGRESS_NAMESPACE})
${CLIENT_EXE} wait --for=jsonpath='{.status.ingress[].host}' --timeout=10s route bookinfo-gateway-istio -n ${NAMESPACE}
INGRESS_ROUTE=$(${CLIENT_EXE} get route bookinfo-gateway-istio -o jsonpath='{.spec.host}{"\n"}' -n ${NAMESPACE})
if [ -z "${INGRESS_ROUTE}" ]; then
sleep 1
echo "No istio-ingressgateway route in ${INGRESS_NAMESPACE} namespace, next, trying bookinfo-gateway-istio route in ${NAMESPACE} namespace"
# next, try route for gateway in bookinfo namespace created by gateway-api
${CLIENT_EXE} wait --for=jsonpath='{.status.ingress[].host}' --timeout=10s route bookinfo-gateway-istio -n ${NAMESPACE}
INGRESS_ROUTE=$(${CLIENT_EXE} get route bookinfo-gateway-istio -o jsonpath='{.spec.host}{"\n"}' -n ${NAMESPACE})
echo "No bookinfo-gateway-istio route in ${NAMESPACE} namespace, next, trying istio-ingressgateway route in ${INGRESS_NAMESPACE} namespace"

# next, try istio-ingressgateway in istio-system, wait for a while the host is populated
${CLIENT_EXE} wait --for=jsonpath='{.status.ingress[].host}' --timeout=10s route istio-ingressgateway -n ${INGRESS_NAMESPACE}
INGRESS_ROUTE=$(${CLIENT_EXE} get route istio-ingressgateway -o jsonpath='{.spec.host}{"\n"}' -n ${INGRESS_NAMESPACE})
if [ -z "${INGRESS_ROUTE}" ]; then
sleep 1
echo "No bookinfo-gateway-istio route in ${NAMESPACE} namespace, the route for productpage app will be used dirrectly"
echo "No istio-ingressgateway route in ${INGRESS_NAMESPACE} namespace, the route for productpage app will be used dirrectly"

# nevermind, use productpage route directly
${CLIENT_EXE} wait --for=jsonpath='{.status.ingress[].host}' --timeout=10s route productpage -n ${NAMESPACE}
INGRESS_ROUTE=$(${CLIENT_EXE} get route productpage -o jsonpath='{.spec.host}{"\n"}' -n ${NAMESPACE})
Expand Down
20 changes: 13 additions & 7 deletions tests/integration/utils/kiali/kiali_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ type MetricsJson struct {
var client = *NewKialiClient()

const (
BOOKINFO = "bookinfo"
ASSETS = "tests/integration/assets"
TIMEOUT = 10 * time.Second
BOOKINFO = "bookinfo"
ASSETS = "tests/integration/assets"
TIMEOUT = 10 * time.Second
TIMEOUT_MEDIUM = 20 * time.Second
TIMEOUT_TRACING = 60 * time.Second
)

func NewKialiClient() (c *KialiClient) {
Expand Down Expand Up @@ -268,7 +270,7 @@ func Traces(objectType, name, namespace string) (*model.TracingResponse, int, er
url := fmt.Sprintf("%s/api/namespaces/%s/%s/%s/traces?startMicros=%d&tags=&limit=100", client.kialiURL, namespace, objectType, name, TimeSince())
traces := new(model.TracingResponse)

code, err := getRequestAndUnmarshalInto(url, traces)
code, err := getRequestAndUnmarshalIntoWithCustomTimeout(url, TIMEOUT_TRACING, traces)
if err == nil {
return traces, code, nil
} else {
Expand All @@ -280,7 +282,7 @@ func Spans(objectType, name, namespace string) ([]model.TracingSpan, int, error)
url := fmt.Sprintf("%s/api/namespaces/%s/%s/%s/spans?startMicros=%d&tags=&limit=100", client.kialiURL, namespace, objectType, name, TimeSince())
spans := new([]model.TracingSpan)

code, err := getRequestAndUnmarshalInto(url, spans)
code, err := getRequestAndUnmarshalIntoWithCustomTimeout(url, TIMEOUT_TRACING, spans)
if err == nil {
return *spans, code, nil
} else {
Expand Down Expand Up @@ -504,7 +506,11 @@ func Grafana() (*models.GrafanaInfo, int, error) {
}

func getRequestAndUnmarshalInto[T any](url string, response *T) (int, error) {
body, code, _, err := httpGETWithRetry(url, client.GetAuth(), TIMEOUT, nil, nil)
return getRequestAndUnmarshalIntoWithCustomTimeout(url, TIMEOUT, response)
}

func getRequestAndUnmarshalIntoWithCustomTimeout[T any](url string, timeout time.Duration, response *T) (int, error) {
body, code, _, err := httpGETWithRetry(url, client.GetAuth(), timeout, nil, nil)
if err != nil {
return code, err
}
Expand Down Expand Up @@ -536,7 +542,7 @@ func IstioApiEnabled() (bool, error) {
url := fmt.Sprintf("%s/api/status", client.kialiURL)
status := new(status.StatusInfo)

_, err := getRequestAndUnmarshalInto(url, status)
_, err := getRequestAndUnmarshalIntoWithCustomTimeout(url, TIMEOUT_MEDIUM, status)
if err == nil {
return status.IstioEnvironment.IstioAPIEnabled, nil
} else {
Expand Down

0 comments on commit 3feaf81

Please sign in to comment.