From 76590e386119dd5b115e81061ef9f4ebdeca1ad6 Mon Sep 17 00:00:00 2001 From: Kevin Exton Date: Mon, 21 Jul 2025 03:03:05 +0000 Subject: [PATCH] Made the deployment of the API Gateway optional. Setting .values.apigw.enabled to false disables the deployment of the API gateway and the redis databases. Environment variables have also been added to the smoke test and install packages jobs so that API gateway related tasks are also disabled. --- .../configMapFiles/installPackages/myTask.sh | 84 ++++++++++--------- .../configMapFiles/tests/smoketest/myTask.sh | 38 +++++---- helm/openwhisk/templates/apigateway-pod.yaml | 2 + helm/openwhisk/templates/apigateway-svc.yaml | 2 + .../templates/install-packages-job.yaml | 2 + helm/openwhisk/templates/redis-pod.yaml | 2 +- helm/openwhisk/templates/redis-pvc.yaml | 2 +- helm/openwhisk/templates/redis-svc.yaml | 2 +- .../templates/tests/smoketest-pod.yaml | 2 + helm/openwhisk/values.yaml | 1 + 10 files changed, 76 insertions(+), 61 deletions(-) diff --git a/helm/openwhisk/configMapFiles/installPackages/myTask.sh b/helm/openwhisk/configMapFiles/installPackages/myTask.sh index bb390434..c01dc350 100644 --- a/helm/openwhisk/configMapFiles/installPackages/myTask.sh +++ b/helm/openwhisk/configMapFiles/installPackages/myTask.sh @@ -19,56 +19,58 @@ export OPENWHISK_HOME=/openwhisk export PROVIDER_DB_URL=$PROVIDER_DB_PROTOCOL://$PROVIDER_DB_USERNAME:$PROVIDER_DB_PASSWORD@$PROVIDER_DB_HOST:$PROVIDER_DB_PORT -##### -# Install Route Mgmt Support -##### - -# Clone openwhisk repo to get installRouteMgmt.sh and core/routemgmt +# Clone openwhisk repo git clone https://github.com/apache/openwhisk openwhisk pushd openwhisk git checkout $OW_GIT_TAG_OPENWHISK rm -f /openwhisk/ansible/files/auth.guest /openwhisk/ansible/files/auth.whisk.system popd -# Setup env for installRouteMgmt.sh -if [ "$WHISK_API_GATEWAY_USER" ]; then - export GW_USER=$WHISK_API_GATEWAY_USER -else - export GW_USER=' ' -fi -if [ "$WHISK_API_GATEWAY_PASSWORD" ]; then - export GW_PWD=$WHISK_API_GATEWAY_PASSWORD -else - export GW_PWD=' ' -fi -if [ "$WHISK_API_GATEWAY_HOST_V2" ]; then - export GW_HOST_V2=$WHISK_API_GATEWAY_HOST_V2 -else - echo "Must provide a value for WHISK_API_GATEWAY_HOST_V2" - exit 1 -fi +if [ "${WHISK_API_GATEWAY_ENABLED:-no}" = "yes" ]; then + ##### + # Install Route Mgmt Support + ##### -pushd $OPENWHISK_HOME/ansible/roles/routemgmt/files - # This operation is unreliable in a TravisCI environment (for unknown reasons), - # so try multiple times before giving up. - PASSED=false - TRIES=0 - until $PASSED || [ $TRIES -eq 10 ]; do - if ./installRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_URL $WHISK_SYSTEM_NAMESPACE /usr/local/bin/wsk; then - PASSED=true - echo "Successfully deployed routemgmt package" - else - echo "Failed to deploy routemgmt package; will pause, uninstall, and try again" - let TRIES=TRIES+1 - sleep 10 - ./uninstallRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_URL $WHISK_SYSTEM_NAMESPACE /usr/local/bin/wsk; - fi - done - if ! $PASSED; then - echo "Giving up after 10 failed attempts to install the routemgmt package" + # Setup env for installRouteMgmt.sh + if [ "$WHISK_API_GATEWAY_USER" ]; then + export GW_USER=$WHISK_API_GATEWAY_USER + else + export GW_USER=' ' + fi + if [ "$WHISK_API_GATEWAY_PASSWORD" ]; then + export GW_PWD=$WHISK_API_GATEWAY_PASSWORD + else + export GW_PWD=' ' + fi + if [ "$WHISK_API_GATEWAY_HOST_V2" ]; then + export GW_HOST_V2=$WHISK_API_GATEWAY_HOST_V2 + else + echo "Must provide a value for WHISK_API_GATEWAY_HOST_V2" exit 1 fi -popd + + pushd $OPENWHISK_HOME/ansible/roles/routemgmt/files + # This operation is unreliable in a TravisCI environment (for unknown reasons), + # so try multiple times before giving up. + PASSED=false + TRIES=0 + until $PASSED || [ $TRIES -eq 10 ]; do + if ./installRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_URL $WHISK_SYSTEM_NAMESPACE /usr/local/bin/wsk; then + PASSED=true + echo "Successfully deployed routemgmt package" + else + echo "Failed to deploy routemgmt package; will pause, uninstall, and try again" + let TRIES=TRIES+1 + sleep 10 + ./uninstallRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_URL $WHISK_SYSTEM_NAMESPACE /usr/local/bin/wsk; + fi + done + if ! $PASSED; then + echo "Giving up after 10 failed attempts to install the routemgmt package" + exit 1 + fi + popd +fi ##### # Install the OpenWhisk Catalog diff --git a/helm/openwhisk/configMapFiles/tests/smoketest/myTask.sh b/helm/openwhisk/configMapFiles/tests/smoketest/myTask.sh index 0ac526de..83059ad6 100644 --- a/helm/openwhisk/configMapFiles/tests/smoketest/myTask.sh +++ b/helm/openwhisk/configMapFiles/tests/smoketest/myTask.sh @@ -71,25 +71,29 @@ if [ -z "$RESULT" ]; then exit 1 fi -# now define it as an api and invoke it that way -echo "Registering as an api" -wsk -i api create /demo /hello get hello || (echo "FAILED: unable to create API"; exit 1) -echo "Invoking action via the api" -API_URL=$(wsk -i api list | grep hello | awk '{print $4}') -echo "External api URL: $API_URL" -INTERNAL_URL=$(echo $API_URL | sed s#^http.*/api/#$WSK_API_HOST_URL/api/#) -echo "Internal api URL: $INTERNAL_URL" -RESULT=$(wget --no-check-certificate -qO- "$INTERNAL_URL" | grep 'Hello world') -if [ -z "$RESULT" ]; then - echo "FAILED! Could not invoke hello via apigateway" - exit 1 -fi +if [ "${WHISK_API_GATEWAY_ENABLED:-no}" = "yes" ]; then + # now define it as an api and invoke it that way + echo "Registering as an api" + wsk -i api create /demo /hello get hello || (echo "FAILED: unable to create API"; exit 1) + echo "Invoking action via the api" + API_URL=$(wsk -i api list | grep hello | awk '{print $4}') + echo "External api URL: $API_URL" + INTERNAL_URL=$(echo $API_URL | sed s#^http.*/api/#$WSK_API_HOST_URL/api/#) + echo "Internal api URL: $INTERNAL_URL" + RESULT=$(wget --no-check-certificate -qO- "$INTERNAL_URL" | grep 'Hello world') + if [ -z "$RESULT" ]; then + echo "FAILED! Could not invoke hello via apigateway" + exit 1 + fi -# now delete the resources so the test could be run again -wsk -i api delete /demo || (echo "FAILED! failed to delete API"; exit 1) -wsk -i action delete hello || (echo "FAILED! failed to delete action"; exit 1) + # now delete the resources so the test could be run again + wsk -i api delete /demo || (echo "FAILED! failed to delete API"; exit 1) + wsk -i action delete hello || (echo "FAILED! failed to delete action"; exit 1) -echo "PASSED! Created Hello action and invoked via cli, web and apigateway" + echo "PASSED! Created Hello action and invoked via apigateway, cli, and web" +else + echo "PASSED! Created Hello action and invoked via cli, and web" +fi diff --git a/helm/openwhisk/templates/apigateway-pod.yaml b/helm/openwhisk/templates/apigateway-pod.yaml index 8db4b319..bf1c3599 100644 --- a/helm/openwhisk/templates/apigateway-pod.yaml +++ b/helm/openwhisk/templates/apigateway-pod.yaml @@ -15,6 +15,7 @@ # limitations under the License. # +{{- if .Values.apigw.enabled }} apiVersion: apps/v1 kind: Deployment metadata: @@ -71,3 +72,4 @@ spec: configMapKeyRef: name: {{ .Release.Name }}-whisk.config key: whisk_internal_api_host_url +{{- end }} diff --git a/helm/openwhisk/templates/apigateway-svc.yaml b/helm/openwhisk/templates/apigateway-svc.yaml index 9a94e744..c48a20fe 100644 --- a/helm/openwhisk/templates/apigateway-svc.yaml +++ b/helm/openwhisk/templates/apigateway-svc.yaml @@ -15,6 +15,7 @@ # limitations under the License. # +{{- if .Values.apigw.enabled }} apiVersion: v1 kind: Service metadata: @@ -30,3 +31,4 @@ spec: name: mgmt - port: {{ .Values.apigw.apiPort }} name: api +{{- end }} diff --git a/helm/openwhisk/templates/install-packages-job.yaml b/helm/openwhisk/templates/install-packages-job.yaml index ba3d0254..330dbc5a 100644 --- a/helm/openwhisk/templates/install-packages-job.yaml +++ b/helm/openwhisk/templates/install-packages-job.yaml @@ -72,6 +72,8 @@ spec: name: {{ .Release.Name }}-whisk.config key: whisk_internal_api_host_url # apigateway configuration (for installing routemgmt actions) + - name: "WHISK_API_GATEWAY_ENABLED" + value: {{ if .Values.apigw.enabled }} "yes" {{ else }} "no" {{ end }} - name: "WHISK_SYSTEM_NAMESPACE" valueFrom: configMapKeyRef: diff --git a/helm/openwhisk/templates/redis-pod.yaml b/helm/openwhisk/templates/redis-pod.yaml index 30c74b1e..54a8ef69 100644 --- a/helm/openwhisk/templates/redis-pod.yaml +++ b/helm/openwhisk/templates/redis-pod.yaml @@ -15,7 +15,7 @@ # limitations under the License. # -{{ if not .Values.redis.external }} +{{ if and .Values.apigw.enabled (not .Values.redis.external) }} apiVersion: apps/v1 kind: Deployment metadata: diff --git a/helm/openwhisk/templates/redis-pvc.yaml b/helm/openwhisk/templates/redis-pvc.yaml index 3feafc42..600255cc 100644 --- a/helm/openwhisk/templates/redis-pvc.yaml +++ b/helm/openwhisk/templates/redis-pvc.yaml @@ -15,7 +15,7 @@ # limitations under the License. # -{{- if and (not .Values.redis.external) .Values.k8s.persistence.enabled }} +{{- if and .Values.apigw.enabled (not .Values.redis.external) .Values.k8s.persistence.enabled }} apiVersion: v1 kind: PersistentVolumeClaim metadata: diff --git a/helm/openwhisk/templates/redis-svc.yaml b/helm/openwhisk/templates/redis-svc.yaml index ed03f781..be880c09 100644 --- a/helm/openwhisk/templates/redis-svc.yaml +++ b/helm/openwhisk/templates/redis-svc.yaml @@ -15,7 +15,7 @@ # limitations under the License. # -{{ if not .Values.redis.external }} +{{ if and .Values.apigw.enabled (not .Values.redis.external) }} apiVersion: v1 kind: Service metadata: diff --git a/helm/openwhisk/templates/tests/smoketest-pod.yaml b/helm/openwhisk/templates/tests/smoketest-pod.yaml index c1a93640..e5e90505 100644 --- a/helm/openwhisk/templates/tests/smoketest-pod.yaml +++ b/helm/openwhisk/templates/tests/smoketest-pod.yaml @@ -53,4 +53,6 @@ spec: configMapKeyRef: name: {{ .Release.Name }}-whisk.config key: whisk_internal_api_host_url + - name: "WSK_API_GATEWAY_ENABLED" + value: {{ if .Values.apigw.enabled }} "yes" {{ else }} "no" {{ end }} {{- end }} diff --git a/helm/openwhisk/values.yaml b/helm/openwhisk/values.yaml index b923da19..229f5d85 100644 --- a/helm/openwhisk/values.yaml +++ b/helm/openwhisk/values.yaml @@ -360,6 +360,7 @@ invoker: # API Gateway configurations apigw: + enabled: true # Disabling this also disables Redis imageName: "openwhisk/apigateway" imageTag: "1.0.0" imagePullPolicy: "IfNotPresent"