From ccdd54f09da78d53b9bed0d52d283c06213086af Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Sun, 11 Feb 2018 23:18:22 +0530 Subject: [PATCH 1/5] Adding OpenShift resources to deploy OpenWhisk API Gateway --- openshift/apigateway.yaml | 137 ++++++++++++++++++++++++++++++++++++ openshift/apimangement.yaml | 39 ++++++++++ 2 files changed, 176 insertions(+) create mode 100644 openshift/apigateway.yaml create mode 100644 openshift/apimangement.yaml diff --git a/openshift/apigateway.yaml b/openshift/apigateway.yaml new file mode 100644 index 00000000..234d1fb3 --- /dev/null +++ b/openshift/apigateway.yaml @@ -0,0 +1,137 @@ +######################################## +## API Gateway ConfigMap +######################################## +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: apigateway + namespace: openwhisk +data: + api_host: openwhisk-openwhisk.192.168.64.58.nip.io + apigw_url: http://apigateway-openwhisk.192.168.64.58.nip.io + redis_host: "redis.openwhisk.svc.cluster.local" + redis_port: "6379" +######################################## +# START REDIS Deployment +######################################## +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: redis + name: redis + namespace: openwhisk +spec: + ports: + - name: redis-6379 + port: 6379 + selector: + app: redis +--- +apiVersion: apps.openshift.io/v1 +kind: DeploymentConfig +metadata: + labels: + app: redis + name: redis + namespace: openwhisk +spec: + replicas: 1 + template: + metadata: + labels: + app: redis + name: redis + spec: + containers: + - image: docker.io/redis:3.2 + name: redis + triggers: + - type: ConfigChange + +######################################## +# END REDIS Deployment +######################################## + +######################################## +# START OpenWhisk ApiGateway Deployment +######################################## +--- +apiVersion: v1 +kind: Service +metadata: + name: apigateway + labels: + name: apigateway + namespace: openwhisk +spec: + selector: + name: apigateway + ports: + - port: 8080 + name: mgmt + - port: 9000 + name: api +--- +apiVersion: apps.openshift.io/v1 +kind: DeploymentConfig +metadata: + name: apigateway + namespace: openwhisk + labels: + name: apigateway +spec: + replicas: 1 + template: + metadata: + labels: + name: apigateway + spec: + restartPolicy: Always + containers: + - name: apigateway + imagePullPolicy: IfNotPresent + image: docker.io/openwhisk/apigateway + ports: + - name: mgmt + containerPort: 8080 + - name: api + containerPort: 9000 + env: + - name: "REDIS_HOST" + valueFrom: + configMapKeyRef: + name: apigateway + key: redis_host + - name: "REDIS_PORT" + valueFrom: + configMapKeyRef: + name: apigateway + key: redis_port + - name: "PUBLIC_GATEWAY_URL" + valueFrom: + configMapKeyRef: + name: apigateway + key: apigw_url + triggers: + - type: ConfigChange + +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + labels: + app: apigateway + name: apigateway + namespace: openwhisk +spec: + port: + targetPort: mgmt + to: + kind: Service + name: apigateway +######################################## +# END OpenWhisk ApiGateway Deployment +######################################## \ No newline at end of file diff --git a/openshift/apimangement.yaml b/openshift/apimangement.yaml new file mode 100644 index 00000000..d6a04202 --- /dev/null +++ b/openshift/apimangement.yaml @@ -0,0 +1,39 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: install-apimanagement + namespace: openwhisk +spec: + activeDeadlineSeconds: 600 + template: + metadata: + name: install-apimanagement + spec: + containers: + - name: apimanagement + image: docker.io/openwhisk/kube-routemgmt + env: + - name: "WHISK_CLI_VERSION" + valueFrom: + configMapKeyRef: + name: whisk.config + key: whisk_cli_version_tag + - name: "WHISK_AUTH" + valueFrom: + secretKeyRef: + name: whisk.auth + key: system + - name: "WHISK_API_HOST_NAME" + valueFrom: + configMapKeyRef: + name: apigateway + key: api_host + - name: "WHISK_NAMESPACE" + valueFrom: + configMapKeyRef: + name: whisk.config + key: whisk_system_namespace + - name: "WHISK_API_GATEWAY_HOST_V2" + value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2" + + restartPolicy: Never From d57fa3d45dedfaa426041dfcee6ad208aeeedd36 Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Tue, 13 Feb 2018 20:26:29 +0530 Subject: [PATCH 2/5] Renaming files to .yml --- openshift/{apigateway.yaml => apigateway.yml} | 0 openshift/{apimangement.yaml => apimangement.yml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename openshift/{apigateway.yaml => apigateway.yml} (100%) rename openshift/{apimangement.yaml => apimangement.yml} (100%) diff --git a/openshift/apigateway.yaml b/openshift/apigateway.yml similarity index 100% rename from openshift/apigateway.yaml rename to openshift/apigateway.yml diff --git a/openshift/apimangement.yaml b/openshift/apimangement.yml similarity index 100% rename from openshift/apimangement.yaml rename to openshift/apimangement.yml From d167b17e3fe0373fb2de5929d377af7d24c12d5d Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Sun, 18 Feb 2018 22:01:28 +0530 Subject: [PATCH 3/5] Removed all hardcoded namespaces Signed-off-by: Kamesh Sampath --- openshift/apigateway.yml | 10 +++------- openshift/{apimangement.yml => apimanagement.yml} | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) rename openshift/{apimangement.yml => apimanagement.yml} (97%) diff --git a/openshift/apigateway.yml b/openshift/apigateway.yml index 234d1fb3..923e9290 100644 --- a/openshift/apigateway.yml +++ b/openshift/apigateway.yml @@ -6,11 +6,12 @@ apiVersion: v1 kind: ConfigMap metadata: name: apigateway - namespace: openwhisk data: + # TODO remove form hardcode api_host: openwhisk-openwhisk.192.168.64.58.nip.io + # TODO remove form hardcode apigw_url: http://apigateway-openwhisk.192.168.64.58.nip.io - redis_host: "redis.openwhisk.svc.cluster.local" + redis_host: "redis" redis_port: "6379" ######################################## # START REDIS Deployment @@ -22,7 +23,6 @@ metadata: labels: app: redis name: redis - namespace: openwhisk spec: ports: - name: redis-6379 @@ -36,7 +36,6 @@ metadata: labels: app: redis name: redis - namespace: openwhisk spec: replicas: 1 template: @@ -65,7 +64,6 @@ metadata: name: apigateway labels: name: apigateway - namespace: openwhisk spec: selector: name: apigateway @@ -79,7 +77,6 @@ apiVersion: apps.openshift.io/v1 kind: DeploymentConfig metadata: name: apigateway - namespace: openwhisk labels: name: apigateway spec: @@ -125,7 +122,6 @@ metadata: labels: app: apigateway name: apigateway - namespace: openwhisk spec: port: targetPort: mgmt diff --git a/openshift/apimangement.yml b/openshift/apimanagement.yml similarity index 97% rename from openshift/apimangement.yml rename to openshift/apimanagement.yml index d6a04202..0423f219 100644 --- a/openshift/apimangement.yml +++ b/openshift/apimanagement.yml @@ -2,7 +2,6 @@ apiVersion: batch/v1 kind: Job metadata: name: install-apimanagement - namespace: openwhisk spec: activeDeadlineSeconds: 600 template: From 13d5a4bba54e8cf3d4bee3cf9b17ca91fb8eae82 Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Mon, 26 Feb 2018 20:22:01 +0530 Subject: [PATCH 4/5] Sane Default values for apigateway ddeployment, via computing Signed-off-by: Kamesh Sampath --- docker/routemgmt/init.sh | 14 ++++++++++++-- openshift/apigateway.yml | 15 ++++++++------- openshift/apimanagement.yml | 9 ++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docker/routemgmt/init.sh b/docker/routemgmt/init.sh index 5444fcac..e414a6ab 100755 --- a/docker/routemgmt/init.sh +++ b/docker/routemgmt/init.sh @@ -5,6 +5,13 @@ set -e export OPENWHISK_HOME=/openwhisk +# Dynamically determine API gateway host +export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" +export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)" +export _WHISK_API_GATEWAY_HOST=$(curl -s --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}') +export _WHISK_API_GATEWAY_HOST_V2=${_WHISK_API_GATEWAY_HOST} +export WHISK_API_HOST_NAME=${_WHISK_API_GATEWAY_HOST} + # Clone openwhisk repo to get latest installRouteMgmt.sh and core/routemgmt # TODO: when OpenWhisk has releases, download release artifacts instead! git clone https://github.com/apache/incubator-openwhisk openwhisk @@ -31,10 +38,13 @@ 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 + echo "Using computed value for WHISK_API_GATEWAY_HOST_V2 as ${APIGW_HOST_V2}" + # echo "Must provide a value for WHISK_API_GATEWAY_HOST_V2" + # exit 1 + export GW_HOST_V2="http://${APIGW_HOST_V2}/v2" fi + # Run installRouteMgmt.sh pushd ansible/roles/routemgmt/files ./installRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_NAME $WHISK_NAMESPACE $OPENWHISK_HOME/bin/wsk diff --git a/openshift/apigateway.yml b/openshift/apigateway.yml index 923e9290..a58072f7 100644 --- a/openshift/apigateway.yml +++ b/openshift/apigateway.yml @@ -8,9 +8,9 @@ metadata: name: apigateway data: # TODO remove form hardcode - api_host: openwhisk-openwhisk.192.168.64.58.nip.io + # api_host: openwhisk-openwhisk.192.168.64.65.nip.io # TODO remove form hardcode - apigw_url: http://apigateway-openwhisk.192.168.64.58.nip.io + # apigw_url: http://apigateway-openwhisk.192.168.64.65.nip.io redis_host: "redis" redis_port: "6379" ######################################## @@ -87,6 +87,7 @@ spec: name: apigateway spec: restartPolicy: Always + serviceAccountName: openwhisk containers: - name: apigateway imagePullPolicy: IfNotPresent @@ -107,11 +108,11 @@ spec: configMapKeyRef: name: apigateway key: redis_port - - name: "PUBLIC_GATEWAY_URL" - valueFrom: - configMapKeyRef: - name: apigateway - key: apigw_url + # - name: "PUBLIC_GATEWAY_URL" + # valueFrom: + # configMapKeyRef: + # name: apigateway + # key: apigw_url triggers: - type: ConfigChange diff --git a/openshift/apimanagement.yml b/openshift/apimanagement.yml index 0423f219..499f845d 100644 --- a/openshift/apimanagement.yml +++ b/openshift/apimanagement.yml @@ -22,17 +22,12 @@ spec: secretKeyRef: name: whisk.auth key: system - - name: "WHISK_API_HOST_NAME" - valueFrom: - configMapKeyRef: - name: apigateway - key: api_host - name: "WHISK_NAMESPACE" valueFrom: configMapKeyRef: name: whisk.config key: whisk_system_namespace - - name: "WHISK_API_GATEWAY_HOST_V2" - value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2" + # - name: "WHISK_API_GATEWAY_HOST_V2" + # value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2" restartPolicy: Never From 032921071dcc3683aa89bdb17569efa7d654801f Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Tue, 27 Feb 2018 14:30:02 +0530 Subject: [PATCH 5/5] - Reverting changes done to routemgmt/int.sh - Made the configmap to deduce or infer the values from env Signed-off-by: Kamesh Sampath --- docker/routemgmt/init.sh | 16 ++-------- openshift/apigateway.yml | 58 ++++++++++++++++++++++--------------- openshift/apimanagement.yml | 18 ++++++++++-- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/docker/routemgmt/init.sh b/docker/routemgmt/init.sh index e414a6ab..7ace7beb 100755 --- a/docker/routemgmt/init.sh +++ b/docker/routemgmt/init.sh @@ -5,13 +5,6 @@ set -e export OPENWHISK_HOME=/openwhisk -# Dynamically determine API gateway host -export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)" -export _WHISK_API_GATEWAY_HOST=$(curl -s --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}') -export _WHISK_API_GATEWAY_HOST_V2=${_WHISK_API_GATEWAY_HOST} -export WHISK_API_HOST_NAME=${_WHISK_API_GATEWAY_HOST} - # Clone openwhisk repo to get latest installRouteMgmt.sh and core/routemgmt # TODO: when OpenWhisk has releases, download release artifacts instead! git clone https://github.com/apache/incubator-openwhisk openwhisk @@ -38,14 +31,11 @@ fi if [ "$WHISK_API_GATEWAY_HOST_V2" ]; then export GW_HOST_V2=$WHISK_API_GATEWAY_HOST_V2 else - echo "Using computed value for WHISK_API_GATEWAY_HOST_V2 as ${APIGW_HOST_V2}" - # echo "Must provide a value for WHISK_API_GATEWAY_HOST_V2" - # exit 1 - export GW_HOST_V2="http://${APIGW_HOST_V2}/v2" + echo "Must provide a value for WHISK_API_GATEWAY_HOST_V2" + exit 1 fi - # Run installRouteMgmt.sh pushd ansible/roles/routemgmt/files ./installRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_NAME $WHISK_NAMESPACE $OPENWHISK_HOME/bin/wsk -popd +popd \ No newline at end of file diff --git a/openshift/apigateway.yml b/openshift/apigateway.yml index a58072f7..f445e732 100644 --- a/openshift/apigateway.yml +++ b/openshift/apigateway.yml @@ -7,12 +7,24 @@ kind: ConfigMap metadata: name: apigateway data: - # TODO remove form hardcode - # api_host: openwhisk-openwhisk.192.168.64.65.nip.io - # TODO remove form hardcode - # apigw_url: http://apigateway-openwhisk.192.168.64.65.nip.io - redis_host: "redis" - redis_port: "6379" + apimgmt-init: | + # Dynamically determine API gateway host + export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" + export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)" + export WHISK_API_GATEWAY_HOST=$(wget -q -O - -o /dev/null --ca-certificate='/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' --header="Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}') + export WHISK_API_HOST_NAME="${WHISK_API_GATEWAY_HOST}" + export PUBLIC_GATEWAY_URL="${WHISK_API_GATEWAY_HOST}" + exec /init.sh + apigateway-init: | + # Dynamically determine API gateway host and other environment variables + export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" + export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)" + export WHISK_API_GATEWAY_HOST=$(wget -q -O - -o /dev/null --ca-certificate='/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' --header="Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}') + export WHISK_API_HOST_NAME="${WHISK_API_GATEWAY_HOST}" + export PUBLIC_GATEWAY_URL="http://${WHISK_API_GATEWAY_HOST}" + # with current bug in minishift its not able to resolve short dns names + # https://github.com/minishift/minishift/issues/2070 + exec env REDIS_HOST="redis.${NAMESPACE}.svc.cluster.local" /etc/init-container.sh ######################################## # START REDIS Deployment ######################################## @@ -25,7 +37,7 @@ metadata: name: redis spec: ports: - - name: redis-6379 + - name: redis port: 6379 selector: app: redis @@ -88,31 +100,31 @@ spec: spec: restartPolicy: Always serviceAccountName: openwhisk + volumes: + - name: apigateway-config + configMap: + name: apigateway + items: + - key: apigateway-init + path: init containers: - name: apigateway imagePullPolicy: IfNotPresent image: docker.io/openwhisk/apigateway + command: [ "/bin/bash", "-o", "allexport", "/apigateway-config/init" ] ports: - name: mgmt containerPort: 8080 - name: api containerPort: 9000 - env: - - name: "REDIS_HOST" - valueFrom: - configMapKeyRef: - name: apigateway - key: redis_host - - name: "REDIS_PORT" - valueFrom: - configMapKeyRef: - name: apigateway - key: redis_port - # - name: "PUBLIC_GATEWAY_URL" - # valueFrom: - # configMapKeyRef: - # name: apigateway - # key: apigw_url + env: + # - name: REDIS_HOST + # value: "redis.openwhisk.svc.cluster.local" + - name: REDIS_PORT + value: "6379" + volumeMounts: + - name: apigateway-config + mountPath: "/apigateway-config" triggers: - type: ConfigChange diff --git a/openshift/apimanagement.yml b/openshift/apimanagement.yml index 499f845d..02cdbd5d 100644 --- a/openshift/apimanagement.yml +++ b/openshift/apimanagement.yml @@ -8,9 +8,19 @@ spec: metadata: name: install-apimanagement spec: + serviceAccountName: openwhisk + volumes: + - name: apimgmt-config + configMap: + name: apigateway + items: + - key: apimgmt-init + path: init containers: - name: apimanagement image: docker.io/openwhisk/kube-routemgmt + command: [ "/bin/bash", "-o", "allexport", "/apimgmt-config/init" ] + imagePullPolicy: IfNotPresent env: - name: "WHISK_CLI_VERSION" valueFrom: @@ -27,7 +37,9 @@ spec: configMapKeyRef: name: whisk.config key: whisk_system_namespace - # - name: "WHISK_API_GATEWAY_HOST_V2" - # value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2" - + - name: "WHISK_API_GATEWAY_HOST_V2" + value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2" + volumeMounts: + - name: apimgmt-config + mountPath: "/apimgmt-config" restartPolicy: Never