# Copyright 2018 Google LLC
#
# Licensed 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
#
#      https://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: bigtable-admin-job
  namespace: bigtable
spec:
  template:
    spec:
      containers:
        - name: bigtable-admin
          image: gcr.io/google-samples/service-catalog/cloud-bigtable-admin:latest
          volumeMounts:
            - name: service-account
              mountPath: /var/secrets/service-account
          env:
            - name: GOOGLE_APPLICATION_CREDENTIALS
              # Path to the private key JSON file stored in mounted secret.
              value: /var/secrets/service-account/privateKeyData
            # Use projectId from the binding credentials stored in the secret.
            - name: GOOGLE_CLOUD_PROJECT
              valueFrom:
                secretKeyRef:
                  name: admin-bigtable-binding
                  key: projectId
            # Use instanceId from the binding credentials stored in the secret.
            - name: BIGTABLE_INSTANCE
              valueFrom:
                secretKeyRef:
                  name: admin-bigtable-binding
                  key: instanceId
          imagePullPolicy: Always
      restartPolicy: Never
      volumes:
        # Make the admin-bigtable-binding secret available as a volume.
        - name: service-account
          secret:
            secretName: admin-bigtable-binding
