You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/07/20 15:10:35 UTC
[incubator-openwhisk-deploy-kube] branch master updated: Move db
initialization into separate Job and reorder invoker init-containers (#261)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-deploy-kube.git
The following commit(s) were added to refs/heads/master by this push:
new 0145a0a Move db initialization into separate Job and reorder invoker init-containers (#261)
0145a0a is described below
commit 0145a0aaaffc38defe699c67d3d03c0b1efcdcd1
Author: David Grove <dg...@users.noreply.github.com>
AuthorDate: Fri Jul 20 11:10:33 2018 -0400
Move db initialization into separate Job and reorder invoker init-containers (#261)
Restructure the db initialization into a separate Job using the
whisk-ansible-runner docker image that can be optionally run on both
"in cluster" and "external" database instances. In addition to
simplifying usage of an external database, this also allows the use of
a vanilla apache/couchdb image for in cluster CouchDB.
Also reorder invoker init-containers so we do the docker-pull-runtimes
before waiting for the controller to be up. This better overlaps the
docker pulls of the runtime containers with the inherent latency of
waiting for the controller to be ready.
---
docker/README.md | 3 -
docker/couchdb/Dockerfile | 31 -------
docker/couchdb/init.sh | 94 ----------------------
docker/whisk-ansible-runner/Dockerfile | 13 ++-
docs/configurationChoices.md | 11 ++-
.../openwhisk/configMapFiles/initCouchDB/initdb.sh | 58 +++++++++++++
helm/openwhisk/templates/_readiness.tpl | 4 +-
helm/openwhisk/templates/couchdb.yaml | 21 -----
helm/openwhisk/templates/initCouchDBJob.yaml | 74 +++++++++++++++++
helm/openwhisk/templates/invoker.yaml | 5 +-
helm/openwhisk/values.yaml | 7 +-
tools/travis/collect-logs.sh | 2 +-
tools/travis/deploy.sh | 3 -
13 files changed, 158 insertions(+), 168 deletions(-)
diff --git a/docker/README.md b/docker/README.md
index c0915bc..22a2db9 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -28,8 +28,5 @@ The built images are:
ansible playbooks.
* whisk-script-runner - An alpine-based utility image for running
simple bash scripts that need the `wsk` cli available to them.
- * couchdb - creates and initializes a CouchDB instance for
- dev/testing of OpenWhisk. This image is not intended for
- production usage.
* invoker-agent - worker node invoker agent -- used to implement
suspend/resume and log consolidation ops for a remote invoker
diff --git a/docker/couchdb/Dockerfile b/docker/couchdb/Dockerfile
deleted file mode 100644
index 3c58a22..0000000
--- a/docker/couchdb/Dockerfile
+++ /dev/null
@@ -1,31 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more contributor
-# license agreements; and to You under the Apache License, Version 2.0.
-
-FROM apache/couchdb:2.1
-
-ADD http://ftp.us.debian.org/debian/pool/main/a/apt/apt-transport-https_1.0.9.8.4_amd64.deb /tmp/apt-transport-https_1.0.9.8.4_amd64.deb
-ADD http://ftp.us.debian.org/debian/pool/main/c/curl/libcurl3-gnutls_7.38.0-4+deb8u8_amd64.deb /tmp/libcurl3-gnutls_7.38.0-4+deb8u58_amd64.deb
-RUN dpkg -i /tmp/libcurl3-gnutls_7.38.0-4+deb8u58_amd64.deb
-RUN dpkg -i /tmp/apt-transport-https_1.0.9.8.4_amd64.deb
-
-RUN apt-get -y update && apt-get -y install \
- git \
- curl \
- sudo \
- python-dev \
- python-pip \
- libffi-dev \
- libssl-dev
-
-RUN pip install --upgrade setuptools
-RUN pip install argcomplete
-RUN pip install couchdb
-RUN pip install --upgrade cffi
-RUN pip install markupsafe
-RUN pip install ansible==2.5.2
-RUN pip install -U pyopenssl
-
-COPY init.sh /init.sh
-RUN chmod +X /init.sh
-
-CMD ["/init.sh"]
diff --git a/docker/couchdb/init.sh b/docker/couchdb/init.sh
deleted file mode 100755
index fe0a64f..0000000
--- a/docker/couchdb/init.sh
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one or more contributor
-# license agreements; and to You under the Apache License, Version 2.0.
-
-set -ex
-
-# start couchdb as a background process
-/docker-entrypoint.sh /opt/couchdb/bin/couchdb &
-
-# wait for couchdb to be up and running
-TIMEOUT=0
-echo "wait for CouchDB to be up and running"
-until $( curl --output /dev/null --silent http://$DB_HOST:$DB_PORT/_utils ) || [ $TIMEOUT -eq 30 ]; do
- echo "waiting for CouchDB to be available"
-
- sleep 2
- let TIMEOUT=TIMEOUT+1
-done
-
-if [ $TIMEOUT -eq 30 ]; then
- echo "failed to setup CouchDB"
- exit 1
-fi
-
-
-if [[ -f /opt/couchdb/data/_openwhisk_initialized.stamp ]]; then
- # If we mounted an existing database from the persistent volume then use it.
- echo "_openwhisk_initialized.stamp exists; using existing database"
-else
- # No existing database; we will have to initialize it.
-
- # Always clone the latest version of OpenWhisk
- git clone https://github.com/apache/incubator-openwhisk /openwhisk
-
- pushd /openwhisk
- # if auth guest overwrite file
- if [ -n "$AUTH_GUEST" ]; then
- echo "$AUTH_GUEST" > /openwhisk/ansible/files/auth.guest
- fi
-
- # if auth whisk system overwrite file
- if [ -n "$AUTH_WHISK_SYSTEM" ]; then
- echo "$AUTH_WHISK_SYSTEM" > /openwhisk/ansible/files/auth.whisk.system
- fi
-
- # setup and initialize DB
- pushd ansible
- ansible-playbook -i environments/local setup.yml
- ansible-playbook -i environments/local couchdb.yml --tags ini \
- -e db_prefix=$DB_PREFIX \
- -e db_host=$DB_HOST \
- -e db_username=$COUCHDB_USER \
- -e db_password=$COUCHDB_PASSWORD \
- -e db_port=$DB_PORT \
- -e openwhisk_home=/openwhisk
- popd
-
- # disable reduce limits on views
- curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_node/couchdb@$NODENAME/_config/query_server_config/reduce_limit -d '"false"'
-
- # create the couchdb system databases
- curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_users
- curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_replicator
- curl -X PUT http://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_global_changes
-
- pushd ansible
- # initialize the DB
- ansible-playbook -i environments/local initdb.yml \
- -e db_prefix=$DB_PREFIX \
- -e db_host=$DB_HOST \
- -e db_username=$COUCHDB_USER \
- -e db_password=$COUCHDB_PASSWORD \
- -e db_port=$DB_PORT \
- -e openwhisk_home=/openwhisk
-
- # wipe the DB
- ansible-playbook -i environments/local wipe.yml \
- -e db_prefix=$DB_PREFIX \
- -e db_host=$DB_HOST \
- -e db_username=$COUCHDB_USER \
- -e db_password=$COUCHDB_PASSWORD \
- -e db_port=$DB_PORT \
- -e openwhisk_home=/openwhisk
- popd
-
- # stamp that we successfully initialized the database
- date > /opt/couchdb/data/_openwhisk_initialized.stamp
-
- popd
-fi
-
-echo "successfully setup and configured CouchDB for OpenWhisk"
-
-sleep inf
diff --git a/docker/whisk-ansible-runner/Dockerfile b/docker/whisk-ansible-runner/Dockerfile
index 938b5c3..7b87b74 100644
--- a/docker/whisk-ansible-runner/Dockerfile
+++ b/docker/whisk-ansible-runner/Dockerfile
@@ -6,17 +6,22 @@ from alpine
ENV DOCKER_VERSION 1.12.0
RUN apk --no-cache add \
+ bash \
+ curl \
+ git \
+ libc6-compat \
+ libffi \
+ openssl \
python \
py-pip \
- libffi \
- openssl
+ wget \
+ zip
RUN apk --no-cache add --virtual build-dependencies \
python-dev \
build-base \
libffi-dev \
- openssl-dev \
- wget
+ openssl-dev
# Install docker client
RUN wget --no-verbose https://get.docker.com/builds/Linux/x86_64/docker-${DOCKER_VERSION}.tgz && \
diff --git a/docs/configurationChoices.md b/docs/configurationChoices.md
index 30eed7c..441a1a1 100644
--- a/docs/configurationChoices.md
+++ b/docs/configurationChoices.md
@@ -63,10 +63,13 @@ db:
password: <password>
```
-Note that if you use an external database, the Helm deployment process
-will not attempt to create the necessary database tables or otherwise
-initialize/wipe the database. You will need to properly initialize
-your external database before deploying the OpenWhisk chart.
+If your external database has already been initialized for use by OpenWhisk,
+you can disable the Kubernetes Job that wipes and re-initializes the
+database by adding the following to your `mycluster.yaml`
+```yaml
+db:
+ wipeAndInit: false
+```
### Persistence
diff --git a/helm/openwhisk/configMapFiles/initCouchDB/initdb.sh b/helm/openwhisk/configMapFiles/initCouchDB/initdb.sh
new file mode 100755
index 0000000..976d6b0
--- /dev/null
+++ b/helm/openwhisk/configMapFiles/initCouchDB/initdb.sh
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+
+# Clone OpenWhisk to get the ansible playbooks needed to initialize CouchDB
+git clone https://github.com/apache/incubator-openwhisk /openwhisk
+
+# generate db_local.ini so the ansible jobs know how to access the database
+pushd /openwhisk/ansible
+ ansible-playbook -i environments/local setup.yml
+ ansible-playbook -i environments/local couchdb.yml --tags ini \
+ -e db_prefix=$DB_PREFIX \
+ -e db_host=$DB_HOST \
+ -e db_username=$COUCHDB_USER \
+ -e db_password=$COUCHDB_PASSWORD \
+ -e db_port=$DB_PORT \
+ -e openwhisk_home=/openwhisk
+popd
+
+# Wait for CouchDB to be available before starting to configure it
+until $( curl --output /dev/null --silent $DB_PROTOCOL://$DB_HOST:$DB_PORT/_utils ); do
+ echo "waiting for CouchDB to be available"
+ sleep 2
+done
+
+# disable reduce limits on views
+echo "Disabling reduce limits on views"
+curl --silent -X PUT $DB_PROTOCOL://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_node/couchdb@$NODENAME/_config/query_server_config/reduce_limit -d '"false"'
+
+# create the couchdb system databases
+echo "Creating _global_changes database"
+curl --silent -X PUT $DB_PROTOCOL://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_global_changes
+echo "Creating _metadata database"
+curl --silent -X PUT $DB_PROTOCOL://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_metadata
+echo "Creating _replicator database"
+curl --silent -X PUT $DB_PROTOCOL://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_replicator
+echo "Creating _users database"
+curl --silent -X PUT $DB_PROTOCOL://$COUCHDB_USER:$COUCHDB_PASSWORD@$DB_HOST:$DB_PORT/_users
+
+# initialize the DB tables for OpenWhisk
+pushd /openwhisk/ansible
+ ansible-playbook -i environments/local initdb.yml \
+ -e db_prefix=$DB_PREFIX \
+ -e db_host=$DB_HOST \
+ -e db_username=$COUCHDB_USER \
+ -e db_password=$COUCHDB_PASSWORD \
+ -e db_port=$DB_PORT \
+ -e openwhisk_home=/openwhisk
+
+ ansible-playbook -i environments/local wipe.yml \
+ -e db_prefix=$DB_PREFIX \
+ -e db_host=$DB_HOST \
+ -e db_username=$COUCHDB_USER \
+ -e db_password=$COUCHDB_PASSWORD \
+ -e db_port=$DB_PORT \
+ -e openwhisk_home=/openwhisk
+popd
+
+echo "successfully initialized CouchDB for OpenWhisk"
diff --git a/helm/openwhisk/templates/_readiness.tpl b/helm/openwhisk/templates/_readiness.tpl
index 3e06fdb..94291de 100644
--- a/helm/openwhisk/templates/_readiness.tpl
+++ b/helm/openwhisk/templates/_readiness.tpl
@@ -3,8 +3,8 @@
{{/* Init container that waits for couchdb to be ready */}}
{{- define "readiness.waitForCouchDB" -}}
-{{ if .Values.db.external }}
-# external db is assumed to be already ready; no need for init container
+{{ if not .Values.db.wipeAndInit }}
+# if not db.wipeAndInit, the external db must already be ready; so no need for init container
{{- else -}}
- name: "wait-for-couchdb"
image: "busybox"
diff --git a/helm/openwhisk/templates/couchdb.yaml b/helm/openwhisk/templates/couchdb.yaml
index d132b42..65bb97e 100644
--- a/helm/openwhisk/templates/couchdb.yaml
+++ b/helm/openwhisk/templates/couchdb.yaml
@@ -43,18 +43,10 @@ spec:
- name: {{ .Values.db.name | quote }}
imagePullPolicy: {{ .Values.db.imagePullPolicy | quote }}
image: {{ .Values.db.image | quote }}
- command: ["/init.sh"]
ports:
- name: couchdb
containerPort: {{ .Values.db.port }}
env:
- - name: "DB_HOST"
- value: "127.0.0.1"
- - name: "DB_PREFIX"
- valueFrom:
- configMapKeyRef:
- name: db.config
- key: db_prefix
- name: "COUCHDB_USER"
valueFrom:
secretKeyRef:
@@ -65,21 +57,8 @@ spec:
secretKeyRef:
name: db.auth
key: db_password
- - name: "DB_PORT"
- valueFrom:
- configMapKeyRef:
- name: db.config
- key: db_port
- name: "NODENAME"
value: "couchdb0"
- readinessProbe:
- httpGet:
- port: {{ .Values.db.port }}
- path: /{{ .Values.db.activationsTable }}
- initialDelaySeconds: 60
- periodSeconds: 10
- failureThreshold: 10
- timeoutSeconds: 1
{{- if .Values.db.persistence.enabled }}
volumeMounts:
- name: database-storage
diff --git a/helm/openwhisk/templates/initCouchDBJob.yaml b/helm/openwhisk/templates/initCouchDBJob.yaml
new file mode 100644
index 0000000..dc7506c
--- /dev/null
+++ b/helm/openwhisk/templates/initCouchDBJob.yaml
@@ -0,0 +1,74 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+
+{{ if .Values.db.wipeAndInit }}
+
+apiVersion: batch/v1
+kind: Job
+metadata:
+ name: init-couchdb
+ namespace: {{ .Release.Namespace | quote }}
+spec:
+ activeDeadlineSeconds: 600
+ template:
+ metadata:
+ name: init-couchdb
+ spec:
+ restartPolicy: Never
+ volumes:
+ - name: task-dir
+ configMap:
+ name: init-couchdb
+ containers:
+ - name: init-couchdb
+ image: openwhisk/kube-whisk-ansible-runner
+ imagePullPolicy: "Always"
+ command: ["/bin/bash", "-c", "set -e; . /task/initdb.sh"]
+ volumeMounts:
+ - name: task-dir
+ mountPath: "/task/initdb.sh"
+ subPath: "initdb.sh"
+ env:
+ - name: "DB_PROTOCOL"
+ valueFrom:
+ configMapKeyRef:
+ name: db.config
+ key: db_protocol
+ - name: "DB_HOST"
+ valueFrom:
+ configMapKeyRef:
+ name: db.config
+ key: db_host
+ - name: "DB_PORT"
+ valueFrom:
+ configMapKeyRef:
+ name: db.config
+ key: db_port
+ - name: "DB_PREFIX"
+ valueFrom:
+ configMapKeyRef:
+ name: db.config
+ key: db_prefix
+ - name: "COUCHDB_USER"
+ valueFrom:
+ secretKeyRef:
+ name: db.auth
+ key: db_username
+ - name: "COUCHDB_PASSWORD"
+ valueFrom:
+ secretKeyRef:
+ name: db.auth
+ key: db_password
+ - name: "NODENAME"
+ value: "couchdb0"
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: init-couchdb
+ namespace: {{ .Release.Namespace | quote }}
+data:
+{{ (.Files.Glob "configMapFiles/initCouchDB/initdb.sh").AsConfig | indent 2 }}
+
+{{ end }}
diff --git a/helm/openwhisk/templates/invoker.yaml b/helm/openwhisk/templates/invoker.yaml
index 68f5a4d..9a196cf 100644
--- a/helm/openwhisk/templates/invoker.yaml
+++ b/helm/openwhisk/templates/invoker.yaml
@@ -44,13 +44,12 @@ spec:
{{- end }}
initContainers:
- # Wait for a controller to be up (which implies kafka, zookeeper, couchdb are all up as well).
-{{ include "readiness.waitForController" . | indent 6 }}
-
{{- if eq .Values.invoker.containerFactory.impl "docker" }}
# Pull images for all default runtimes before starting invoker
{{ include "docker_pull_runtimes" . | indent 6 }}
{{- end }}
+ # Wait for a controller to be up (which implies kafka, zookeeper, couchdb are all up as well).
+{{ include "readiness.waitForController" . | indent 6 }}
containers:
- name: {{ .Values.invoker.name | quote }}
diff --git a/helm/openwhisk/values.yaml b/helm/openwhisk/values.yaml
index 22a81e1..b3705d8 100644
--- a/helm/openwhisk/values.yaml
+++ b/helm/openwhisk/values.yaml
@@ -91,11 +91,14 @@ kafka:
# Database configuration
db:
external: false
+ # Should we run a Job to wipe and re-initialize the database when the chart is deployed?
+ # This should always be true if external is false.
+ wipeAndInit: true
name: "couchdb"
- image: "openwhisk/kube-couchdb:latest"
+ image: "apache/couchdb:2.1"
# NOTE: setting replicaCount > 1 will not work.
replicaCount: 1
- imagePullPolicy: "Always"
+ imagePullPolicy: "IfNotPresent"
restartPolicy: "Always"
host: nil
port: 5984
diff --git a/tools/travis/collect-logs.sh b/tools/travis/collect-logs.sh
index cff1495..1ebed5f 100755
--- a/tools/travis/collect-logs.sh
+++ b/tools/travis/collect-logs.sh
@@ -25,7 +25,7 @@ kubectl -n openwhisk logs -lname=nginx >& logs/nginx.log
kubectl -n openwhisk logs -lname=kafkaprovider >& logs/kafkaprovider.log
kubectl -n openwhisk logs jobs/install-routemgmt >& logs/routemgmt.log
kubectl -n openwhisk logs jobs/install-catalog >& logs/catalog.log
-kubectl -n openwhisk logs jobs/kafkapkginstaller >& logs/kafkapkginstaller.log
+kubectl -n openwhisk logs jobs/init-couchdb >& logs/init-couchdb.log
kubectl get pods --all-namespaces -o wide --show-all >& logs/all-pods.txt
# System level logs from minikube
diff --git a/tools/travis/deploy.sh b/tools/travis/deploy.sh
index 1eb9436..7ba06a9 100755
--- a/tools/travis/deploy.sh
+++ b/tools/travis/deploy.sh
@@ -15,8 +15,5 @@ echo "Publishing kube-whisk-script-runner image"
echo "Publishing kube-whisk-ansible-runner image"
./tools/travis/publish.sh openwhisk kube-whisk-ansible-runner latest docker/whisk-ansible-runner
-echo "Publishing kube-couchdb image"
-./tools/travis/publish.sh openwhisk kube-couchdb latest docker/couchdb
-
echo "Publishing kube-invoker-agent image"
./tools/travis/publish.sh openwhisk kube-invoker-agent latest docker/invoker-agent