---
# Source: openwhisk/templates/couchdb-init-job.yaml
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


apiVersion: batch/v1
kind: Job
metadata:
  name: nuvolaris-init-couchdb
  labels:
    name: nuvolaris-init-couchdb
    app: nuvolaris-openwhisk
spec:
  backoffLimit: 3
  template:
    metadata:
      name: nuvolaris-init-couchdb
      labels:
        name: nuvolaris-init-couchdb
        heritage: "Helm"
        release: "nuvolaris"
        chart: "openwhisk-1.0.1"
        app: nuvolaris-openwhisk
    spec:
      restartPolicy: Never
      volumes:
      - name: task-dir
        configMap:
          name: nuvolaris-init-couchdb
      - name: whisk-auth
        secret:
          secretName: nuvolaris-whisk.auth
      
      containers:
      - name: init-couchdb
        image: "openwhisk/ow-utils:3e6138d"
        imagePullPolicy: "IfNotPresent"
        command: ["/bin/bash", "-c", "set -e; . /task/initdb.sh"]
        #command: ["sleep", "inf"]
        volumeMounts:
        - name: task-dir
          mountPath: "/task/initdb.sh"
          subPath: "initdb.sh"
        - name: whisk-auth
          mountPath: "/etc/whisk-auth"
        env:
        - name: "DB_PROTOCOL"
          valueFrom:
            configMapKeyRef:
              name: nuvolaris-db.config
              key: db_protocol
        - name: "DB_HOST"
          valueFrom:
            configMapKeyRef:
              name: nuvolaris-db.config
              key: db_host
        - name: "DB_PORT"
          valueFrom:
            configMapKeyRef:
              name: nuvolaris-db.config
              key: db_port
        - name: "DB_PREFIX"
          valueFrom:
            configMapKeyRef:
              name: nuvolaris-db.config
              key: db_prefix
        - name: "COUCHDB_USER"
          valueFrom:
            secretKeyRef:
              name: nuvolaris-db.auth
              key: db_username
        - name: "COUCHDB_PASSWORD"
          valueFrom:
            secretKeyRef:
              name: nuvolaris-db.auth
              key: db_password
        - name: "NODENAME"
          value: "couchdb0"

        # tag to use for git clone to get ansible files to initialize couchdb
        - name: "OW_GIT_TAG_OPENWHISK"
          value: "3e6138d088fbd502a69c31314ad7c0089c5f5283"
